Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 1 of 3 123 LastLast
Results 1 to 25 of 59

Thread: Need some minor help.

  1. #1
    Member
    Join Date
    Feb 2013
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need some minor help.

    Im doing a project and I need my project to convert fahrenheit to celsius to kelvin along with feet to meters to inches and pounds to kilograms to stones. Anyways Ive coded the project (not sure how right it is) and when I run it, it asks for the amounts for each equation but then terminates the project. How can i fix this?

     import java.util.Scanner;
     
     
    public class Project2 {
     
    	private static final Object False = null;
    	private static final int number = 0;
    	private static final int CS = 0;
    	private static final int fTemp = 0;
    	private static final int fDist = 0;
    	private static final int ME = 0;
    	private static final int pWeight = 0;
    	private static final int KL = 0;
     
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
     
    				//Declare constants
    				final double CS = (5.0 / 9);
    				final double ME = 0.3048;
    				final double KL = 0.4536;
     
    				//Declare variables
    				Scanner input = new Scanner(System.in);
    				String entry;
    				int fTemp, fDist, pWeight;
    				String Inputnumber = null;
    				double cTemp, mDist, kWeight, K, I, S;
     
    				System.out.println(" A B ");
    				System.out.println(" Project Title "); 
     
    				//Get Input
    				System.out.print("Enter a Fahrenheit temperature (integer): ");
    				fTemp = input.nextInt();
    				System.out.print("Enter a distance in feet (integer): ");
    				fDist = input.nextInt();
    				System.out.print("Enter a weight in pounds (integer): ");
    				pWeight = input.nextInt();							
     
     
    				}
     
    			//Perform Conversions
    			static int cTemp = fTemp * CS;
    			static int mDist = fDist * ME;
    			static int kWeight = pWeight * KL;
    			static double K = (fTemp + 459.67) * 5/9;
    			int I = fDist * 12;
    			double S = pWeight * 0.0714285714;
     
     
     
     
     
    	//Methods		
    	private static void validInput(int i, int j) {
    		// TODO Auto-generated method stub
    		boolean withinRange = true;
     
    		if (i < 0 || i > 212);
    		System.out.println("Out of range");
    		withinRange = false;
     
    	}
     
     
    	private static boolean validInput(String entry) {
    		// TODO Auto-generated method stub
    		boolean isValid = false;
     
    		try {
    			Integer.parseInt(entry);
     
    			isValid = true;
     
    		}
    		catch  (Exception ex) {
    		System.out.println("Entered value is invalid");
    		}
     
    		//Display Report
    		System.out.println(fTemp  + " fahrenheit " + cTemp + " celsius "  + K + " Kelvin ");
     
    		return isValid;
     
     
     
     
     
     
     
    	}
    }

    My project is suppose to look like this as the ending result:
    Name
    Project title

    Enter a Fahrenheit temperature (integer) [0-212]: 212
    Enter a distance in feet (integer) [0-100]: 100
    enter a weight in pounds (integer) [0-100]: 100

    212 Fahenheit is 100.0 Celsius and 373.150 Kelvin
    100 Feet is 30.480 Meters and 1200.00 Inches
    100 Pounds is 45.360 Kilograms and 7.143 Stones

    Please enter a fahrenheit temperature (integer) [0-212]: abc
    The entered temperature value is invalid.

    Please enter a fahrenheit temperature (integer) [0-212]: 213
    The entered value is out of range [0-212]


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need some minor help.

    My project is suppose to look like this
    What does the contents of the console window look like when the program is executes?

    To copy the contents of the command prompt window:
    Click on Icon in upper left corner
    Select Edit
    Select 'Select All' - The selection will show
    Click in upper left again
    Select Edit and click 'Copy'

    Paste here.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Member
    Join Date
    Feb 2013
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need some minor help.

    Mine when executed says this;
    A B
    Project Title
    Enter a Fahrenheit temperature (integer): 212
    Enter a distance in feet (integer): 100
    Enter a weight in pounds (integer): 100

    and that would be it.
    just above it in the command prompt window it says <terminated> Project 2

    I'm not sure if I have some codes out of place or not enough in there.

    I also tried taking the conversions and putting them above the last bracket to look like this;
    //Get Input
    				System.out.print("Enter a Fahrenheit temperature (integer): ");
    				fTemp = input.nextInt();
    				System.out.print("Enter a distance in feet (integer): ");
    				fDist = input.nextInt();
    				System.out.print("Enter a weight in pounds (integer): ");
    				pWeight = input.nextInt();							
     
    				//Perform Conversions
    				cTemp = fTemp * CS;
    				mDist = fDist * ME;
    				kWeight = pWeight * KL;
    				K = (fTemp + 459.67) * 5/9;
    				I = fDist * 12;
    				S = pWeight * 0.0714285714;
     
    				}
     
     
     
     
     
     
     
    	//Methods		
    	private static void validInput(int i, int j) {
    		// TODO Auto-generated method stub
    		boolean withinRange = true;
     
    		if (i < 0 || i > 212);
    		System.out.println("Out of range");
    		withinRange = false;
     
    	}
     
     
    	private static boolean validInput(String entry) {
    		// TODO Auto-generated method stub
    		boolean isValid = false;
     
    		try {
    			Integer.parseInt(entry);
     
    			isValid = true;
     
    		}
    		catch  (Exception ex) {
    		System.out.println("Entered value is invalid");
    		}
     
    		//Display Report
    		System.out.println(fTemp  + " fahrenheit " + cTemp + " celsius "  + K + " Kelvin ");
     
    		return isValid;
     
     
     
     
     
     
     
    	}
    }
    But I still get the same result and now I have an error in my display report saying cTemp and K cannot be resolved to a variable.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need some minor help.

    You need to compile the code with the javac program's -Xlint to see a possible problem with the code.
    A sample commandline for compiling:
    D:\Java\jdk1.6.0_29\bin\javac.exe -Xlint Project2.java



    How and when does the code execute the println() statements that will show the results?

    cTemp and K cannot be resolved to a variable.
    You'll have to post all of the code so I can see what the problem is. The last post was only partial code.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Feb 2013
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need some minor help.

    Ok I got it showing most of the results in my command prompt here is my updated code.
    import java.util.Scanner;
     
     
    public class Project2 {
     
    	private static final Object False = null;
    	private static final int number = 0;
    	private static final int CS = 0;
    	private static final int fTemp = 0;
    	private static final int fDist = 0;
    	private static final int ME = 0;
    	private static final int pWeight = 0;
    	private static final int KL = 0;
     
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
     
    				//Declare constants
    				final double CS = (5.0 / 9);
    				final double ME = 0.3048;
    				final double KL = 0.4536;
     
    				//Declare variables
    				Scanner input = new Scanner(System.in);
    				String entry;
    				int fTemp, fDist, pWeight;
    				String Inputnumber = null;
    				double cTemp, mDist, kWeight, K, I, S;
     
    				System.out.println(" A B ");
    				System.out.println(" Project Title "); 
     
    				//Get Input
    				System.out.print("Enter a Fahrenheit temperature (integer): ");
    				fTemp = input.nextInt();
    				System.out.print("Enter a distance in feet (integer): ");
    				fDist = input.nextInt();
    				System.out.print("Enter a weight in pounds (integer): ");
    				pWeight = input.nextInt();							
     
    				//Perform Conversions
    				cTemp = fTemp * CS;
    				mDist = fDist * ME;
    				kWeight = pWeight * KL;
    				K = (fTemp + 459.67) * 5/9;
    				I = fDist * 12;
    				S = pWeight * 0.0714285714;
     
    				//Display Report
    				System.out.println(fTemp  + " fahrenheit " + cTemp + " celsius "  + K + " Kelvin ");
    				System.out.println(fDist  +  " feet "  + mDist + " meters " + I + " Inches ");
    				System.out.println(pWeight + " pounds " + kWeight + " kilograms " + S + "Stones ");
     
    				}
     
    	//Methods		
    	private static void validInput(int i, int j) {
    		// TODO Auto-generated method stub
    		boolean withinRange = true;
     
    		if (i < 0 || i > 212);
    		System.out.println("Out of range");
    		withinRange = false;
     
    	}
     
     
    	private static boolean validInput(String entry) {
    		// TODO Auto-generated method stub
    		boolean isValid = false;
     
    		try {
    			Integer.parseInt(entry);
     
    			isValid = true;
     
    		}
    		catch  (Exception ex) {
    		System.out.println("Entered value is invalid");
    		}
     
     
     
    		return isValid;
     
     
     
     
     
     
     
     
     
     
     
     
    	}
    }

    Now I believe I need to get the methods (validateInput and Interseparse) that I have under the display results to work and I think that would solve the terminating problem. How would i go about that? if it helps I'm using Eclipse.

    These are also my results now;
    A B
    Project Title
    Enter a Fahrenheit temperature (integer): 212
    Enter a distance in feet (integer): 100
    Enter a weight in pounds (integer): 100
    212 fahrenheit 117.77777777777779 celsius 373.15000000000003 Kelvin
    100 feet 30.48 meters 1200.0 Inches
    100 pounds 45.36 kilograms 7.14285714Stones

    Does my question make sense or is it confusing? Im very new to this so the methods are a bit tricky to me, on where to put them for them to execute.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need some minor help.

    where to put them for them to execute.
    You can put the methods in any order in the class. Their position doesn't effect when they will be executed.
    Methods are executed when they are called. If you (or the JVM in some cases) do not call a method, it will not be executed.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Member
    Join Date
    Feb 2013
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need some minor help.

    ok well with my coding in the previous post am I doing it right or have I not called the methods yet?

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need some minor help.

    have I not called the methods yet?
    Where does the code call the methods?
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Member
    Join Date
    Feb 2013
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need some minor help.

    I honestly dont know. I thought after i put //Methods and then the codes.

  10. #10
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need some minor help.

    Take a look at the tutorial:
    Passing Information to a Method or a Constructor (The Java™ Tutorials > Learning the Java Language > Classes and Objects)

    Here is an example of calling a method from your code:
    fTemp = input.nextInt();
    It calls the nextInt() method of the Scanner class.
    If you don't understand my answer, don't ignore it, ask a question.

  11. #11
    Member
    Join Date
    Feb 2013
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need some minor help.

    I still am getting errors on everything I do.

  12. #12
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need some minor help.

    Copy and paste here the text of any error messages you want help with along with the code.
    If you don't understand my answer, don't ignore it, ask a question.

  13. #13
    Member
    Join Date
    Feb 2013
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need some minor help.

    import java.util.Scanner;
     
     
    public class Project2 {
     
    	private static final Object False = null;
    	private static final int number = 0;
    	private static final int CS = 0;
    	private static final int fDist = 0;
    	private static final int ME = 0;
    	private static final int pWeight = 0;
    	private static final int KL = 0;
     
    	/**
    	 * @param args
    	 * @return 
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		validInput();
     
     
    				//Declare constants
    				final double CS = (5.0 / 9);
    				final double ME = 0.3048;
    				final double KL = 0.4536;
     
    				//Declare variables
    				Scanner input = new Scanner(System.in);
    				String entry;
    				int fTemp = 0, fDist, pWeight;
    				String Inputnumber = null;
    				double cTemp, mDist, kWeight, K, I, S;
     
    				System.out.println(" A B ");
    				System.out.println(" Project Title "); 
     
    				//Get Input
    				System.out.print("Enter a Fahrenheit temperature (integer): ");
    				fTemp = input.nextInt();
    				System.out.print("Enter a distance in feet (integer): ");
    				fDist = input.nextInt();
    				System.out.print("Enter a weight in pounds (integer): ");
    				pWeight = input.nextInt();							
     
    				//Perform Conversions
    				cTemp = fTemp * CS;
    				mDist = fDist * ME;
    				kWeight = pWeight * KL;
    				K = (fTemp + 459.67) * 5/9;
    				I = fDist * 12;
    				S = pWeight * 0.0714285714;
     
     
    				//Display Report
    				System.out.println(fTemp  + " fahrenheit " + cTemp + " celsius "  + K + " Kelvin ");
    				System.out.println(fDist  +  " feet "  + mDist + " meters " + I + " Inches ");
    				System.out.println(pWeight + " pounds " + kWeight + " kilograms " + S + "Stones ");
     
    	}
     
    	//Methods		
    	private static void validInput(int i, int j) {
     
    		// TODO Auto-generated method stub
    		boolean withinRange = true;
     
    		if (i < 0 || i > 212);
    		System.out.println("Out of range");
    		withinRange = false;
     
    	}
     
     
    	private static boolean validInput(String entry) { 
    	// TODO Auto-generated method stub
    		boolean isValid = false;
     
    		try {
    			Integer.parseInt(entry);
     
    			isValid = true;
     
    		}
    		catch  (Exception ex) {
    		System.out.println("Entered value is invalid");
    		}
     
     
     
    		return isValid;
     
     
     
     
     
     
     
     
     
     
     
     
     
    	}
     
    	private static void validInput() {
    		// TODO Auto-generated method stub
     
    	}
    }

    I got no errors in that code but I still cant get the methods to be executed for example if i put in the value 213 it needs to say out of range not convert it.

  14. #14
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need some minor help.

    it needs to say out of range not convert it.
    Where will it print that message? How does the code that prints the message get executed? If you don't call a method, the code in the method will not be executed.


    Did you compile the code with javac -Xlint option as I suggested in post#4. It will show you a problem in your code.
    If you don't understand my answer, don't ignore it, ask a question.

  15. #15
    Member
    Join Date
    Feb 2013
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need some minor help.

    It needs to print that message in the results. I need the methods to be called on which apparently i havent done right. My methods are after the display report, does that matter? I tried to compile the code with what you posted but even that got an error in Eclipse.

  16. #16
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need some minor help.

    My methods are after the display report, does that matter?
    See post#6

    When you get errors, you need to copy the full text of the error messages and paste it here.

    public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		validInput();
    Here you call the validInput() method BEFORE there is any input to validate. What good can that do?
    You need to call the method AFTER the data to be validated has been input
    AND you need to pass to the method the data to be validated.
    If you don't understand my answer, don't ignore it, ask a question.

  17. #17
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need some minor help.

    If you don't understand my answer, don't ignore it, ask a question.

  18. #18
    Member
    Join Date
    Feb 2013
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need some minor help.

    Quote Originally Posted by Norm View Post
    See post#6

    When you get errors, you need to copy the full text of the error messages and paste it here.

    public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		validInput();
    Here you call the validInput() method BEFORE there is any input to validate. What good can that do?
    You need to call the method AFTER the data to be validated has been input
    AND you need to pass to the method the data to be validated.
    Could you by any chance give me an example of doing this the correct way?

  19. #19
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need some minor help.

    Here is some pseudo code:
    get input from user
    validate input
    use input in computations
    print out results
    If you don't understand my answer, don't ignore it, ask a question.

  20. #20
    Member
    Join Date
    Feb 2013
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need some minor help.

    Alright hopefully my last question as im sure this is kind of annoying to you, but heres my code. Now the only errors I am getting now is in bold and bigger font. I put it in the pseudo code that you gave.

    Error for the first validInput and guess:
    Multiple markers at this line
    - Duplicate local variable guess
    - Syntax error on token ")", ; expected
    - void is an invalid type for the variable
    validInput
    - Syntax error on token "(", ; expected

    Error for the second method:
    Multiple markers at this line
    - Illegal modifier for parameter validInput; only final is
    permitted
    - Syntax error on token "(", ; expected
    - Syntax error on token ")", ; expected
    - Duplicate local variable entry

    Multiple markers at this line
    - Duplicate local variable
    fDist
    - Duplicate local variable
    pWeight
    - Duplicate local variable
    fTemp

    Void methods cannot return a value

    Those are my errors. How may I go about coding this to where those go away?

    import java.util.Scanner;
     
    public class Project2 {
    private static final int MAX_VALUE = 212;
    private static final int MIN_VALUE = 0;
     
    	/**
    	 * @param args
    	 * @return 
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
     
    				//Declare constants
    				final double CS = (5.0 / 9);
    				final double ME = 0.3048;
    				final double KL = 0.4536;
     
    				//Declare variables
    				Scanner input = new Scanner(System.in);
    				String entry;
    				int fTemp, fDist, pWeight, number, guess = -1;
    				String Inputnumber = null;
    				double cTemp, mDist, kWeight, K, I, S;
     
    				System.out.println(" A B ");
    				System.out.println(" Project Title "); 
     
     
    				//Get Input
    				System.out.print("Enter a Fahrenheit temperature (integer): ");
    				fTemp = input.nextInt();
    				System.out.print("Enter a distance in feet (integer): ");
    				fDist = input.nextInt();
    				System.out.print("Enter a weight in pounds (integer): ");
    				pWeight = input.nextInt();							
     
    				//Methods
    				private static void [B][SIZE=4]validInput[/SIZE][/B](int [SIZE=4][B]guess[/B][/SIZE]) {
    					// TODO Auto-generated method stub
    					boolean withinRange = true;
     
    					if (guess < MIN_VALUE || guess > MAX_VALUE);
    					System.out.println("Out of range");
     
    					withinRange = false;
     
     
    					validInput();
    				}
     
    				private static boolean [B][SIZE=4]validInput[/SIZE][/B](String [SIZE=4][B]entry[/B][/SIZE]) { 
    					// TODO Auto-generated method stub
    						int [B][SIZE=4]fTemp, fDist, pWeight[/SIZE][/B];
    						boolean isValid = false;
     
    						try {
    						fTemp = Integer.parseInt(entry);
    						fDist=Integer.parseInt(entry);
    						pWeight=Integer.parseInt(entry);
    							isValid = true;
     
    						}
    						catch  (Exception ex) {
    						System.out.println("Entered value is invalid");
     
    						validInput();
    						}
    						[B][SIZE=4]return isValid[/SIZE][/B];
     
     
     
    				//Perform Conversions
    				cTemp = fTemp * CS;
    				mDist = fDist * ME;
    				kWeight = pWeight * KL;
    				K = (fTemp + 459.67) * 5/9;
    				I = fDist * 12;
    				S = pWeight * 0.0714285714;
     
    				//Display Report
    				System.out.println(fTemp  + " fahrenheit " + cTemp + " celsius "  + K + " Kelvin ");
    				System.out.println(fDist  +  " feet "  + mDist + " meters " + I + " Inches ");
    				System.out.println(pWeight + " pounds " + kWeight + " kilograms " + S + "Stones ");
    	}
     
     
    	}
    				private static void validInput() {
    					// TODO Auto-generated method stub
     
     
     
    	}
    }

  21. #21
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need some minor help.

    You have left off the source line numbers for the compiler errors making it hard to find them.
    Here is a sample of an error message from the javac command:
    TestSorts.java:138: cannot find symbol
    symbol  : variable var
    location: class TestSorts
             var = 2;
             ^

    You are having a problem understanding the difference between defining a method and calling it. You can NOT define a method inside of another method:
    public int returnOne(int x) {   //  define a method
       return 1;  // return a value /ignores x
    } // end returnOne()
    You call a method from inside a method:
      public void anotherMethod() {
         ...
         int anInt = returnOne(234);  //  call returnOne method
         ...
      }  //end anotherMethod()
    If you don't understand my answer, don't ignore it, ask a question.

  22. #22
    Member
    Join Date
    Feb 2013
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need some minor help.

    Yeah I am.. I'm gonna read up on methods and see if I can figure it. In eclipse to get the source codeeould i run it eoth yhe errors and in the problrms tab copy that?out. This is all a foregin language t
    o me. Sorry this message so bad I'm on my phone.

  23. #23
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need some minor help.

    Wait until you are at your computer to send messages.
    If you don't understand my answer, don't ignore it, ask a question.

  24. #24
    Member
    Join Date
    Feb 2013
    Posts
    35
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need some minor help.

    Ok Im getting tired of this project and Im sure your getting tired of answering my questions but is this correct now yes or no?
    import java.util.Scanner;
     
    public class Project2 {
    private static final int MAX_VALUE = 212;
    private static final int MIN_VALUE = 0;
     
    	/**
    	 * @param args
    	 * @return 
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
     
    				//Declare constants
    				final double CS = (5.0 / 9);
    				final double ME = 0.3048;
    				final double KL = 0.4536;
     
    				//Declare variables
    				Scanner input = new Scanner(System.in);
    				String entry;
    				int fTemp, fDist, pWeight, number, guess = -1;
    				double cTemp, mDist, kWeight, K, I, S;
     
    				System.out.println(" A B ");
    				System.out.println(" Project Title "); 
     
     
    				//Get Input
    				System.out.print("Enter a Fahrenheit temperature (integer): ");
    				validInput();
     
    				System.out.print("Enter a distance in feet (integer): ");
    				validInput();
     
    				System.out.print("Enter a weight in pounds (integer): ");
    				validInput();	
     
    	{
    				//Display Report
    				System.out.println(fTemp  + " fahrenheit " + cTemp + " celsius "  + K + " Kelvin ");
    				System.out.println(fDist  +  " feet "  + mDist + " meters " + I + " Inches ");
    				System.out.println(pWeight + " pounds " + kWeight + " kilograms " + S + "Stones ");
     
    				//Perform Conversions	
    				cTemp = fTemp * CS;
    				mDist = fDist * ME;
    				kWeight = pWeight * KL;
    				K = (fTemp + 459.67) * 5/9;
    				I = fDist * 12;
    				S = pWeight * 0.0714285714; }
     
     
     
     
     
     
    				//Methods
    				public static void validInput(int guess) {
    					// TODO Auto-generated method stub
    					boolean withinRange = true;
     
    					if (guess < MIN_VALUE || guess > MAX_VALUE);
    					System.out.println("Out of range");
     
    					withinRange = false;
     
     
    					validInput();
    				}//end Method
     
     
    				//Next Method
    				public static boolean validInput(String entry) { 
    					// TODO Auto-generated method stub
    						int fTemp, fDist, pWeight;
    						boolean isValid = true;
     
    						try {
    						fTemp = Integer.parseInt(entry);
    						fDist=Integer.parseInt(entry);
    						pWeight=Integer.parseInt(entry);
    							isValid = false;
     
    						}
    						catch  (Exception ex) {
    						System.out.println("Entered value is invalid");
     
    						validInput();
    						}
    						return isValid;
     
     
     
     
     
     
     
     
     
     
    	}
    				private static void validInput() {
    					// TODO Auto-generated method stub
     
     
     
    	}
    }

    My only error with this when i try to run is after the semicolon in the last conversion..
    Description Resource Path Location Type
    Syntax error, insert "}" to complete Block Project2.java /Project 2/src line 51 Java Problem

  25. #25
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Need some minor help.

    is this correct now yes or no?
    What happens when you compile and execute the code?
    If there are errors, then its not correct.
    If you get the right answers, then it could be correct.

    Where is line 51 that is mentioned in the "error message"??


    You need to check the correct pairing of { with a }.
    There should be a { at the start of the code for a method definition
    and a } at the end of the code for the method.
    There should NOT be any methods defined inside of another method.
    If you don't understand my answer, don't ignore it, ask a question.

Page 1 of 3 123 LastLast

Similar Threads

  1. Java vending machine, minor thing.
    By Aprok in forum What's Wrong With My Code?
    Replies: 3
    Last Post: October 5th, 2011, 02:35 PM
  2. my code displaying some minor wrong o/p ....plz suggest me an answer !
    By naved in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 28th, 2011, 11:59 AM
  3. [SOLVED] Please help with this... I think I have a minor coding error
    By Leprechaun_hunter in forum What's Wrong With My Code?
    Replies: 5
    Last Post: April 12th, 2011, 08:02 AM