Hi, this is my basic program for an assignment but I can't figure out why I am not getting the desired output for the grade printed and why there is a repetition of the Enter Student Name at the end before the program loops again. I have also included a screenshot of the results as well as my code.
import java.util.Scanner;
public class EvalMarks1 {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
char grade = 'F';
double cwMark = 0, examMark = 0;
int i;
String inputName;
String endProgram = "NONE";
String [] student = new String [10];
System.out.println ("Please enter name of 10 students:");
for (i = 0; i < 10; i++)
{
System.out.print ("Student " + (i+1) + ": ");
student [i] = input.nextLine();
}
print (student);
do {
System.out.print ("Please enter student name: ");
inputName = input.nextLine ();
if (inputName.matches(endProgram))
break;
else {
for (i= 0; i < 10; i++){
if (inputName.matches (student [i])){
System.out.print ("Enter " + student [i] + "'s course work mark: ");
cwMark = input.nextDouble ();
while (cwMark < 0 || cwMark > 100){
System.out.print ("I am sorry; This is not a valid range of course work mark. Please re-enter mark: ");
cwMark = input.nextDouble ();
}
System.out.print ("Enter " + student [i] + "'s exam mark: ");
examMark = input.nextDouble ();
while (examMark <0 || examMark > 100){
System.out.print ("I am sorry; This is not a valid range of exam mark. Please re-enter mark: ");
examMark = input.nextDouble ();
}
getGrade (examMark, cwMark);
System.out.print ("Grade: " + grade + "\n");
}
}
}
} while (true);
}
public static void print (String [] student)
{
int i ;
System.out.println ("List of students you entered is as follows: ");
for (i = 0; i < 10; i++)
{
System.out.print (" " + (i+1) + ". " + student [i] + "\n");
}
}
public static char getGrade (double examMark, double cwMark)
{
double averMark = (examMark + cwMark) / 2;
char grade;
if (averMark >= 0 && averMark < 50){
grade = 'F';
}
else if (averMark >= 50 && averMark < 60){
grade = 'D';
}
else if (averMark >= 60 && averMark < 70){
grade = 'C';
}
else if (averMark >= 70 && averMark < 80){
grade = 'B';
}
else{
grade = 'A';
}
return grade;
}
}