Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello. I have some Java code that works, but it is not displaying the proper results. I have attached my code and a screenshot of

Hello. I have some Java code that works, but it is not displaying the proper results. I have attached my code and a screenshot of the numbers that need to be entered and the intended results. Thanks for any help!

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package u3a1_debugfixifstmts;

import java.util.Scanner;

/**

*

*

*/

public class U3A1_DebugFixIFStmts {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

// TODO code application logic here

System.out.println("Teacher's Copy");

Scanner input = new Scanner(System.in);

// prompt the user to enter 3 ints

// and read them into

// firstChoice

//secondChoice

//thirdChoices

System.out.println("Enter three integers:");

int firstChoice = 0;

int secondChoice = 0;

int thirdChoice = 0;

// loops user enters valid number

do{

System.out.println("Enter first num in range (1-7)");

firstChoice = input.nextInt();

}while(firstChoice7);

do{

System.out.println("Enter second num in range (1-7)");

secondChoice = input.nextInt();

}while(secondChoice7);

do{

System.out.println("Enter third num in range (1-7)");

thirdChoice = input.nextInt();

}while(thirdChoice7);

//Determine & print the state of choices made

if (firstChoice == 0)

System.out.println("State of choices: " +

"no choices made yet");

if (secondChoice == 0)

System.out.println("State of choices: " +

"user made first choice (" + firstChoice + ") " +

"number of choices = 1");

// changed = to ==, = is used to assign the values and == is used to compare the values

else if (thirdChoice == 0)

System.out.println("State of choices: " +

"user made first choice (" + firstChoice + ") " +

"user made second choice (" + secondChoice + ") " +

"number of choices = 2");

// ; missed

System.out.println("State of choices: " +

"user made first choice (" + firstChoice + ") " +

"user made second choice (" + secondChoice + ") " +

"user made third choice (" + thirdChoice + ") " +

"number of choices = 3");

}

}

image text in transcribedimage text in transcribed

There is no need to validate the entered three integers to ensure they comply with the above rules. (Choices are between 1 and 7 and are entered in order.) Assume the entered data will be valid. Use these valid sets of data for testing: 000 200 140 7 57 Successful completion of this assignment will show the number of non-zero choices made by the user and their values when the application is run. Your program output should look like this sample output

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions