Answered step by step
Verified Expert Solution
Question
1 Approved Answer
IN JAVA. (PLEASE READ MY DESCRIPTION BEFORE YOU REPOST THE WRONG ANSWER FROM ANOTHER USER!!!) STOP COPYING FROM ANOTHER POST AND REPOST IT. IT'S WRONG
IN JAVA. (PLEASE READ MY DESCRIPTION BEFORE YOU REPOST THE WRONG ANSWER FROM ANOTHER USER!!!)
STOP COPYING FROM ANOTHER POST AND REPOST IT. IT'S WRONG AND NOT WHAT I'M LOOKING FOR!!! I WILL UPVOTE FOR THE RIGHT ANSWER PLEASE READ CAREFULLY AND DO ALL THE WORKS.
IT HAS 3 PARTS: VEHICLE, DRIVER DESCRIPTION, AND EXTRA CREDIT.
I MARKED THE IMPORTANT PARTS WHICH SHOULD BE DONE AND IT HAS TO USE THAT SAMPLE LOOP WHILE CODING. YOU CAN'T CHANGE IT. THANK YOU SO MUCH.
Write a class called Vehicle containing the following fields make: (i.e. Ford) model: (i.e. Taurus) year speed distance (Distance traveled in race) It should include a constructor that takes make, model, and year and initializes the proper fields with this data. Zero out the speed and distance. The methods a Vehicle should have are: accelerate() - which increases the speed by 10 mph. Every time a user runs accelerate() on an instance of Vehicle, the speed increases by 10. Since no stock car can realistically go an unlimited speed, cap the speed to 120 mph. brake() - decreases the speed by 10 mph. Every time a user runs brakes() on an instance of Vehicle, the speed decreases by 10. Since slowest you can go is 0 mph, make sure you prevent negative speeds. (There's no going backwards.) adjustCarspeed() - Use a random number generator to determine whether a car accelerates or brakes. 50% of the time a car will accelerate: 25% of the time a car will stay the same speed, the other 25% the car will brake. accessor (getters) methods that return the values of these private fields. (setDistance is a bit different.) mutators (setters) - methods that change the values of these private fields. setDistance() - that takes a time in minutes, calculates the distance traveled by the car based on the current speed and time input and adds it to the total distance traveled by the car. toStringo - So you can print the object properly If written correctly. vour Vehicle class should work plug and play into both driver projects! Submit a gist of the Vehicle class as well as the drivers. Make sure you include the proper global header. Look at the Project Template for that header. Driver Description Both drivers run a two car 500 mile race. First car to reach 500 miles wins. The Vehicles run in a loop. Each loop will represent 1 minute. If a car is going 50mph, then in one minute the distance traveled by the car is 50.0 / 60.0 miles. The loop will generate a random value, decide whether to accelerate, brake, or do nothing to the cars. You can then query the car's speed to determine the distance traveled in that minute. Accumulate their distances. The loop will terminate as soon as the distance traveled by a car exceeds 500 miles. Sample loop: private static void race ThemCars(Vehicle car1, Vehicle car2) { while (car1.getDistance()
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started