Question
Need some help getting the rest of this program worked out. The following is what the console should output Welcome to the Length Converter 1
Need some help getting the rest of this program worked out.
The following is what the console should output
Welcome to the Length Converter
1 - Convert a length
2 - Add a type of conversion
3 - Delete a type of conversion
4 - Exit
Enter menu number: 1
1 - Miles to Kilometers: 1.6093
2 - Kilometers to Miles: 0.6214
3 - Inches to Centimeters: 2.54
Enter conversion number: 2
Enter Kilometers: 10
10.0 Kilometers = 6.214 Miles
1 - Convert a length
2 - Add a type of conversion
3 - Delete a type of conversion
4 - Exit
Enter menu number: 2
Enter 'From' unit: Centimeters
Enter 'To' unit: Inches
Enter the conversion ratio: .3937
This entry has been saved.
1 - Convert a length
2 - Add a type of conversion
3 - Delete a type of conversion
4 - Exit
Enter menu number: 1
1 - Miles to Kilometers: 1.6093
2 - Kilometers to Miles: 0.6214
3 - Inches to Centimeters: 2.54
4 - Centimeters to Inches: 0.3937
Enter conversion number: 4
Enter Centimeters: 2.54
2.54 Centimeters = 1 Inches
1 - Convert a length
2 - Add a type of conversion
3 - Delete a type of conversion
4 - Exit
Enter menu number: 4
Goodbye.
Operation should accomplish the following:
This application begins by displaying a main menu with four items.
If the user chooses the first main menu item, the application displays a menu of possible conversions. After the user selects a conversion, the application prompts the user to enter a unit of measurement, calculates the conversion, displays the result, and displays the main menu again.
If the user chooses the second main menu item, the application prompts the user to enter the values for a new conversion, saves this new conversion to a file, and displays a message to the user.
If the user chooses the third main menu item, the application displays a menu of possible conversions. After the user selects the conversion, the application deletes that conversion from the file, displays a message to the user, and displays the main menu again.
If the user chooses the fourth main menu item, the application displays a goodbye message and exits.
The program should follow these Specifications:
Create a class named Conversion that can store information about a conversion, including the from unit, from value, to unit, to value, and conversion ratio. This class should also contain the methods that perform the conversion calculations and return the results as a formatted string.
Create a class named ConversionIO that contains two methods: one that reads an array list of Conversion objects from a file and another that writes an array list of Conversion objects to a file. For example:
public static ArrayList
public static void saveConversions(ArrayList
Store the list of conversions in a text file named conversion_types.txt in the same directory as the ConversionIO class. If the conversion_types.txt file doesnt exist, the ConversionIO class should create it. This class should use buffered I/O streams, and it should close all I/O streams when theyre no longer needed.
Create a class named ConversionsApp that displays the menus and responds to the users choices.
I have already taken care of the conversion class:
Conversion
package lengthconverter; import java.text.DecimalFormat; public class Conversion { String fromUnit; String toUnit; double conversionRatio;
//Creates varibales to store conversion data public Conversion(String fromUnit, String toUnit, double conversionRatio) {
super(); this.fromUnit = fromUnit; this.toUnit = toUnit; this.conversionRatio = conversionRatio; }
//Displays type of conversion made public String getType(){
return fromUnit+" To "+toUnit+":"+conversionRatio; }
//Calculates conversion and stores as public String conversionCalc(double fromValue){
double toValue = fromValue * conversionRatio; DecimalFormat decFormat = new DecimalFormat("#.##"); toValue = Double.valueOf(decFormat.format(toValue)); return String.valueOf(toValue); } }
My biggest issue is the ConversionIO class so far.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started