Java measurement program

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kr151080
    New Member
    • Dec 2009
    • 6

    Java measurement program

    I need some help with a Measurement Program I Wrote.....I have this code as the main workings of my program:
    Code:
    import java.util.*;
    
    public class Measurement{
    {
      static Scanner console = new Scanner(System.in)
      public static void main(String[] args);
      double feet, inches, feetTotal, inchTotal, centTotal;
      boolean done;
      String str;
    
      ConvExc checkForZero = new ConvExc();
    
      public void printScreenFeet() throws InputMismatchException {
        done = false;
        do{
          try
          {
            System.out.println("Enter Feet Measurement:");
            double feet;
            System.out.flush();
            feet = console.nextDouble();
            while (checkForZero.enterZeroExc(feet)) {
              System.out.println("Please Enter a Number Greater then Zero!");
              System.out.println("Enter Feet Measurement:");
              System.out.flush();
              feet = console.nextDouble();
            }
            done = true;
          }
          catch (InputMismatchException imeRef){
            str = console.next();
            System.out.println("Error: Please enter a new number value");
            System.out.println();
          }
        }while (!done);
      }
    
      public void printScreenInch() throws InputMismatchException {
        done = false;
        do{
          try{
            System.out.println("Enter Inches Measurement:");
            double inches;
            System.out.flush();
            inches = console.nextDouble();
            while (checkForZero.enterZeroExc(inches)) {
              System.out.println("Please Enter a Number Greater then Zero!");
              System.out.println("Enter Inches Measurement:");
              System.out.flush();
              inches = console.nextDouble();
            }
            done = true;
          }
          catch (InputMismatchException imeRef){
            str = console.next();
            System.out.println("Error: Please enter a new number value");
            System.out.println();
          }
        }while (!done);
      } 
    
      feetTotal = feet*30.48;
      inchTotal = inches*2.54;
      centTotal = feetTotal+inchTotal;
      System.out.println(feetTotal + " cm in " + feet + " feet");
      System.out.println(inchTotal + " cm in " + inches + " inches");
    
      System.out.println("Total cm = "+centTotal);
    
      }
    
    }

    .....when i compile i am getting 2 errors the errors i'm getting are:

    Measurement.jav a:5: illegal start of expression
    static Scanner console = new Scanner(System. in)
    ^
    Measurement.jav a:13: illegal start of expression
    public void printScreenFeet () throws InputMismatchEx ception {;

    Does anyone know how to fix these errors? I've got no idea and I need some help BADLY!!! Please Help!!!

    THANKS!!


    The Supporting Classes i have are the Main2 class:
    Code:
    public class Main2 {
    
    
        public static void main(String[] args) {
    
            Conversion display = new Conversion();
            display.printScreenFeet();
            display.printScreenInch();
            display.printConversion();
           
        }
    
    }
    
    
    and the ConvExc Class:
    
    import java.util.*;
    
    public class ConvExc {
        
    
            public boolean enterZeroExc(double num){
              
                if (num<0) {
                return true;
                }
                else {
                    return false;
                }
         
    
            }

    .......PLEASE HELP!! THANK YOU!!
    Last edited by Frinavale; Dec 17 '09, 09:38 PM. Reason: Please post code in [code]...[/code] tags. Added code tags.
  • pbrockway2
    Recognized Expert New Member
    • Nov 2007
    • 151

    #2
    Code:
    static Scanner console = new Scanner(System.in)
    You have a missing semicolon at the end of this line.

    Comment

    • pbrockway2
      Recognized Expert New Member
      • Nov 2007
      • 151

      #3
      In PM:

      I changed and added the semicolon and it still doesn't compile. Its still throwing up 3 errors in the measurement.jav a file. I don't know what is wrong with them and was wondering if you might know what the errors would be??
      I think it's best for forum discussions to be held in the forum. That way everyone is able to contribute what they can.

      I would suggest that you describe the problem: ie post code and compiler messages that are causing problems. There's no need to post a whole lot of stuff. Start with the supporting classes and get them right. (They are not in the code you posted originally.) And then make sure they are all present (Conversion is missing in what you posted).

      Work just one small step at a time and deal with compiler errors as they arise.

      Comment

      • Frinavale
        Recognized Expert Expert
        • Oct 2006
        • 9749

        #4
        Um, I was indenting your code for the Measurement class noticed a bunch of errors.

        First of all you have:

        Code:
        public class Measurement{
        {
        Are you supposed to have 2 open curly braces??

        Then after you close your printScreenInch method...you have a bunch of variables declared (??) followed by a bunch of System.out.prin tln() statements. I don't even know what would happen if this did compile.

        Please check over your code because I'm sure there are more syntax errors.
        You will probably find a lot of your errors if you properly indent your code.


        -Frinny

        Comment

        Working...