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

Thread: Can Someone PLEASE help me

  1. #1
    Junior Member
    Join Date
    Mar 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Can Someone PLEASE help me

    First off...THANK YOU!! I need some direction on how to set up a "yes" or "no" question and if its a "yes" answer...will go into a while loop to enter 3 scores..

    I need the question to say....."Would you like to enter test scores?" I am going to paste my code so you can view it.

    THIS IS WHAT I NEED THIS PROGRAM TO DO PLEASE.......(Ask if they want to enter scores? If yes go into the loop then ask for score1, then score 2, finally score3. Then calc average and display results. Then ask again if they want to enter another score).





    import javax.swing.JOptionPane;

    public class whileAssignment
    {
    public static void main (String [] args)
    {
    //declare variables

    String strScore1, strScore2,strScore3;
    int score1, score2, score3, average;

    //get user input


    THIS IS WHERE I NEED THE YES OR NO TO DICTATE WHETHER OR NOT I GO INTO THE LOOP....


    //open the while loop



    while(score1 != 74)
    {
    strScore1 = JOptionPane.showInputDialog("Would you like to enter score 1 again?");
    score1 = Integer.parseInt(strScore1);


    //close the loop
    }

    strScore2 = JOptionPane.showInputDialog("Would you like to enter score 2?");
    score2 = Integer.parseInt(strScore2);



    //open the while loop



    while(score2 != 83)
    {
    strScore2 = JOptionPane.showInputDialog("Would you like to enter score 2 again?");
    score2 = Integer.parseInt(strScore2);


    //close the loop
    }

    strScore3 = JOptionPane.showInputDialog("Would you like to enter score 3?");
    score3 = Integer.parseInt(strScore3);



    //open the while loop



    while(score3 != 91)
    {
    strScore3 = JOptionPane.showInputDialog("Would you like to enter score 3 again?");
    score3 = Integer.parseInt(strScore3);


    //close the loop
    }
    average = (score1 + score2 +score3) / 3;

    JOptionPane.showMessageDialog(null, "The average of all 3 scores is: " + average);


    }
    }


    i APPRECIATE ANY HELP AND GUIDANCE...THANK YOU!!

  2. #2
    Junior Member
    Join Date
    Mar 2013
    Posts
    1
    My Mood
    Daring
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Can Someone PLEASE help me

    I did you a great favour.
    Your code is now human-readable:


    import javax.swing.JOptionPane;
     
    public class whileAssignment 
    {
    	public static void main (String [] args)
    	{
    		//declare variables
    		String strScore1, strScore2,strScore3; 
    		int score1, score2, score3, average; 
     
    		//get user input
    		//THIS IS WHERE I NEED THE YES OR NO TO DICTATE WHETHER OR NOT I GO INTO THE LOOP....
    		//open the while loop
     
     
     
    		while(score1 != 74)
    		{
    			strScore1 = JOptionPane.showInputDialog("Would you like to enter score 1 again?");
    			score1 = Integer.parseInt(strScore1);
    			//close the loop
    		}
     
    		strScore2 = JOptionPane.showInputDialog("Would you like to enter score 2?");
    		score2 = Integer.parseInt(strScore2);
     
     
     
    		//open the while loop
    		while(score2 != 83)
    		{
    			strScore2 = JOptionPane.showInputDialog("Would you like to enter score 2 again?");
    			score2 = Integer.parseInt(strScore2);
    			//close the loop
    		}
     
    		strScore3 = JOptionPane.showInputDialog("Would you like to enter score 3?");
    		score3 = Integer.parseInt(strScore3);
     
     
    		//open the while loop
    		while(score3 != 91)
    		{
    			strScore3 = JOptionPane.showInputDialog("Would you like to enter score 3 again?");
    			score3 = Integer.parseInt(strScore3);
    			//close the loop
    		}
    		average = (score1 + score2 +score3) / 3;
    		JOptionPane.showMessageDialog(null, "The average of all 3 scores is: " + average);
    	}
    }


    --- Update ---

    I will stipulate all errors (in red), along with solutions (in blue).

    1.Lack of explanation of the nature and aim of the program in entirety.Solution is self-explanatory.
    2.Inappropriate use of 'while' loops...albeit I am incognizant of the true nature of your program. Most likely, you need replace all whiles with ifs in contrast.
    3.Lack of String variable and 'do while' loop to process continue score cycle request.Create a do while loop, that encapsulates all that block of code into the do block, employing the answer string variable as a medium to accept user input at the end of each score entry cycle.