Advertisement
alexfare

Untitled

Feb 15th, 2019
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.78 KB | None | 0 0
  1. CIS 117 Chapter 6 Assignment
  2. The dragsters are poised at the start of a long, straight track. Their drivers are about to do everything in their power to get to the end of that track before everyone else. The race will demand as much acceleration as possible to reach the top speed. Intense concentration and skill is demanded from the participants to be the winner. Welcome to the world of drag racing, a popular sport played across the globe.
  3. Most drag races have a track a quarter of a mile (1320 feet) long. Even though the road has no twist or turns, and there aren’t many competitors to guard against, a driver must be very skilled at gear-shifting in order not to lose grip of his dragster. While the average mid-size car can complete a quarter-mile in about 15 to 20 seconds, a dragster can complete that same distance in less than five seconds! The trick is to have a vehicle with a long and narrow body, very thin front tires, and the right balance of weight and horsepower to maximize acceleration across the track.
  4. In this assignment, your objective is to build a program that simulates a drag race. Three dragsters are in the race, so the program will ask, for each dragster, for the color, name of the driver, the horsepower, maximum engine rpm, weight, and the average diameter of its wheels.
  5. To simulate the race, the program will display a table of data that shows the distance each dragster has traveled, in half-second increments, until the vehicle reaches the end at 1,320 feet. The columns of the table indicate the elapsed time of the race, and should start at 0 and end when the last car crosses the finish line. In each row, the first column will display the name of the driver, followed by the distance the dragster has traveled at each half-second increment. When a given dragster reaches the finish line, but others have not, additional columns can be left blank.
  6. Here’s an example of what the table should look using a specific set of properties for
  7. each Dragster. The numbers below will depend upon those parameters.
  8. Dragster 0.5 1.0 1.5 2.0 2.5 3.0 3.5 5.0 5.5 sec.
  9. ---------------- ---- ---- ---- ---- ---- ---- ---- ---- ----
  10. Red (Snoopy) 150 280 420 790 950 1105 1320
  11. Green (Hawkeye) 130 210 380 520 710 975 1150 1320
  12. Blue (Viper) 100 180 320 460 620 880 920 1190 1320
  13. The WINNER is the Red car! Congratulations, Snoopy!
  14. The program should announce a winner. If there’s a tie, indicate which vehicle ended up
  15. in the tie.
  16. Technical Requirements
  17. Build a Java application with a public class named Ch06Asg that has a main method.
  18. Then, in the same file, and below the closing curly-brace of the Ch06Asg class, create a
  19. class named Dragster (do not declare it public) with the following attributes:
  20. • color (a string)
  21. • driver’s name (a string)
  22. • horsepower (a decimal value greater than zero)
  23. • engine RPM (an integer value greater than zero)
  24. • weight (a decimal value in units of pounds)
  25. • average wheel diameter (a decimal value in units of feet)
  26. The class should have a private field for each attribute, along with public getter and
  27. setter methods for each attribute. The setter methods should reject any invalid data by
  28. failing to set the value if it is outside of the valid range.
  29. To create the table of distances, create a method withinin the class named
  30. CalculateDistance that accepts a variable named time as an input parameter. The
  31. equations to calculate the acceleration and distance are as follows:
  32. acceleration = (hp * 169017 ) / ( rpm * w * r )
  33. distance = 0.5 * acceleration * time * time
  34. where hp is the horsepower, rpm is the engine’s maximum rpm, w is the weight of the
  35. vehicle, r is the average wheel radius, acceleration is in feet per square second, and the
  36. distance is in feet.
  37. When the program starts, ask the user for the attributes of each Dragster, creating three
  38. Dragster objects, each with the appropriate attribute values. Next, create the header
  39. row for the table. You will generate one row for each Dragster object. For each column
  40. of a given row, call the appropriate Dragster object’s CalculateDistance method,
  41. passing it the time indicated at the top of the column. Display the calculated distance in
  42. the appropriate spot in the table, rounding the value to the nearest foot.
  43. For example, a vehicle with a horsepower of 130, rpm of 1000, weight of 2712 pounds,
  44. and wheel radius of 1 foot, will have an acceleration of 8.10 f/s2. In three seconds, it will
  45. have traveled 0.5 * 8.10 * 3 * 3 = 101 feet.
  46. Submit the Ch06Asg.java file within Blackboard on or before the assignment deadline.
  47. Make sure to add a comment block at the top of the file with your name, the date, course,
  48. title of the program, and a brief description. Add comments throughout the code where
  49. you believe they would help clarify code that is not immediately obvious as to its
  50. purpose or meaning.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement