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 12 of 12

Thread: Beginner Java Problem Help.

  1. #1
    Junior Member
    Join Date
    Feb 2013
    Posts
    10
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Beginner Java Problem Help.

    Hello, im pretty new to Java programming and im currently taking a college class involving java coding. Im doing this weeks homework and have been able to answer all of them but this one. I just cant seem to figure it out. Heres the question:

    import javax.swing.JOptionPane;
    public class name
    	{
    		public static void main(String[] args)
    		{type code here and execute
     
     
    	}
    }
    The question: Reorder the following code and plug it on the above main method. Execute and run the program on your java program for three scores (70, 80, and 90).

    else if (Average>69) LetterGrd="C";
    else if (Average>79) LetterGrd="B";
    if (Average>89) LetterGrd="A";
    input=JOptionPane.showInputDiaglot("EnterFirstScore1");
    JOptionPane.showMessageDialog(null,"The scoreis "+LetterGrd;
    score1 = Double.parseDouble(input);
    input=JoptionPane.showInputDiaglog("EnterFirstScore2");
    input=JoptionPane.showInputDiaglog("EnterFirstScore3");
    score2=Double.parseDouble(input);
    score3=Double.parseDouble(input);
    Average=(score1+score2+score3)/3;
    String input, LetterGrd;
    doublescore1,score2,score3,Average;
    else LetterGrd="F";
    else if (Average>59) LetterGrd="D";


  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: Beginner Java Problem Help.

    What have you tried and what happened?

    What order must the statements be in?
    What needs to be first?
    What next?
    And what next?


    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    Feb 2013
    Posts
    10
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Beginner Java Problem Help.

    Quote Originally Posted by Norm View Post
    What have you tried and what happened?

    What order must the statements be in?
    What needs to be first?
    What next?
    And what next?


    Please edit your post and wrap your code with
    [code=java]
    <YOUR CODE HERE>
    [/code]
    to get highlighting and preserve formatting.
    Thats the thing, im not really sure what needs to be first.

    Im guessing grade A, B, and then C?

  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: Beginner Java Problem Help.

    im not really sure what needs to be first.
    What does your textbook or notes say about the order of statements?

    There is some logic to the order.
    For example you can not add two numbers together until the user has given you the numbers.
    The result can not be printed before it is computed.
    An if must be before an else.

    What have you tried?
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: Beginner Java Problem Help.

    Should be easy enough to reverse engineer this. Look at it as an algorithm when you reorder the lines.

    For example;

    else LetterGrd="F";

    changes to ...

    otherwise assign variable LetterGrd an F.

    Do this for all the lines and then it should all make sense.

  6. #6
    Junior Member
    Join Date
    Feb 2013
    Posts
    10
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Beginner Java Problem Help.

    import javax.swing.JOptionPane;
    public class Exampart2
    	{
    		public static void main(String[] args)
    		{
    			String input, LetterGrd;
    			double score1,score2,score3,Average;
     
    			if (Average>89) LetterGrd="A";
    			else if (Average>79) LetterGrd="B";
    			else if (Average>69) LetterGrd="C";
    			else if (Average>59) LetterGrd="D";
    			else LetterGrd="F";
     
    			score1=Double.parseDouble(input);
    			score2=Double.parseDouble(input);
    			score3=Double.parseDouble(input);
     
     
     
    			Average =(score1 + score2 + score3)/3;
     
    			JOptionPane.showMessageDialog(null,"The scoreis "+LetterGrd);
    			input=JOptionPane.showInputDialog("EnterFirstScore1");
    			input=JOptionPane.showInputDialog("EnterFirstScore2");
    			input=JOptionPane.showInputDialog("EnterFirstScore3");
     
    			System.exit(0);
    		}
    }

    This is what I currently have. Using Jgrasp

  7. #7
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: Beginner Java Problem Help.

    Not quite right yet. Try and see what the program is trying to do, and then the order of the lines will be clearer.

    For example; the JOptionPane messages are asking for user input, so why are they at the end?

  8. The Following User Says Thank You to Starstreak For This Useful Post:

    darkr166 (February 24th, 2013)

  9. #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: Beginner Java Problem Help.

    The statements are almost in reversed order.
    If you don't understand my answer, don't ignore it, ask a question.

  10. The Following User Says Thank You to Norm For This Useful Post:

    darkr166 (February 24th, 2013)

  11. #9
    Junior Member
    Join Date
    Feb 2013
    Posts
    10
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Beginner Java Problem Help.

    Ok i think i got it. I was able to run it on jgrasp without a problem but can someone just verify how it looks?

    import javax.swing.JOptionPane;
    public class Exampart2
    	{
    		public static void main(String[] args)
    		{
     
    			String input, LetterGrd;
     
    			input=JOptionPane.showInputDialog("EnterFirstScore1");
    			input=JOptionPane.showInputDialog("EnterFirstScore2");
    			input=JOptionPane.showInputDialog("EnterFirstScore3");
     
     
     
    			double score1,score2,score3,Average;
     
    			score1=Double.parseDouble(input);
    			score2=Double.parseDouble(input);
    			score3=Double.parseDouble(input);
    			Average =(score1 + score2 + score3)/3;			
     
    			if (Average>89) LetterGrd="A";
    			else if (Average>79) LetterGrd="B";
    			else if (Average>69) LetterGrd="C";
    			else if (Average>59) LetterGrd="D";
    			else LetterGrd="F";
     
     
    			JOptionPane.showMessageDialog(null,"The scoreis" + LetterGrd);
     
    			System.exit(0);
    		}
    }

    edit: ok, the instruction is to put 70, 80, 90 on the windows as the values. When i do that it gives me "The score is A" but when u average the 3 scores together its an 80 which should be a B. Whats wrong here?

  12. #10
    Junior Member
    Join Date
    Feb 2013
    Posts
    10
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Beginner Java Problem Help.

    Ok soo i figured out that for the 3rd input box that shows up for "score3", whatever number is inputted there becames the letter grade.

    For instance if u put "0" for score1 and score2 and put "100" for score3 the score is still an A even though if u average them together is a 33=F.

    ...stuck trying to figure out what i did wrong.

  13. #11
    Member
    Join Date
    Sep 2012
    Posts
    128
    Thanks
    1
    Thanked 14 Times in 14 Posts

    Default Re: Beginner Java Problem Help.

    The input variable is getting assigned a value, but what happens to it?

    Follow the program through on some paper by writing down the variable name and what its value is. Is the value getting replaced at some point?

  14. The Following User Says Thank You to Starstreak For This Useful Post:

    darkr166 (February 24th, 2013)

  15. #12
    Junior Member
    Join Date
    Feb 2013
    Posts
    10
    Thanks
    5
    Thanked 0 Times in 0 Posts

    Default Re: Beginner Java Problem Help.

    Quote Originally Posted by Starstreak View Post
    The input variable is getting assigned a value, but what happens to it?

    Follow the program through on some paper by writing down the variable name and what its value is. Is the value getting replaced at some point?
    Ohhhhhhhh facepalm.gif


    I finally saw what i was doing wrong.... Thanks. bowdown.gif



    import javax.swing.JOptionPane;
    public class Exampart2
    	{
    		public static void main(String[] args)
    		{
    			String input, LetterGrd;
     
    			double score1,score2,score3,Average;		
     
    			input=JOptionPane.showInputDialog("Enter First Score1");
    				score1 = Double.parseDouble(input);
    			input=JOptionPane.showInputDialog("Enter First Score2");
    				score2 = Double.parseDouble(input);
    			input=JOptionPane.showInputDialog("Enter First Score3");
    				score3 = Double.parseDouble(input);
     
    			Average =(score1+score2+score3) /3;
     
    			if (Average>89) LetterGrd="A";
    			else if (Average>79) LetterGrd="B";
    				else if (Average>69) LetterGrd="C";
    					else if (Average>59) LetterGrd="D";
    						else LetterGrd="F";
     
    			JOptionPane.showMessageDialog(null,"The score is "+LetterGrd);			
     
    		}
    }

Similar Threads

  1. Java Speech API problem very beginner
    By yugeshshrestha in forum Java Theory & Questions
    Replies: 3
    Last Post: July 4th, 2012, 12:52 PM
  2. Beginner problem with a do-while.
    By Eliijahh in forum Loops & Control Statements
    Replies: 3
    Last Post: November 21st, 2011, 01:28 PM
  3. Replies: 10
    Last Post: October 26th, 2011, 02:22 PM
  4. Beginner Problem
    By Melvrick in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 15th, 2011, 12:29 PM
  5. Beginner Problem
    By nve5009 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 19th, 2010, 11:29 AM