Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Conversion Program

  1. #1
    Junior Member
    Join Date
    Sep 2013
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Conversion Program

    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.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,139
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Conversion Program

    One possible problem I see is the code does not use the value returned by the menu() method.
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    DreamGod420 (October 17th, 2013)

  4. #3
    Junior Member
    Join Date
    Sep 2013
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Conversion Program

    After a bit of toying with it and referring back to my Java textbook. I was able to make it work. Thank you for help though.

Similar Threads

  1. Issues with my conversion program...
    By ocdjg in forum Object Oriented Programming
    Replies: 0
    Last Post: June 12th, 2013, 12:26 AM
  2. help me with a conversion program please
    By kristina5193 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: December 3rd, 2012, 09:00 AM
  3. Question about methods, temperature conversion program
    By aivory616 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: November 23rd, 2012, 01:27 PM
  4. Help with conversion
    By TheEvilCouncil in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 2nd, 2012, 08:29 PM
  5. Base Conversion
    By Pingu in forum What's Wrong With My Code?
    Replies: 7
    Last Post: February 22nd, 2011, 03:15 PM