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.

Results 1 to 4 of 4

Thread: Need Help, Not sure how to fix basic error!

  1. #1
    Junior Member
    Join Date
    Sep 2012
    Posts
    26
    My Mood
    Bored
    Thanks
    6
    Thanked 5 Times in 4 Posts

    Default Need Help, Not sure how to fix basic error!

    Okay so here's my code:
     
    /*
    Paulino Rosado
    9/15/2012
    Determine the correct action to maintain proper tire pressure
    */
     
    import java.util.*;
     
    public class Ch3PA1
    {
    	public static void main(String[]args)
    	{
    		int type, frontright, frontleft, rearright, rearleft;
     
    		Scanner Keyboard = new Scanner (System.in);
     
    		System.out.println("Please enter the number that corresponds to the type of hauling you do!");
    		System.out.println("                          1. Normal                                    ");
    		System.out.println("                          2. Hauling                                   ");
    		System.out.println("                          3. Rugged                                    ");
    		type = Keyboard.nextInt();
     
    		switch(type)
    		{
    			case 1:
    				System.out.println("Please enter the current tire pressure of you're front right tire.");
    				frontright = Keyboard.nextInt();
     
    				System.out.println("Please enter the current tire pressure of you're front left tire.");
    				frontleft = Keyboard.nextInt();
     
    				System.out.println("Please enter the current tire pressure of you're rear right tire.");
    				rearright = Keyboard.nextInt();
     
    				System.out.println("Please enter the current tire pressure of you're rear left tire.");
    				rearleft = Keyboard.nextInt();
     
    				if(frontright < 33){
    					frontright = 33 - frontright;
    					System.out.println("Add "+frontright+"psi to the front right tire");
    				}else if (frontright > 43){
    					frontright = frontright - 43;
    					System.out.println("Subtract "+frontright+"psi from the front right tire");
    			    }else if(frontright <= 43 && frontright >= 33);
    			    	System.out.println("You have the correct tire pressure in the front right tire!");
     
     
    				if(frontleft < 33){
    					frontleft = 33 - frontleft;
    					System.out.println("Add "+frontleft+" psi to the front left tire");
    				}else if (frontleft > 43){
    					frontleft = frontleft - 43;
    					System.out.println("Subtract "+frontleft+" psi from the front left tire");
    				}else if(frontleft <= 43 && frontleft >= 33);
    			    	System.out.println("You have the correct tire pressure in the front left!");
     
    				if(rearright < 33){
    					rearright = 33 - rearright;
    					System.out.println("Add "+rearright+" psi to the rear right tire");
    				}else if (rearright > 43){
    					rearright = rearright - 43;
    					System.out.println("Subtract "+rearright+" psi from the rear right tire");
    			    }else if(rearright <= 43 && rearright >= 33);
    			    	System.out.println("You have the correct tire pressure in the right rear tire!");
     
    				if(rearleft < 33){
    					rearleft = 33 - rearleft;
    					System.out.println("Add "+rearleft+" psi to the rear left tire");
    				}else if (rearleft > 43){
    					rearleft = rearleft - 43;
    					System.out.println("Subtract "+rearleft+" psi from the rear left tire");
    				}else if(rearleft <= 43 && rearleft >= 33);
    			    	System.out.println("You have the correct tire pressure in the rear left tire!");
    				break;
     
    			case 2:
    				System.out.println("You picked 2");
    				break;
    			case 3:
    				System.out.println("You picked 3");
    			}
    		}
    	}
    Heres the output:
    Please enter the number that corresponds to the type of hauling you do!
                              1. Normal
                              2. Hauling
                              3. Rugged
    1
    Please enter the current tire pressure of you're front right tire.
    43
    Please enter the current tire pressure of you're front left tire.
    29
    Please enter the current tire pressure of you're rear right tire.
    43
    Please enter the current tire pressure of you're rear left tire.
    52
    Add -10psi to the front right tire
    Add 4 psi to the front left tire
    You have the correct tire pressure in the front left!
    You have the correct tire pressure in the right rear tire!
    Subtract 9 psi from the rear left tire
    You have the correct tire pressure in the rear left tire!
    Press any key to continue . . .
    It seems that after it calculates the correct tire, and gives the output, the else if statement picks up that the variable is within the bounds and outputs "You have the correct tire pressure in the tire" again, but I can't figure out how to fix it! thanks!
    Last edited by ChicoTheMan94; September 15th, 2012 at 12:10 PM.


  2. #2
    Forum Squatter newbie's Avatar
    Join Date
    Nov 2010
    Location
    North Wales
    Posts
    661
    My Mood
    Stressed
    Thanks
    28
    Thanked 115 Times in 106 Posts
    Blog Entries
    1

    Default Re: Need Help, Not sure how to fix basic error!

    Remove the colon.

    else if(frontright <= 43 && frontright >= 33);
    Please use [highlight=Java]//code goes here...[/highlight] tags when posting your code

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    26
    My Mood
    Bored
    Thanks
    6
    Thanked 5 Times in 4 Posts

    Default Re: Need Help, Not sure how to fix basic error!

    Quote Originally Posted by newbie View Post
    Remove the colon.

    else if(frontright <= 43 && frontright >= 33);
    Please for the love of god dont let it be this, I'll feel too stupid T_T

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    21,038
    Thanks
    52
    Thanked 2,280 Times in 2,251 Posts

    Default Re: Need Help, Not sure how to fix basic error!

    If you'd use the -Xlint option with the javac command, the compiler would tell you about those errors:
    Running: D:\Java\jdk1.6.0_29\bin\javac.exe    -Xlint     Ch3PA1.java
     
    Ch3PA1.java:40: warning: [empty] empty statement after if
    			    }else if(frontright <= 43 && frontright >= 33);
    			                                                  ^
    Ch3PA1.java:50: warning: [empty] empty statement after if
    				}else if(frontleft <= 43 && frontleft >= 33);
    				                                            ^
    Ch3PA1.java:59: warning: [empty] empty statement after if
    			    }else if(rearright <= 43 && rearright >= 33);
    			                                                ^
    Ch3PA1.java:68: warning: [empty] empty statement after if
    				}else if(rearleft <= 43 && rearleft >= 33);
    				                                          ^
    4 warnings
     
    4 error(s)
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Basic
    By deemu in forum Java Theory & Questions
    Replies: 1
    Last Post: March 5th, 2012, 08:36 AM
  2. A basic calculator
    By SathApoc in forum What's Wrong With My Code?
    Replies: 2
    Last Post: December 22nd, 2011, 11:47 AM
  3. Basic Calculator
    By Yes. in forum What's Wrong With My Code?
    Replies: 13
    Last Post: June 4th, 2010, 04:24 PM
  4. Basic Animation
    By tabutcher in forum Java Theory & Questions
    Replies: 0
    Last Post: April 20th, 2010, 10:07 AM
  5. Some basic questions.
    By trips in forum Java Theory & Questions
    Replies: 5
    Last Post: July 21st, 2009, 02:15 AM