Java disaster. please help!!!

Discussion in 'OT Technology' started by nietsni3, Nov 22, 2004.

  1. nietsni3

    nietsni3 Guest

    Code:
    //converting input from inch to cm
    //throw the exception if input is invalid
     
    import java.io.*;
    public class Conversion //extends Exception
    {
    static BufferedReader keyboard = new
    	BufferedReader(new InputStreamReader(System.in));
     
    public static void main(String[] args)
    {
    double feet, inches, cm, f, i;
     
    	public static double calculateInput() throws IOException
    {
    try{
     
    System.out.print("Enter the length in feet: ");
    System.out.flush();
    feet =
    	Double.parseDouble(keyboard.readLine());
    System.out.println();
     
    f = (feet)*(30.48);
    System.out.print(feet+ " is " + f+"centimeters");
     
    System.out.print("Enter the length in inches: ");
    System.out.flush();
    inches =
    	Double.parseDouble(keyboard.readLine());
    System.out.println();
     
    i = (inches)*(2.54);
    System.out.print(inches+ " is " + i+"centimeters");
     
    }
     
    catch(Exception eRef)
    {
    System.out.println("Please re-enter the values for length");
    calculateInput();
    }
    finally
    {
    if(feet<0 && inches<0)
    	{System.out.println("Please re-enter the values for length");
    	calculateInput();}
    else
    	System.out.flush();
    }
    };
    }
    }
    
    i wrote this program and got this error when compiling
    :
    Please help me to fix the problem. i need it by tonight :bowdown:
     
  2. DeeVoc

    DeeVoc Heh.

    Joined:
    Aug 13, 2001
    Messages:
    33,124
    Likes Received:
    0
    Location:
    Brooklyn
    wrap the function in a try/catch block and either print or ignore the excpetion when/if caught . . .
     
  3. sam758

    sam758 OT Supporter

    Joined:
    Aug 26, 2003
    Messages:
    901
    Likes Received:
    0
    1. you're missing closing parenthesis after every method.
    2. you might want to take out throws IOException after calculateInput since you already have a try-catch block that covers the whole method.
    3. take out the recursive call to calculateInput in the catch blocks, use a while {try..catch} instead.
     

Share This Page