By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,352 Members | 1,593 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,352 IT Pros & Developers. It's quick & easy.

Java measurement program

P: 6
I need some help with a Measurement Program I Wrote.....I have this code as the main workings of my program:
Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2.  
  3. public class Measurement{
  4. {
  5.   static Scanner console = new Scanner(System.in)
  6.   public static void main(String[] args);
  7.   double feet, inches, feetTotal, inchTotal, centTotal;
  8.   boolean done;
  9.   String str;
  10.  
  11.   ConvExc checkForZero = new ConvExc();
  12.  
  13.   public void printScreenFeet() throws InputMismatchException {
  14.     done = false;
  15.     do{
  16.       try
  17.       {
  18.         System.out.println("Enter Feet Measurement:");
  19.         double feet;
  20.         System.out.flush();
  21.         feet = console.nextDouble();
  22.         while (checkForZero.enterZeroExc(feet)) {
  23.           System.out.println("Please Enter a Number Greater then Zero!");
  24.           System.out.println("Enter Feet Measurement:");
  25.           System.out.flush();
  26.           feet = console.nextDouble();
  27.         }
  28.         done = true;
  29.       }
  30.       catch (InputMismatchException imeRef){
  31.         str = console.next();
  32.         System.out.println("Error: Please enter a new number value");
  33.         System.out.println();
  34.       }
  35.     }while (!done);
  36.   }
  37.  
  38.   public void printScreenInch() throws InputMismatchException {
  39.     done = false;
  40.     do{
  41.       try{
  42.         System.out.println("Enter Inches Measurement:");
  43.         double inches;
  44.         System.out.flush();
  45.         inches = console.nextDouble();
  46.         while (checkForZero.enterZeroExc(inches)) {
  47.           System.out.println("Please Enter a Number Greater then Zero!");
  48.           System.out.println("Enter Inches Measurement:");
  49.           System.out.flush();
  50.           inches = console.nextDouble();
  51.         }
  52.         done = true;
  53.       }
  54.       catch (InputMismatchException imeRef){
  55.         str = console.next();
  56.         System.out.println("Error: Please enter a new number value");
  57.         System.out.println();
  58.       }
  59.     }while (!done);
  60.   } 
  61.  
  62.   feetTotal = feet*30.48;
  63.   inchTotal = inches*2.54;
  64.   centTotal = feetTotal+inchTotal;
  65.   System.out.println(feetTotal + " cm in " + feet + " feet");
  66.   System.out.println(inchTotal + " cm in " + inches + " inches");
  67.  
  68.   System.out.println("Total cm = "+centTotal);
  69.  
  70.   }
  71.  
  72. }

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

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

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:
Expand|Select|Wrap|Line Numbers
  1. public class Main2 {
  2.  
  3.  
  4.     public static void main(String[] args) {
  5.  
  6.         Conversion display = new Conversion();
  7.         display.printScreenFeet();
  8.         display.printScreenInch();
  9.         display.printConversion();
  10.  
  11.     }
  12.  
  13. }
  14.  
  15.  
  16. and the ConvExc Class:
  17.  
  18. import java.util.*;
  19.  
  20. public class ConvExc {
  21.  
  22.  
  23.         public boolean enterZeroExc(double num){
  24.  
  25.             if (num<0) {
  26.             return true;
  27.             }
  28.             else {
  29.                 return false;
  30.             }
  31.  
  32.  
  33.         }

.......PLEASE HELP!! THANK YOU!!
Dec 17 '09 #1
Share this Question
Share on Google+
3 Replies


Expert 100+
P: 151
Expand|Select|Wrap|Line Numbers
  1. static Scanner console = new Scanner(System.in)
You have a missing semicolon at the end of this line.
Dec 17 '09 #2

Expert 100+
P: 151
In PM:

I changed and added the semicolon and it still doesn't compile. Its still throwing up 3 errors in the measurement.java 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.
Dec 17 '09 #3

Frinavale
Expert Mod 5K+
P: 9,731
Um, I was indenting your code for the Measurement class noticed a bunch of errors.

First of all you have:

Expand|Select|Wrap|Line Numbers
  1. public class Measurement{
  2. {
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.println() 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
Dec 17 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.