Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- CIS 117 Chapter 6 Assignment
- 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.
- 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.
- 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.
- 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.
- Here’s an example of what the table should look using a specific set of properties for
- each Dragster. The numbers below will depend upon those parameters.
- Dragster 0.5 1.0 1.5 2.0 2.5 3.0 3.5 5.0 5.5 sec.
- ---------------- ---- ---- ---- ---- ---- ---- ---- ---- ----
- Red (Snoopy) 150 280 420 790 950 1105 1320
- Green (Hawkeye) 130 210 380 520 710 975 1150 1320
- Blue (Viper) 100 180 320 460 620 880 920 1190 1320
- The WINNER is the Red car! Congratulations, Snoopy!
- The program should announce a winner. If there’s a tie, indicate which vehicle ended up
- in the tie.
- Technical Requirements
- Build a Java application with a public class named Ch06Asg that has a main method.
- Then, in the same file, and below the closing curly-brace of the Ch06Asg class, create a
- class named Dragster (do not declare it public) with the following attributes:
- • color (a string)
- • driver’s name (a string)
- • horsepower (a decimal value greater than zero)
- • engine RPM (an integer value greater than zero)
- • weight (a decimal value in units of pounds)
- • average wheel diameter (a decimal value in units of feet)
- The class should have a private field for each attribute, along with public getter and
- setter methods for each attribute. The setter methods should reject any invalid data by
- failing to set the value if it is outside of the valid range.
- To create the table of distances, create a method withinin the class named
- CalculateDistance that accepts a variable named time as an input parameter. The
- equations to calculate the acceleration and distance are as follows:
- acceleration = (hp * 169017 ) / ( rpm * w * r )
- distance = 0.5 * acceleration * time * time
- where hp is the horsepower, rpm is the engine’s maximum rpm, w is the weight of the
- vehicle, r is the average wheel radius, acceleration is in feet per square second, and the
- distance is in feet.
- When the program starts, ask the user for the attributes of each Dragster, creating three
- Dragster objects, each with the appropriate attribute values. Next, create the header
- row for the table. You will generate one row for each Dragster object. For each column
- of a given row, call the appropriate Dragster object’s CalculateDistance method,
- passing it the time indicated at the top of the column. Display the calculated distance in
- the appropriate spot in the table, rounding the value to the nearest foot.
- For example, a vehicle with a horsepower of 130, rpm of 1000, weight of 2712 pounds,
- and wheel radius of 1 foot, will have an acceleration of 8.10 f/s2. In three seconds, it will
- have traveled 0.5 * 8.10 * 3 * 3 = 101 feet.
- Submit the Ch06Asg.java file within Blackboard on or before the assignment deadline.
- Make sure to add a comment block at the top of the file with your name, the date, course,
- title of the program, and a brief description. Add comments throughout the code where
- you believe they would help clarify code that is not immediately obvious as to its
- purpose or meaning.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement