support@w4writers.com +44 7743 307695
Oct 20, 2021

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 computers hidden total without going over 21.

Here are some suggestions for the games 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 players 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 users points.

Thecomputers total should remain hidden until the loop has finished.

After the loop has finished, the computers 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 cars fuel gauge and odometerThe classes you will design are the following:

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

To know the cars current amount of fuel, in gallons.

To report the cars 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 engine is running.

2. The Odometer Class: This class will simulate the car odometer. Its responsibilities are:

To know the cars current mileage.

To report the cars 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 objects current amount of fuel by one gallon for every 24 miles the car has traveled. (This addresses the cars 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 cars 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 employees hourly pay rate
 wages. An array of seven doubles to hold each employees 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 employees 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 employees 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 employees hours and pay rate. It should then display each employees
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.

E. Course Grades

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 students 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 students 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
instead.) This object should already hold the students score for
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
instead.) This object should already hold the students score for
the essay, Element 2 of the grades field should reference this
object.


toString:
This method should return a string that contains the numeric
scores and grades for each element in the grades array

 

Demonstrate the class in a program

Order this Assignment now

Total: GBP120

fables template