/* NestedControlStructure.java
taken from textbook:
Java Programming: From Problem Analysis to Program Design
by D.S. Malik and P.S. Nair, Thomson Course Technology, 2003
Modified by Craig Persiko
*/
import java.util.Scanner;
public class NestedControlStructure
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner (System.in);
String studentId;
int testScore;
int count = 0;
System.out.print("Enter student ID "
+ "(Enter ZZZ to end): ");
studentId = keyboard.nextLine();
System.out.println();
while(!studentId.equals("ZZZ"))
{
count++;
System.out.print("Enter test score: ");
testScore = keyboard.nextInt();
keyboard.nextLine(); // dispose of newline character
System.out.println();
System.out.print("Student Id = " + studentId
+ ", test score = "
+ testScore + ", and grade = ");
if(testScore >= 90)
System.out.println("A.");
else if(testScore >= 80)
System.out.println("B.");
else if(testScore >= 70)
System.out.println("C.");
else if(testScore >= 60)
System.out.println("D.");
else
System.out.println("F.");
System.out.print("Enter student ID "
+ "(Enter ZZZ to end): ");
studentId = keyboard.nextLine();
System.out.println();
}// end while
System.out.println("\nStudents in class = " + count);
}
}
/* Sample Output:
Enter student ID (Enter ZZZ to end): 1
Enter test score: 75
Student Id = 1, test score = 75, and grade = C.
Enter student ID (Enter ZZZ to end): 50
Enter test score: 95
Student Id = 50, test score = 95, and grade = A.
Enter student ID (Enter ZZZ to end): zzz
Enter test score: 88
Student Id = zzz, test score = 88, and grade = B.
Enter student ID (Enter ZZZ to end): ZZZ
Students in class = 3
*/
syntax highlighted by Code2HTML, v. 0.9