2.10.8 Racing Final Test Case Won't Turn Green - What am I missing ? //Racecar.java Image transcription text 2.10.8 Racing Submit + Continue Save 1 public class Racecar 3 private double accel; // acceleration 4 private String name; // name of driver 5 6 public Racecar(double acceleration, String driver) 7 8 accel = acceleration; 9 name = driver; 10 11 12 // Returns the time it takes the racecar 13 // to complete the track 14 public double computeTime(double distance) 15 - M 16 double time = Math. sqrt(2*distance/accel); 17 return Math. round(time*100)/100.0; 18 19 20 public String toString() 21 - 22 return "Racer " + name; 23 24 3 // RaceMain.java Image transcription text 2.10.8 Racing Submit + Continue Save Output Test Cases Docs Assignment Grade More 1 public class RaceMain 2 . { Test Cases 3 public static void main(String args) 4 Check Code Expand All Minimize All 5 // Length of the course in meters 6 double distance = 2414; // ~ 1.5 miles 7 Test Pass Message 8 // Generate a random acceleration for each car Testing computeTime V Great ! 9 double acceleration1 = Math. round(Math. random()*100)/100.0; 10 double acceleration2 = Math. round(Math. random()*100)/100.0; 11 Testing toString V Great! 12 / /double acceleration1 = Math. random() + 1); 13 / /double acceleration2 = Math. random() + 1); Testing computeTime V Great ! 14 15 // Create two Racecar objects Testing toString V Great! 16 Racecar Max = new Racecar(acceleration1, "Driver 1"); 17 Racecar Lewis = new Racecar(acceleration2, "Driver 2"); You should print 2 lines V Great! 18 19 // Compute the finishing times for both cars Testing you used Math. random Great! 20 double time1 = Max. computeTime(distance); 21 double time2 = Lewis. computeTime(distance); Testing output is correct x Check you're printing all required information 22 23 // Print times of each car Your result: Racer Driver 1 car finished in 86.85 seconds 24 System. out. printIn(Max + " car finished in " + timel + " seconds"); Racer Driver 2 car finished in 219.73 seconds 25 System. out. printIn(Lewis + " car finished in " + time2 + " seconds"); 26 3 Difference: Racer Driver 1 car finished in 86.85 seconds 27 3 Racer Driver 2 car finished in 219.73 seconds Image transcription text Racecar Most of the Rocecar class has been completed for you, but you will need to complete the computeTime method. computeTime — takes one parameter, a double , which is the length of the course. Returns how long it will take the racecarto complete the course in seconds, rounded to two decimal places. See the explanation below for instructions on how to compute the time. Main Method In main , you should create two Racecor objects to represent two cars on the race track. Compute how long each car takes to complete the race. Print out each car's time. There are comments in main to help you with the algorithm. For the Racecor objects, make up a driver's name for each car. Use Math. random to randomly choose each car's acceleration. The acceleration should be greater than one. You can use a combination of Math . random and Math . round , or use the equation given in the slides. To make the minimum value 1 using the equation, just add 1 to the final answer. Computing the finishing time From physics. the kinematic equations tell us that d = v0 * t + Ell.5"r.l"t2 where d is distance in meters. VB is the starting velocity in mfs, t is the time in seconds, and a is acceleration in misz. Since the car starts from rest, v0 = 0 . This means that t = JCZW/d) The value of t will generally be a number with a long decimal value. Make sure to use Moth. round to round the value of t to the second decimal place. Example Output First car finished in 262.62 seconds Second car finished in 126.96 seconds



Answer :

Other Questions