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 2 of 3 FirstFirst 123 LastLast
Results 26 to 50 of 59

Thread: Need some minor help.

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

    Default Re: Need some minor help.

    S = pWeight * 0.0714285714; }

    this is the line with the error and its the semi colon. Tells me to insert } to complete the block but once i do, the same error is still there.
    As for being correct I meant as in how the whole code looks with the methods if I added the {} correct.
    When I try to compile it I get:
    Exception in thread "main" java.lang.Error: Unresolved compilation problem:
    Syntax error, insert "}" to complete Block

  2. #27
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need some minor help.

    S = pWeight * 0.0714285714; }
    For readability the } in the above line should be on the next line and inline below the statement with the pairing }


    You need to check the correct pairing of each { 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.

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

    Default Re: Need some minor help.

    Where or How am I still defining a method inside another method?
    I also still get the insert a } on the same semicolon after moving a } to the next line.

  4. #29
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need some minor help.

    Where is the ending } for the main() method?

    To clearly see which } ends a method,
    label all the }s that end a method with a comment:
    } // end main()

    } // end validateInput()
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Need some minor help.

    Honestly Ive got no clue, when I say that Im new to this I mean this is the second thing I ever tried coding..

  6. #31
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need some minor help.

    To clearly see which } ends a method,
    label all the }s that end a method with a comment:
    } // end main()

    } // end validateInput()


    Each method should have only one ending }
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Need some minor help.

    Yeah anything I do doesnt not work for me. I still get an error somewhere.

  8. #33
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need some minor help.

    Perhaps you need to take a break and try something else. If you are having counting and pairing {s and }s in a small program, I don't know what will happen when you try to write a bigger program.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Need some minor help.

    Its due tomorrow night so I got to figure this out. I understand that there has to be the same amount { as }. Which i just noticed im missing two } somewhere in this thing. Am I on the right track?

  10. #35
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need some minor help.

    That's one requirement: that all {s must have a pairing }
    One way to check for unpaired {}s
    Print out the source code on paper and use a pencil: circle the { and draw a line to its } and circle that. Continue until all the {s are connected to a } and all }s are connected to a {
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Need some minor help.

    Ok I will try that. Now once I figure that out will my methods like this code be ok still or do I need to move them around more?
    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 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();
    												}//end Integer parse
    						return isValid;
     
    	}
     
    					//Next Method
    					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 validateInput
     
    					private static void validInput() {
    						// TODO Auto-generated method stub
     
     
     
    	}
    }
    [COLOR="Silver"]

  12. #37
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need some minor help.

    The formatting for the code is poor which makes it very hard to read.

    Review this pseudo code from an earlier post as a suggestion for what order to do things:
    get input from user
    validate input
    use input in computations
    print out results


    Where are the comments on the end }s???
    To clearly see which } ends a method,
    label all the }s that end a method with a comment:
    } // end main()

    } // end validateInput()


    Each method should have only one ending }
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Need some minor help.

    Does this read any better?
    Declare constants
    Declare variables
    get input
    method 1
    method 2
    perform conversion
    display report

    Sorry this is taking so long, Im a visual learner rather then just reading things.

  14. #39
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need some minor help.

    What are the steps: method1 and method2? Their names don't have any relationship to what the program is doing.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Need some minor help.

    I know i just wrote that as an example. My first method is //Integer.parse which at the end of the method or at least what i think is the end just before the return isValid. I have }//end Integer.parse.
    As for the other method //ValidateInput, on the line following validInput(); i have }//end validateInput

  16. #41
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need some minor help.

    Have you fixed the compiler errors yet?
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Need some minor help.

    Ok let me try a different approach to this one step at a time.
    Could you tell me if my methods are correct, their separate. just the methods none of my conversion equations on here yet.

    public class validateInput {
     
    	//ValidateInput Method
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		int minRange = 0;
    		int maxRange = 212;
     
    		validInput (minRange, maxRange);
    	}
     
    	private static boolean validInput(int minRange, int maxRange) {
    		boolean True = false;
    		// TODO Auto-generated method stub
    		boolean withinrange = True;
     
    		int a = 0;
    		if (a < minRange || a > maxRange);
    		System.out.println("Out of Range");
    		withinrange = false;
     
    		return withinrange;
    	}//End validateInput method
     
    }//End main method

    import java.util.Scanner;
    public class integerparsetwo {
     
     
     
    	//Integer parse Method
    	public static boolean validInput(String[] args, String Inputnumber) {
    		// TODO Auto-generated method stub
    		int fTemp, fDist, pWeight;
    		boolean isValid = true;
    		boolean validInput = true;
     
     
    		try {
    			fTemp = Integer.parseInt(Inputnumber);
    			fDist = Integer.parseInt(Inputnumber);
    			pWeight = Integer.parseInt(Inputnumber);
     
    		}
    		catch (Exception ex) {
     
    			System.out.println("The entered value is invalid");
    			validInput  = false;
    		}
    		return validInput;
     
    	}//End integerparse method
     
    }//End main method

    These are on two different classes just so I could write them out. So am I going on the right track so far and could proceed to putting in my conversions and then somehow joining the two classes to one project.
    Oh and when I try to run either of them right now it just says Out of range like my println has in the validateinput method. But I cant enter any numbers as of right now.

  18. #43
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need some minor help.

    }//End validateInput method  <<<<<<<A
     
    }//End main method   <<<<<<<<<<B

    There is an error right there. It looks like the end of the main() method at B includes another method ending at A.
    That is not allowed.


    Is the comment correct? Are those the ending }s of methods?

    		if (a < minRange || a > maxRange);
    		System.out.println("Out of Range");

    The way that is coded looks like two statements both of which will be executed.
    So the println will always execute.
    Statements following an if statement should be inside of {}s
    		if (a < minRange || a > maxRange)  {
    		    System.out.println("Out of Range");
                    }
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Need some minor help.

    the A comment is the ending of the method. the B comment is the end of the main which I thought I had to put. But all the { } are correct. I just found a video on how to do exactly what I needed and it works heres that code;
    import java.util.*;
    public class InputValidation {
    	public static void main(String[] args) {
    		int value=-1;
    		Scanner inputScanner = new Scanner(System.in);
    		do {
    			System.out.println("Enter a value (0-212); ");
    			try {
    				value = inputScanner.nextInt();
    				if (value<0 || value>212) {
    					System.out.println("Out of range");
    				}
    			}
    			catch (Exception e) {
    				System.out.println("This value is invalid.");
    				inputScanner.next();
    			}
    		} while (value<0 || value>212);
    		System.out.println("You entered " + value);
    	}
    	//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);
    	int fTemp, fDist, pWeight, number, guess = -1;
    	double cTemp, mDist, kWeight, K, I, S;
     
    	{		
    	//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 ");
    }
    }

    Even has my extra credit in it. Ok Now all I have to do is get these in the correct order Im guessing so that it will convert the temps into the different variations of temps and so on and so forth. Am I looking to understand it now?

  20. #45
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need some minor help.

    It is confusing to have comments that are wrong. The end of a class is different than the end of a method.

    can I now take my conversions and variables and get input from earlier in the day and put them below the metho
    Earlier there was pseudo code that listed a possible order of the steps to solve the problem. Review them.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Need some minor help.

    I did, Im just trying to configure them in the correct place to get it all working. Do I add the other information in the do loop or do I add them around the loop?

  22. #47
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need some minor help.

    What step in the list of pseudo code steps does the code in the do loop accomplish?


    What happens when the code in post#44 is compiled and executed?

    If you would label the end of methods it could help you see what the code can do.
    For example the end of the main() method is before the code to do the rest of the steps in the list of steps.
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Need some minor help.

    That would be the validate input part of pseudo code.

    As for when it is executed, it does almost everything i need. If I enter 250 it states that it is out of range, if I enter abc it states that it is invalid, if I enter 212 it stops.
    When I say almost everything I mean I need to be able to enter a temperature, distance and weight for it to then be validated.

    So I have to figure out where to put my equations for the conversions in the loop?


    So im guessing it would look something like this.
    Enter a temperature, distance, weight- for the get input
    the loop that validates the information entered
    the calculations somewhere either in the loop or outside
    and last the display report outside the loop?

    Am I getting closer?

  24. #49
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Need some minor help.

    Break down the step: Compute the results
    into simple single steps.
    Is there any need for a loop to compute the results?
    If you don't understand my answer, don't ignore it, ask a question.

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

    Default Re: Need some minor help.

    The loop is for extra credit.

    So should I do something like the fahrenheit to celsius on one line and the fahrenheit to kelvin later on in the code?

    Or put the conversion somehow about the loop?

Page 2 of 3 FirstFirst 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