JMU
logoDukeDash.png
Programming Assignment 4


1 Overview: President Alger is still pleased with your work on DukeDash and wants you to extend the prototype a little more. In particular, he now wants you to add a safety feature that will make it clear to the driver when he or she is exceeding the speed limit.

In some situations, this system will be given the current speed in mi/hr and the speed limit in km/hr. In other situations, this system will only be given the current speed in mi/hr and will use the default speed limit of 40.0 km/hr. In both situations, it will convert the speed to km/hr, compare it to the speed limit, and modify the display accordingly. If the user-supplied speed limit is less than the smallest allowable speed limit (of 20.0 km/hr), the smallest allowable speed limit is used instead.

2 Parts: This assignment is divided into several parts, each of which will be graded individually. You must complete all parts of this assignment in order. 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.

a. An algorithm for processing the command line arguments. Click here to go to Blackboard. (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 algorithm for processing the speed and speed limit. Click here to go to Blackboard. (Note: You may only attempt this part of the assignment once. Hence, it is only required that you attempt this part before starting the next part. However, if you do not earn a grade of 100% on this part you should make sure you understand all of the correct answers before starting the next part.)

c. A Java main class that is: given either 1 or 2 command-line strings containing the real-valued speed in mi/hr and an optional real-valued speed limit in km/hr, converts the strings as appropriate; performs the necessary calculations; and displays the results. Click here for the requirements.

3 Getting Started on the Programming: Before doing anything else, you should create a directory/folder (e.g., named pa4) that will hold all of the files for this assignment.

Next, you should copy your Converter.class and the provided Text.class and Dashboard.class to the directory you just created.

4 A Reminder: Recall from the lecture on "Using Arrays" that there is a getLength() function in the Array class that is passed an array and returns an int containing the number of elements in that array.

To use this function in a class of yours, you must include the line:

  import java.lang.reflect.*;
  

at the top of the source file for your class. (This is because the class that contains the getLength() function is neither in your working directory nor in the directory where most built-in Java classes are kept.)

5 Testing the DetailedSpeedSetter Class: You must test the DetailedSpeedSetter class using the following values.
Speed (mi/hr) Speed Limit (km/hr) Speeding?
0.0 0.0 false
24.8 40.0 false
24.9 40.0 true
25.0 40.3 false
40.0 60.0 true
40.0 64.37 true
40.0 65.0 false
100.0 160.0 true
100.0 160.9344 true
100.0 161.1 false
10.0 5.0 false
19.0 10.0 true
0.0 false
24.8 false
24.9 true
40.0 true

Obviously, you will need to execute the DetailedTripSetter program fifteen times (with fifteen different sets of command-line arguments). You should probably create a script/batch file for this purpose (that you can run from the command line).

In addition, you should test your code using the PA4TestSuite.jar (in the same way you used PA3TestSuite.jar for the previous assignment). Before doing so, you will need to copy junit.jar to your working directory for this assignment.

Going Further


Copyright 2013