# Game of twenty one, Morse Converter, Car Instrument Simulator Java and other codes

Need to do in Java Language

A. A Game of 21

Write a program that uses the Die class that was presented in Chapter 4 to write a program that lets the user play against the computer in a variation of the popular blackjack card game. In this variation of the game, two six-sided dice are used instead of cards. The dice are rolled, and the player tries to beat the computerâ€™s hidden total without going over 21.

Here are some suggestions for the gameâ€™s design:

Each round of the game is performed as an iteration of a loop that repeats as long as the player agrees to roll the dice, and the playerâ€™s total does not exceed 21.

At the beginning of each round, the program will ask the user whether he or she wants to roll the dice to accumulate points.

During each round, the program simulates the rolling of two six-sided dice. It rolls the dice first for the computer, then it asks the user if he or she wants to roll. (Use the Die class that was demonstrated in Chapter 4 to simulate the dice).

The loop keeps a running total of both the computer and the userâ€™s points.

Thecomputerâ€™s total should remain hidden until the loop has finished.

â€œAfter the loop has finished, the computerâ€™s total is revealed, and whoever the player with the most points without going over 21 wins.â€

B. Car Instrument Simulator

Design tow classes that work together to simulate a carâ€™s fuel gauge and odometer.Â The classes you will design are the following:

1. TheÂ FuelGauge Class: This class will simulate a fuel gauge. Its responsibilities are:

To know the carâ€™s current amount of fuel, in gallons.

To report the carâ€™s current amount of fuel, in gallons.

To be able to increment the amount of fuel by one gallon. This simulates putting fuel in the car. (The car can hold a maximum of 15 gallons).

To be able decrement the amount of fuel by one gallon, if the amount of fuel is greater than zero gallons. This simulates burning fuel when the carâ€™s engine is running.

2. TheÂ Odometer Class: This class will simulate the carâ€™s odometer. Its responsibilities are:

To know the carâ€™s current mileage.

To report the carâ€™s current mileage.

To be able to increment the current mileage by one mile. the maximum mileage on the odometer is 99,999 miles. When this amount is exceeded, the odometer resets the current mileage to 0.

To be able to work with the aÂ FuelGaugeÂ object. It should decrease the FuelGauage objectâ€™s current amount of fuel by one gallon for every 24 miles the car has traveled. (This addresses the carâ€™s fuel economy is 24 miles per gallon).

Demonstrate the classes by creating instances of each. Simulate filling the car up with fuel, and then run a loop that increments the odometer until the car runs out of fuel. During each loop iteration, print out the carâ€™s mileage and amount of fuel.

C. Payroll Class

Write a Payroll class that uses the following arrays as fields:
â€¢ employeeId. An array of seven integers to hold employee identification numbers. The
array should be initialized with the following numbers:
5658845 4520125 7895122 8777541
8451277 1302850 7580489
â€¢ hours. An array of seven integers to hold the number of hours worked by each
employee
â€¢ payRate. An array of seven doubles to hold each employeeâ€™s hourly pay rate
â€¢ wages. An array of seven doubles to hold each employeeâ€™s gross wages
The class should relate the data in each array through the subscripts. For example, the
number in element 0 of the hours array should be the number of hours worked by the
employee whose identification number is stored in element 0 of the employeeId array. That
same employeeâ€™s pay rate should be stored in element 0 of the payRate array.
In addition to the appropriate accessor and mutator methods, the class should have a
method that accepts an employeeâ€™s identification number as an argument and returns the
gross pay for that employee.

Demonstrate the class in a complete program that displays each employee number and asks
the user to enter that employeeâ€™s hours and pay rate. It should then display each employeeâ€™s
identification number and gross wages.
Input Validation: Do not accept negative values for hours or numbers less than 6.00 for
pay rate.

D. Morse Code Converter

Write a program that asks the user to enter a string and then converts that string to Morse code. Morse code is a code where each letter of the English alphabet, each digit, and various punctuation characters are represented by a series of dots and dashes.

In a course, a teacher gives the following tests and assignments:

â€¢ A lab activity that is observed by the teacher and assigned a numeric score.
â€¢ A pass/fail exam that has 10 questions. The minimum passing score is 70,
â€¢ An essay that is assigned a numeric score.
â€¢ A final exam that has 50 questions.

Write a class named CourseGrades. The class should have a GradedActivity array named
grades as a field. The array should have four elements, one for each of the assignments
previously described. The class should have the following methods;

setLab:

This method should accept a GradedActivity object as its argument.
This object should already hold the studentâ€™s score for the
lab activity. Element 0 of the grades field should reference this
object

setPassFailExam:

This method should accept a PassFailExan object as its argument.
This object should already hold the studentâ€™s score for the pass/fail
exam. Element I of the grades field should reference thil object.

MtEssay:

This method should accept an Essay object as its argument, (See
Programming Challenge 4 for the Essay class. If you have not
completed Programming Challenge 4, use a GradedActivity object
the essay, Element 2 of the grades field should reference this
object.

satFinalExam:

This method should accept an Essay object as its argument, (See
Programming Challenge 4 for the Essay class. If you have not
completed Programming Challenge 4, use a GradedActivity object
the essay, Element 2 of the grades field should reference this
object.

toString:
This method should return a string that contains the numeric

Demonstrate the class in a program

### Recommended Posts

##### CAPE5330: You have completed RTD experiments on each of the reactors: Advanced Reaction Engineering Coursework, UOL, UK

November 28, 2022

##### A critical argument of relevant supply chain models/concepts from multiple sources, (supported by references) have to underpin discussion.

November 28, 2022

##### MN-M024: You are required to build models in an Excel worksheet: Financial Modelling Coursework, SU, UK

November 28, 2022