1 COP2551 Project 2 – Modularized Unit Conversion Tool 100

advertisement
COP2551
Project 2 – Modularized Unit Conversion Tool
100 Points
Submission Requirements
 Submit your project folder via the Submit tool provided on the website
o Follow the project submission guidelines for the class
Design Documentation Requirements
Note: Create a “Design Documents” folder in the project folder to store the design documents.



Structure chart (simply recreate the structure chart provided below)
Flowchart of the withinRange() method
Pseudocode of the getInput() method
Design Specification Requirements
Note: Refer to the sample output in the Example Output section below.
1. Modify the program created for Project 1
A. The program must conform to the structure chart provided below
B. The method declarations provided below must be used
C. Do not modify the provided method declarations
D. Do not create any additional methods
main
getInput
withinRange
performConversions
convertTemperature
displayReport
convertDistance
convertWeight
void
void
void
void
convertDistance(int feet);
convertTemperature(int Fahrenheit);
convertWeight(int pounds);
displayReport(int fahrenheit, int feet, int pounds, double
celsius, double meters, double kilograms, double Kelvin,
double Inches, double Stones);
boolean getInput();
void performConversions(int fahrenheit, int feet, int pounds);
boolean withinRange(int input, int minRange, int maxRange);
1
2. Each method must be called from within its parent method only (i.e., the getInput(),
performConversions() and displayReport() methods can only be called from within the main()
method – refer to the provided structure chart)
3. After the user enters a value for a given prompt (temperature, distance or weight), perform the
following tests
A. Did the user enter a numeric value? (use the Integer.parseInt() method and try…catch
blocks)
1. If not, display the error message “The entered value is invalid”
B. Did the user enter a value within the allowable range? (use the return value of the
withinRange() method)
1. If not, display the error message “The entered value is out of range [x – y]”,
where x and y represent the low- and high-end of the range, respectively
Note: If any of the above tests fail, the getInput()method should immediately return control to the
main() method after displaying the appropriate error message, and the main() method should exit to the
system without executing the remainder of the program.
4. Perform the following additional conversions using the provided equations
A. Fahrenheit to Kelvin
K = (F + 459.67) * 5 / 9
B. Feet to inches
I = F * 12
C. Pounds to stones
S = P * 0.0714285714
Note: Three additional variables (of type double) will need to be created to hold the additional
converted values. Also, group common conversions within their respective method (i.e., perform the
Fahrenheit to Celsius and Kelvin conversions within the convertTemperature() method).
5. Modify the displayed report to include the results of the additional conversions
Additional Notes
 Use one variable for each entered or converted value (9 variables)
 Do not read global variable values directly (global variable values should be passed to the
methods that will use them)
 Use “flag” variables to represent whether the user entered valid data and whether the entered
data is within the allowable range
 Ensure your source code conforms to the commenting standards for the class
 Submit the project source code as a single *.java file
 Submit a capture of the program output as a *.txt file
2
Example Output
Ima Java Student
Modularized Unit Conversion Tool
Enter a Fahrenheit temperature (integer) [0 - 212]: 212
Enter a distance in feet (integer) [0 - 100]: 100
Enter a weight in pounds (integer) [0 - 100]: 100
212 Fahrenheit is 100.0 Celsius and 373.150 Kelvin
100 Feet is 30.480 Meters and 1200.000 Inches
100 Pounds is 45.360 Kilograms and 7.143 Stones
Ima Java Student
Modularized Unit Conversion Tool
Enter a Fahrenheit temperature (integer) [0 - 212]: 213
The entered value is out of range [0 - 212].
Ima Java Student
Modularized Unit Conversion Tool
Please enter a Fahrenheit temperature (integer) [0 - 212]: abc
The entered temperature value is invalid.
Optional Improvements (impress the instructor)
Note: Ensure your program satisfies each of the design specification requirements before attempting
the optional improvements.


Add a WHILE loop to the main() method to allow the program to automatically repeat after
displaying the conversion report or error message
o Tip: Prompt the user to continue to prevent the loop from occurring before the user is ready
o You will need to read chapter 5 section 5.4 (pages 230 – 234) in the textbook
Display the program output in columns using the String.format method (see example below)
o Display three decimal places for each of the converted values (i.e., Celsius and Kelvin)
o Refer to String Formatting in the Development Documents section on the course website
Ima Java Student
Modularized Unit Conversion Tool
Enter a Fahrenheit temperature (integer) [0 - 212]: 212
Enter a distance in feet (integer) [0 - 100]: 100
Enter a weight in pounds (integer) [0 - 100]: 100
Fahrenheit
Feet
Pounds
212
100
100
Celsius
Meters
Kilograms
100.000
30.480
45.360
Kelvin
Inches
Stones
373.150
1200.000
7.143
3
Download