import java.util.Scanner;
public class SwitchStatement {
private String courseName;
private int total;
private int gradeCounter;
private int aCount;
private int bCount;
private int cCount;
private int dCount;
private int fCount;
public SwitchStatement(String name){
courseName = name;
}
public String getCourseName(){
return courseName;
}
public void displayMessage(){
System.out.println("Welcome to the grade book for " + getCourseName());
}
public void displayMessage1(){
System.out.println("Enter The ineger grades in the range of 0 - 100\n"
+"Please Enter <Ctrl> z then press enter to stop entering grades.");
}
public void counter(){
int grade;
Scanner input = new Scanner(System.in);
System.out.println("Please Enter Your Grades or -1 to quit: ");
grade = input.nextInt();
if (grade != -1){
while (grade != -1){
grade = input.nextInt();
gradeCounter = gradeCounter + 1;
total = total + grade;
}//while statement ends
}else System.out.println("You have not entered any grades.");
}//method ends
public void counterofletters(int grade){
switch (grade / 10){
case 9:
case 10:
++aCount;
break;
case 8:
++bCount;
break;
case 7:
++cCount;
break;
case 6:
++dCount;
break;
default:
++fCount;
break;
}//switch end
}//method end
public void displayValues(){
double average;
average = (double) total / gradeCounter;
System.out.println("The number of grades entered is " + gradeCounter);
System.out.println("The total of the grades is " + total);
System.out.println("The Average of the grades is " + average);
System.out.println("The number of students who received each grade:\n"
+ "Grade A:" + aCount + "\nGrade B: " + bCount +
"\nGrade C: " + cCount + "\nGrade D:" + dCount +
"\nGrade F: " + fCount);
}
}//Class end
//new Class
public class SwitchStatementTest {
public static void main(String[] args){
SwitchStatement myStatement = new SwitchStatement("Biology");
myStatement.displayMessage();
myStatement.displayMessage1();
myStatement.counter();
myStatement.counterofletters(0);
myStatement.displayValues();
}
}
Here, i could not understand how to call counterofLetters method in the driver class.