So for my CIS class, I need to write a program that converts inputed meters into either kilometers, inches, or feet based off of a menu provided to the user and their input. the meters entered cannot be negative, and if the menu option is outside of the 1-4 option range, it should be invalid. I am getting errors for :
java: method showKilometers in class challenge8 cannot be applied to given types;
required: double
found: no arguments
reason: actual and formal argument lists differ in length
java: method showInches in class challenge8 cannot be applied to given types;
required: double
found: no arguments
reason: actual and formal argument lists differ in length
java: method showFeet in class challenge8 cannot be applied to given types;
required: double
found: no arguments
reason: actual and formal argument lists differ in length
Thank you in advanced for any help.
here is my code:
import javax.swing.JOptionPane; public class challenge8 { public static void main(String[] args) { double meters; double kilometers; double inches; double feet; int menuItem; meters = getMeters(); menuItem = menu(); kilometers = showKilometers(); inches = showInches(); feet = showFeet(); while (menuItem < 0 || menuItem > 4) { JOptionPane.showMessageDialog(null,"That is an invalid menu option."); menu(); } if (menuItem == 1) { JOptionPane.showMessageDialog(null, meters + " meters is " + kilometers + " kilometers."); } else if (menuItem == 2) { JOptionPane.showMessageDialog(null, meters + " meters is " + inches + " inches."); } else if (menuItem == 3) { JOptionPane.showMessageDialog(null, meters + " meters is " + feet + " feet."); } else if (menuItem == 4) { System.exit(0); } System.exit(0); } public static double getMeters() { String input; double numMeters; input = JOptionPane.showInputDialog("Please enter a distance in meters."); numMeters = Double.parseDouble(input); if (numMeters < 0){ JOptionPane.showMessageDialog(null, "Meter can not be negative."); } return numMeters; } public static double showKilometers(double numMeters) { return numMeters * 0.001; } public static double showInches(double numMeters) { return numMeters * 39.37; } public static double showFeet(double numMeters) { return numMeters * 3.281; } public static int menu() { String input; int choice; input = JOptionPane.showInputDialog("Please choose one of the following:\n 1. Convert to kilometers\n" + " 2. Convert to inches\n 3. Convert to feet\n 4. Quit the program"); choice = Integer.parseInt(input); return choice; } }
--- Update ---
I fixed the method error, I just had to pass meters into the methods.
howver now my loop is messed up. It will work if on the first try, the option entered is 1-4, but if it is outside that range, the second time, no matter what the number is, it still says it is invalid.