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.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%
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:20 O
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,
Transcribed Image Text:4:20 O 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,
4:20 O
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) =
%3D
time (hrs) X speed (km/hr). So, you
understand, the maximum distance a
car can travel in 10 hours bhased on
Transcribed Image Text:4:20 O 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) = %3D time (hrs) X speed (km/hr). So, you understand, the maximum distance a car can travel in 10 hours bhased on
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
Time complexity
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education