Results 1 to 5 of 5
  1. #1
    javadude0404 is offline Member
    Join Date
    May 2011
    Posts
    1
    Rep Power
    0

    Default Problem with Conversion Program

    Hey so im really new to java and I am having trouble with an assignment that converts meters to kilometers, inches, and feet based off of the users choice. Can anyone help with solving the errors::confused: Thanks
    Here is what I got so far

    import java.util.Scanner;


    public class Program4RIT {
    public static void main(String[] args){

    double meters;
    int decision;
    meters = getInputLength();

    }
    public static int getInputLength(){
    int meters;
    Scanner keyboard = new Scanner (System.in);
    System.out.println( "Enter a distance in meters" );
    meters = keyboard.nextInt();
    return meters;

    }

    {
    System.out.println("1.Convert to kilometers");
    System.out.println("2.Convert to inches");
    System.out.println("3.Convert to feet");
    System.out.println("4.Quit the program");
    System.out.println("Enter your choice :");
    Scanner input;
    int decision = input.nextInt();



    if (decision == 1){}
    }

    public static int getKilometers(){
    double meters;
    showKilometers1(meters);
    }
    private static void showKilometers1(double meters) {
    // TODO Auto-generated method stub

    }

    {
    int decision1;
    if (decision1==2){}
    }


    public static int getInches(){
    double meters;
    showInches(meters);
    }private static void showInches(double meters) {
    // TODO Auto-generated method stub

    }

    {


    if (decision1 == 3){

    }
    public static int showFeet(){
    double meters;
    showFeet(meters);
    }

    while (decision < 4);
    if ( decision == 4)
    {
    System.out.println(" Bye!");
    }



    public static void showKilometers(double meters){
    }
    {
    double kilometers;
    int meters;
    kilometers =( meters /1000);
    System.out.println( meters + "The distance in meters is " + kilometers + " kilometers " );

    }
    public static void showInches(double meters);
    {
    double inches;
    double meters;
    inches=( meters *39.3700787);
    System.out.println( meters + "The distance in meters is " + inches + " inches " );
    }
    public static void showFeet(double meters)
    {
    double feet;
    feet =( meters *3.280839895);
    System.out.println( meters + "The distance in meters is " + feet + " inches " );
    }
    {
    }
    {
    }



    }

    }

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    8

    Default

    Well, maybe, if we knew what the errors were.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    25

    Default

    Please
    • Tell us what errors you are having posting the actual error messages themselves.
    • Indicate which lines are causing which errors.
    • Edit your post above and add code tags so that your code will be readable. The tag [code] goes above your code block and the tag [/code] goes below the code block.


    Much luck and welcome to the forum!

  4. #4
    Solarsonic is offline Senior Member
    Join Date
    Mar 2011
    Posts
    261
    Rep Power
    4

    Default

    Wtf... your code makes no sense whatsoever.

    Try using a switch statement for the input like so:

    Java Code:
    Scanner scanner = new Scanner(System.in);
    int decision=scanner.nextInt();
    
    switch(decision) {
    case 1: //kilometers
    /* CODE */
    break; //end the case
    
    case 2: //inches
    /* CODE */
    break;
    }
    Etc.

  5. #5
    Toll's Avatar
    Toll is offline Senior Member
    Join Date
    May 2011
    Location
    Sweden
    Posts
    382
    Rep Power
    3

    Default

    I can definitely see what the problem is with that code... Nothing is where it's supposed to be. The program (if it even compiles; I doubt it does) does the following: Ask how many meters, and then quits. Indent your code properly to get a grasp of how it looks, and start from there.

Similar Threads

  1. Binary-to-Decimal Conversion (Precision Problem)
    By shadowfax57 in forum New To Java
    Replies: 4
    Last Post: 09-07-2010, 09:00 AM
  2. Problem of conversion JFrame to Applet
    By Rekuta in forum Java Applets
    Replies: 9
    Last Post: 05-16-2010, 03:31 AM
  3. celsius to farenheit conversion program...
    By andrewsx in forum New To Java
    Replies: 3
    Last Post: 03-03-2010, 04:34 AM
  4. a simple conversion problem
    By sweetjava in forum New To Java
    Replies: 3
    Last Post: 07-20-2009, 06:34 AM
  5. Problem in TIFF Conversion
    By lakshmipriyam in forum Advanced Java
    Replies: 1
    Last Post: 08-09-2007, 10:44 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •