So, as before, DukeDash will be given the current speed in mi/hr, convert it to km/hr, and display the speed in km/hr. Now, DukeDash will also be given the distance traveled during the current trip in ft and the duration of the current trip in hr and it must calculate and display the average trip speed in both mi/hr and km/hr.
The later parts are based on the earlier parts and you may (indeed, should) use your answers to the earlier parts to complete the later parts. (Note: Unlike the previous assignment, you may need to expand on and/or modify the textual algorithms when developing the Java implementations.)
a. A textual version of an algorithm for converting a distance in ft to a distance in mi and a textual version of an algorithm for converting a trip distance measured in ft and a trip duration measured in hr to trip speeds measured in both mi/hr and km/hr. (Note: You may attempt this part of the assignment multiple times. You may not attempt the next part of the assignment until you have earned a grade of 100% on this part.)
b. An exercise on integer division, type casting and implicit numeric promotion. (Note: You may attempt this part of the assignment multiple times. You may not attempt the next part of the assignment until you have earned a grade of 80% on this part.)
c.1. A modified version of your Java class named Converter
that now has the ability to convert distances measured in whole feet to
equivalent distances measured in miles.
c.2. A Java application that is: given command-line strings containing a real-valued speed in mi/hr, an integer-valued trip distance in ft, and a trip duration in hr; converts the strings as appropriate; performs the necessary calculations; and displays the results.
pa2
) that
will hold all of the files for this assignment.
Next, you should copy your
Converter.java
and the provided
Text.class
and Dashboard.class
to the directory
you just created.
After that, you must test your Conveter
class (since you
have not yet tested it). You must use the same test cases you used
to test the SpeedPrinter
class. To facilitate the process,
you may use the following program:
You should read and understand this program before using it.
Converter
class and your
TripSetter
class independently.
toMiles()
function to the Converter
class.
There must not be a main()
method in your
Converter
class.
Converter.toMiles()
with the following values. (Note: The results in this table
are rounded to two decimal places.)
Feet | Miles |
0 | 0.00 |
1000 | 0.19 |
1320 | 0.25 |
2173 | 0.41 |
2640 | 0.50 |
5280 | 1.00 |
10560 | 2.00 |
105600 | 20.00 |
2138958 | 405.11 |
To facilitate the process, you may use the following program:
You should read and understand this program before using it.
Converter.toMiles()
function, you should make sure you didn't break anything that was
already working. This is a process that is known as regression
testing. To that end, you should test
Converter.toKPH()
using all of the test cases you
used earlier.
Converter
class, you should use the textual algorithm from Part a to
implement the TripSetter
class.
TripSetter
class using the following values. (Note: The results in this table
are rounded to two decimal places.)
Distance | Duration | mi/hr | km/hr |
200 | 1.00 | 0.04 | 0.06 |
5280 | 1.00 | 1.00 | 1.61 |
5280 | 2.00 | 0.50 | 0.80 |
316800 | 1.00 | 60.00 | 96.56 |
316800 | 0.75 | 80.00 | 128.75 |
316800 | 1.25 | 48.00 | 77.25 |
423198 | 1.47 | 54.52 | 87.75 |
You must use test the current speed functionality using the same
test cases you used to test the SpeedPrinter
class.
Obviously, you will need to execute the TripSetter
program
seven times (with seven different sets of command-line arguments).
In order to reduce the burden on the Web-CAT server, you should test your code off-line before using Web-CAT. To facilitate that process, you should:
junit.jar
to your working folder/directory. (Note: Remember to right-click
when downloading.)
PA2TestSuite.jar
to your working folder/directory. (Note: Remember to right-click
when downloading.)
Converter
and TripSetter
classes.PA2TestSuite.jar
to execute it.
(Note: If the test suite does not execute it is probably because
your operating system does not recognize executable .jar
files. In this case, you can execute it from the command shell
using the command java -jar PA2TestSuite.jar
)If your code fails any of the tests, you will be given hints that should help you correct your mistakes.
Your code must pass all of the tests. If not, you will receive a grade of 0.
Late submissions will not be accepted. If your code is submitted late, even one second late, you will receive a grade of 0.
It is not enough that your code works. You will be penalized (perhaps severely) for code that: does not satisfy the course style guide, is inelegant, contains duplicative sections, or is badly designed.
Copyright 2013