Create AutomaticCar class that shall have private model, year, speed and gear attributes. Encapsulate complete state and expose the state for read/write (where it makes sense and needed). As its automatic car, so other shall not be able to update the gear attribute directly. The gear would auto change based on speed and other parameters (defined below). The speed range for different gears is (gear : speed-range) 0:0 1:1-100 2:101-200 3:201-300 4:301-400 5:401-500.  The speed should not be updated if a -ve value is passed to its set method, in such cases, it shall print an appropriate error message. If car's earlier speed was 50 and set method is called with argument 20, the car speed would become 20, not 70. Please note, same method would be used to increase and decrease the speed, depending on whether the earlier speed was lower or higher as compared to new value passed. Here are some further points/rules that you must implement: Make LuckyRacer class, in its main method, create 5 objects of AutomaticCar. Get car model from user input. These 5 cars shall participate in race, name these car objects: car1, car 2 up to car 5. There shall be multiple rounds of the race, in each round you shall update speed based on a random value (detail given in next point), the car that got higher random number, in most number of rounds, on the average, shall win the race. How to generate a random number? There is a class: Random in package java.util, create an object and call its method nextInt(x) ... where x is an int, it return a random number from 0 to x. Drive each car for 10 hours (10 rounds, each round of 1 hour), after each round, update the car speed to a random number, generated for each car separately, in range of 1 to 500 (inclusive). How you shall represent 1 hour in program? Run 10 iterations of for loop, assume each iteration represent 1 hour lap. The speed can go from 0 to any in-range speed directly and gear shall auto change to appropriate value as per speed. Print the distance covered by each car after each hour. After 10 hours, the car with highest distance covered shall win. You shall print the car model that won the race e.g. "BMW i8 Won the race". As you know, distance (km) = time (hrs) X speed (km/hr). So, you understand, the maximum distance a car can travel in 10 hours, based on above rules is 5000 km, how? say each time maximum number was generated for the race (10 X 500). To calculate total distance traveled by each car, add another attribute, odoMeter in AutomaticCar and initialize it to 0. After each hour, add the total distance traveled by the car in that round in odoMeter field. Print the status of race after each hour, i.e. which car is winning with the distance traveled by that car so far. The output may look like below. To fit on screen, lets set scale 1km = 100km, use dash '-' to represent scaled 1 km. Like this: After 1 hour/s: Car 1 -- : 200 km passed Car 2 --- : 300 km passed Car 3 -- : 250 km passed Car 4 - : 180 km passed Car 5 ---- : 400 km passed   (keep printing status in each loop iteration) ... ...   After 10 hour/s: Car 1 ---------------------------------------------------------------------- : 2100 km passed Car 2 -------------------------------------------------------------------------------- : 2700 km passed Car 3 ------------------------------------------------------------ : 1800 km passed Car 4 -------------------------------------------------- : 1500 km passed Car 5 ---------------------------------------------------------------------- : 2100 km passed   Car 2, BMW i8 Won the Race.   Above dashes are just example, use proper scale to represent distance correctly on single line. You shall also print the gear number the winner car used mostly during race, based on gear average and rounding it.   (In Java)

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter11: More Object-oriented Programming Concepts
Section: Chapter Questions
Problem 3GZ
icon
Related questions
Question
100%

Create AutomaticCar class that shall have private model, year, speed and gear attributes. Encapsulate complete state and expose the state for read/write (where it makes sense and needed). As its automatic car, so other shall not be able to update the gear attribute directly. The gear would auto change based on speed and other parameters (defined below). The speed range for different gears is (gear : speed-range)

  1. 0:0
  2. 1:1-100
  3. 2:101-200
  4. 3:201-300
  5. 4:301-400
  6. 5:401-500. 

The speed should not be updated if a -ve value is passed to its set method, in such cases, it shall print an appropriate error message. If car's earlier speed was 50 and set method is called with argument 20, the car speed would become 20, not 70. Please note, same method would be used to increase and decrease the speed, depending on whether the earlier speed was lower or higher as compared to new value passed.

Here are some further points/rules that you must implement:
  1. Make LuckyRacer class, in its main method, create 5 objects of AutomaticCar. Get car model from user input. These 5 cars shall participate in race, name these car objects: car1, car 2 up to car 5. There shall be multiple rounds of the race, in each round you shall update speed based on a random value (detail given in next point), the car that got higher random number, in most number of rounds, on the average, shall win the race.

  2. How to generate a random number? There is a class: Random in package java.util, create an object and call its method nextInt(x) ... where x is an int, it return a random number from 0 to x. Drive each car for 10 hours (10 rounds, each round of 1 hour), after each round, update the car speed to a random number, generated for each car separately, in range of 1 to 500 (inclusive). How you shall represent 1 hour in program? Run 10 iterations of for loop, assume each iteration represent 1 hour lap. The speed can go from 0 to any in-range speed directly and gear shall auto change to appropriate value as per speed.

  3. Print the distance covered by each car after each hour. After 10 hours, the car with highest distance covered shall win. You shall print the car model that won the race e.g. "BMW i8 Won the race". As you know, distance (km) = time (hrs) X speed (km/hr). So, you understand, the maximum distance a car can travel in 10 hours, based on above rules is 5000 km, how? say each time maximum number was generated for the race (10 X 500). To calculate total distance traveled by each car, add another attribute, odoMeter in AutomaticCar and initialize it to 0. After each hour, add the total distance traveled by the car in that round in odoMeter field.

  4. Print the status of race after each hour, i.e. which car is winning with the distance traveled by that car so far. The output may look like below. To fit on screen, lets set scale 1km = 100km, use dash '-' to represent scaled 1 km. Like this:
After 1 hour/s:
Car 1 -- : 200 km passed
Car 2 --- : 300 km passed
Car 3 -- : 250 km passed
Car 4 - : 180 km passed
Car 5 ---- : 400 km passed
 
(keep printing status in each loop iteration)
...
...
 
After 10 hour/s:
Car 1 ---------------------------------------------------------------------- : 2100 km passed
Car 2 -------------------------------------------------------------------------------- : 2700 km passed
Car 3 ------------------------------------------------------------ : 1800 km passed
Car 4 -------------------------------------------------- : 1500 km passed
Car 5 ---------------------------------------------------------------------- : 2100 km passed
 
Car 2, BMW i8 Won the Race.
 
Above dashes are just example, use proper scale to represent distance correctly on single line. You shall also print the gear number the winner car used mostly during race, based on gear average and rounding it.
 
(In Java)
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 4 images

Blurred answer
Knowledge Booster
Study of Characters
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage