Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-04-2005, 06:37 AM   PM User | #1
muellerj
New to the CF scene

 
Join Date: Feb 2005
Location: WI
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
muellerj is an unknown quantity at this point
Angry Eclipse, Java syntax error (probably easy solution)

I am a beginer to Java (im writing my first program for a class) but I can't seem to figure out a syntax error. Here is some stuff for background. I am using Eclipse 3.0.1 IDE and I downloaded Java 5 Update 1 JDK from Sun and installed both (note I installed Eclipse first, not sure if it matters). Windows XP SP2.

Eclipse is showing this error...

Syntax error on token "(", ; expected
Syntax error on token ")", ; expected

for the following code.(line 21)

The IDE underlines the () that I put in RED and says the error is there. I don't get it because I don't think I need a ; anywhere. (and this code is copied directly from my prof's website)

Thanks for any help, really really new to java, I hope it is something simple.

Code:
package edu.uwec.cs.muellerzabel.conversion;
import javax.swing.JOptionPane;


/**
 * @author MUELLERJ ZABELJJ 
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Convert {

	public static void main(String[] args) {
		private static double getDouble(string prompt) {
	        double x = 0;
	        boolean done = false;
	        while (!done) {
	            try {
	                x = Double.parseDouble(JOptionPane.showInputDialog(prompt));
	                done = true;
	            } catch (NumberFormatException e) {
	                JOptionPane.showMessageDialog(null,
	                        "That wasn't a valid input.  Please enter a number.");
	            }
	        }
	        return x;
	    }
		
		double dblUserInput = 0;
		double dblEnglish = 0;
		double dblFeet = 0;
		double dblInches = 0;
		
		dblUserInput = getDouble("Enter the number of meters you would like to convert to feet or inches.");
		
		dblEnglish = dblUserInput * 39.37;
		dblFeet = dblEnglish / 12;
		dblInches = dblEnglish;
		
		if (dblEnglish > 12){
			JOptionPane.showMessageDialog(null, dblUserInput + " meters is equal to " + dblFeet + " feet.");
		}else {
			JOptionPane.showMessageDialog(null, dblUserInput + " meters is equal to " + dblInches + " inches.");
			
		}
	}
}

Last edited by muellerj; 02-04-2005 at 06:40 AM..
muellerj is offline   Reply With Quote
Old 02-04-2005, 06:54 AM   PM User | #2
cfc
Regular Coder

 
Join Date: Dec 2004
Location: Keswick, Ontario
Posts: 251
Thanks: 0
Thanked 0 Times in 0 Posts
cfc is an unknown quantity at this point
Two problems:
- Don't declare/define getDouble within main
- In the arguments for getDouble, String is not capitalized.

This code compiled and ran perfectly:

Code:
package edu.uwec.cs.muellerzabel.conversion;
import javax.swing.JOptionPane;


/**
 * @author MUELLERJ ZABELJJ 
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
public class Convert {
	private static double getDouble(String prompt) {
	        double x = 0;
	        boolean done = false;
	        while (!done) {
	            try {
	                x = Double.parseDouble(JOptionPane.showInputDialog(prompt));
	                done = true;
	            } catch (NumberFormatException e) {
	                JOptionPane.showMessageDialog(null,
	                        "That wasn't a valid input.  Please enter a number.");
	            }
	        }
	        return x;
	}

	public static void main(String[] args) {
		
		
		double dblUserInput = 0;
		double dblEnglish = 0;
		double dblFeet = 0;
		double dblInches = 0;
		
		dblUserInput = getDouble("Enter the number of meters you would like to convert to feet or inches.");
		
		dblEnglish = dblUserInput * 39.37;
		dblFeet = dblEnglish / 12;
		dblInches = dblEnglish;
		
		if (dblEnglish > 12){
			JOptionPane.showMessageDialog(null, dblUserInput + " meters is equal to " + dblFeet + " feet.");
		} else {
			JOptionPane.showMessageDialog(null, dblUserInput + " meters is equal to " + dblInches + " inches.");
			
		}
	}
}

Last edited by cfc; 02-04-2005 at 07:40 AM..
cfc is offline   Reply With Quote
Old 02-04-2005, 03:37 PM   PM User | #3
muellerj
New to the CF scene

 
Join Date: Feb 2005
Location: WI
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
muellerj is an unknown quantity at this point
Smile

Thanks a lot! I figured someone who knew what they were doing could spot that pretty quickly. Now I don't have to ask my Professor.
muellerj is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:37 AM.


Advertisement
Log in to turn off these ads.