78.7k views
5 votes
Write a Java program called Decision that includes a while loop to prompt the user to enter 5 marks using the

JOptionPane statement and a System.out statement to output a message inside the loop highlighting a pass
mark >= 50 and <= 100. Any other mark will output a messaging stating it’s a fail.
Example of the expected output is as follows:
55 is a pass
12 is a fail

User Mark Lavin
by
4.6k points

1 Answer

0 votes

Answer:

Written in Java

import javax.swing.JOptionPane;

public class Decision{

public static void main(String[] args) {

int i = 1;

while(i<=5){

String score = JOptionPane.showInputDialog("Input <score>");

int mark = Integer.parseInt(firstNumber);

if(mark >= 50 && mark <= 100) {

JOptionPane.showMessageDialog(null, mark, " is a pass", JOptionPane.PLAIN_MESSAGE);

}

else{

JOptionPane.showMessageDialog(null, mark, " is a fail", JOptionPane.PLAIN_MESSAGE);

}

i++;

}

}

}

Step-by-step explanation:

This initializes the a counter variable i to 1

int i = 1;

The following iteration is repeated as long as i is less than or equal to 5

while(i<=5){

This prompts user for input

String score = JOptionPane.showInputDialog("Input <score>");

This converts user input to integer

int mark = Integer.parseInt(firstNumber);

This checks if input is within 50 and 100 (inclusive)

if(mark >= 50 && mark <= 100) {

This prints pass

JOptionPane.showMessageDialog(null, mark, " is a pass", JOptionPane.PLAIN_MESSAGE);

}

If otherwise

else{

This prints fail

JOptionPane.showMessageDialog(null, mark, " is a fail", JOptionPane.PLAIN_MESSAGE);

}

This increments the counter variable by 1

i++;

}

User Eugene Soldatov
by
4.8k points