Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I tried to modify my program for the grade book ( i rewrote it) for programming

ID: 3819847 • Letter: I

Question

I tried to modify my program for the grade book ( i rewrote it) for programming cahalleng 7 for chapter 7 so that it drops the lowest score when determining the test score average and the letter grade. Why am I getting an error?

import javax.swing.JOptionPane;// needed for the pop up window


public class Teacher1 {
//Creating Arrays
String names[]=new String[5];
char grades[]=new char[5];
double tests[][]=new double[5][4];
double avgarr[]=new double[5];
Scanner sc=null;
  
//Default constructor
public Teacher1() {
sc=new Scanner(System.in);
}
  
/*this method will get each student information
* and populates that information into an array
*/
public void getStudentsTestScore()
{
for(int i=0;i<5;i++)
{
//getting the name of each student
System.out.print("Enter Name of Student "+(i+1)+" :");
names[i]=sc.next();
for(int j=0;j<4;j++)

//Getting the test score in each test of every student
System.out.print(" Test "+(j+1)+" score :");
if(tests[i][j]>100)
{
System.out.println("in appropriate value TRY AGAIN");
j--;
continue;
  
}
System.out.println(" ");
}
}
  
/** this should remove the lowest score
it was a pain in the nether region.   
*/
public void removeLowest()
{
int getLowScorePosition;
double lowestScoreIndex;
  
int lowScoreIndex = getLowScorePosition();
remove(lowScoreIndex);
}
public void removeLowestScore()
{
int lowScoreIndex = GetLowScorePostion();
double lowestScore = tests[0];
for (int i = 1; i < currentSize; i++)
{
if (scores[i]<lowestScore)
{
lowestScore = double Teacher1.tests;
lowestScoreIndex = i;
}
}
return lowestScoreIndex;
  
}

/* this method will display the grade of the student
* based on user entered name which is passed
* as parameter to this method
*/
public char getStudentGrade(String name)
{
char grade = 0;
double sum,avg=0.0;
for(int h=0;h<5;h++)
{
sum=0.0;
for(int m=0;m<4;m++)
{
//calculating the total score in all 4 tests of each student
sum+=tests[h][m];
}
//calculating average
avg=sum/4;

//Populating into an array
avgarr[h]=avg;
  
//based on the average test score corresponding grade will be given
if(avg>=90 && avg<=100)
{
grade='A';
}
else if(avg>=80 && avg<=89)
{
grade='B';
}
else if(avg>=70 && avg<=79)
{
grade='C';
}
else if(avg>=60 && avg<=69)
{
grade='D';
}
else if(avg<=59)
{
grade='F';
}
grades[h]=grade;
}
  
//Getting the corresponding student grade
for(int i=0;i<5;i++)
if(names[i].equalsIgnoreCase(name))
{
grade=grades[i];
}
return grade;
}

/* This will return the average test score of a student
* whose name is passed as parameter to this method
*/
public double getStudentAvgTestScore(String name)
{
double sum=0.0,avg=0.0;
for(int i=0;i<5;i++)
if(names[i].equalsIgnoreCase(name))
{
  
for(int k=0;k<4;k++)
{
sum+=tests[i][k];
}
}
avg=sum/4;
return avg;
}
  
//toString(0 method displays each student name,average test score and grade
@Override
public String toString() {
for(int i=0;i<5;i++)
{
System.out.println(" Student Name :"+names[i]);
System.out.println("Average Test Score :"+avgarr[i]);
System.out.println("Grade :"+grades[i]);

}
  
return "";
}
  
}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

import javax.swing.JOptionPane;// needed for the pop up window


public class Teacher1 {
//Creating Arrays
String names[]=new String[5];
char grades[]=new char[5];
double tests[][]=new double[5][4];
double avgarr[]=new double[5];
Scanner sc=null;
  
//Default constructor
public Teacher1() {
sc=new Scanner(System.in);
}
  
/*this method will get each student information
* and populates that information into an array
*/
public void getStudentsTestScore()
{
for(int i=0;i<5;i++)
{
//getting the name of each student
System.out.print("Enter Name of Student "+(i+1)+" :");
names[i]=sc.next();
for(int j=0;j<4;j++)

//Getting the test score in each test of every student
System.out.print(" Test "+(j+1)+" score :");
if(tests[i][j]>100)
{
System.out.println("in appropriate value TRY AGAIN");
j--;
continue;
  
}
System.out.println(" ");
}
}
  
/** this should remove the lowest score
it was a pain in the nether region.   
*/
public void removeLowest()
{
int getLowScorePosition;
double lowestScoreIndex;
  
int lowScoreIndex = getLowScorePosition();
remove(lowScoreIndex);
}
public void removeLowestScore()
{
int lowScoreIndex = GetLowScorePostion();
double lowestScore = tests[0];
for (int i = 1; i < currentSize; i++)
{
if (scores[i]<lowestScore)
{
lowestScore = double Teacher1.tests;
lowestScoreIndex = i;
}
}
return lowestScoreIndex;
  
}

/* this method will display the grade of the student
* based on user entered name which is passed
* as parameter to this method
*/
public char getStudentGrade(String name)
{
char grade = 0;
double sum,avg=0.0;
for(int h=0;h<5;h++)
{
sum=0.0;
for(int m=0;m<4;m++)
{
//calculating the total score in all 4 tests of each student
sum+=tests[h][m];
}
//calculating average
avg=sum/4;

//Populating into an array
avgarr[h]=avg;
  
//based on the average test score corresponding grade will be given
if(avg>=90 && avg<=100)
{
grade='A';
}
else if(avg>=80 && avg<=89)
{
grade='B';
}
else if(avg>=70 && avg<=79)
{
grade='C';
}
else if(avg>=60 && avg<=69)
{
grade='D';
}
else if(avg<=59)
{
grade='F';
}
grades[h]=grade;
}
  
//Getting the corresponding student grade
for(int i=0;i<5;i++)
if(names[i].equalsIgnoreCase(name))
{
grade=grades[i];
}
return grade;
}

/* This will return the average test score of a student
* whose name is passed as parameter to this method
*/
public double getStudentAvgTestScore(String name)
{
double sum=0.0,avg=0.0;
for(int i=0;i<5;i++)
if(names[i].equalsIgnoreCase(name))
{
  
for(int k=0;k<4;k++)
{
sum+=tests[i][k];
}
}
avg=sum/4;
return avg;
}
  
//toString(0 method displays each student name,average test score and grade
@Override
public String toString() {
for(int i=0;i<5;i++)
{
System.out.println(" Student Name :"+names[i]);
System.out.println("Average Test Score :"+avgarr[i]);
System.out.println("Grade :"+grades[i]);

}
  
return "";
}
  
}

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

I get errors associated with the lowest score = double teacher.tests. is says about class is expected. and illegal start of expression

Explanation / Answer

package myProject;
import java.util.*;
//Class Teacher1 definition
public class Teacher1
{
   //Creating Arrays
   String names[]=new String[5];
   char grades[]=new char[5];
   double tests[][]=new double[5][4];
   double avgarr[]=new double[5];
   static Scanner sc=null;
  
   //Default constructor
   public Teacher1()
   {
       sc = new Scanner(System.in);
   }
  
   /*this method will get each student information
   * and populates that information into an array
   */
   public void getStudentsTestScore()
   {
       int i, j;
       //Loops for 5 students
   for(i=0;i<5;i++)
   {
       //getting the name of each student
   System.out.print("Enter Name of Student "+(i+1)+" :");
   names[i]=sc.next();
   //Loops for 4 subject marks
   for(j=0;j<4;j++)
   {   
   //Getting the test score in each test of every student
   System.out.print(" Test "+(j+1)+" score :");
   tests[i][j] = sc.nextDouble();
   //Validates test mark if greater than 100 asks to reenter
   if(tests[i][j]>100)
   {
       System.out.println("in appropriate value TRY AGAIN");
       j--;
       continue;
   }//End of if
   System.out.println(" ");
   }//End of inner for loop
   }//End of outer for loop
   }//End of method
  
   /** This should remove the lowest score it was a pain in the nether region. */
   public void removeLowest(int lowStudentIndex, int lowScoreIndex)
   {
       //Nullify the lowest test score
       System.out.println("Student " + names[lowStudentIndex]);
       System.out.println("Lowest Mark " + tests[lowStudentIndex][lowScoreIndex]);
   tests[lowStudentIndex][lowScoreIndex] = 0;
   }//End of method
   /** Method to find out the lowest score index of a student. */
   public void getLowScorePosition()
   {
       //Initializes both index to -1
          int lowScoreIndex = -1;
          int lowStudentIndex = -1;
          //Assumes the first score is the lowest
   double lowestScore = tests[0][0];
   //Loops for 5 students
   for (int i = 0; i < 5; i++)
   {
       //Loops for 4 test scores
       for(int j = 0; j < 4; j++)
       {
           //Checks if the current score is less than the earliest lowestScore then update
           if (tests[i][j] < lowestScore)
           {
               //Update the lowest score to the current score
               lowestScore = tests[i][j];
               //Update the lowest score index to the current index for score
               lowScoreIndex = j;
               //Update the lowest student index to the current index for student
               lowStudentIndex = i;
           }//End of if
       }//End of inner for loop
   }//End of outer for loop
   //Calls the method to nullify the score
   removeLowest(lowStudentIndex, lowScoreIndex);
   }//End of method
     
   /* this method will display the grade of the student
   * based on user entered name which is passed
   * as parameter to this method
   */
   public char getStudentGrade(String name)
   {
          char grade = 0;
   double sum,avg=0.0;
   //For 5 students
   for(int h=0;h<5;h++)
   {
       //Initializes sum to zero for each student
       sum=0.0;
       //For 4 test scores
   for(int m=0;m<4;m++)
   {
       //calculating the total score in all 4 tests of each student
   sum+=tests[h][m];
   }
   //calculating average
   avg=sum/4;     
   //Populating into an array
   avgarr[h]=avg;
  
   //based on the average test score corresponding grade will be given
   if(avg>=90 && avg<=100)
   {
       grade='A';
   }
   else if(avg>=80 && avg<=89)
   {
       grade='B';
   }
   else if(avg>=70 && avg<=79)
   {
       grade='C';
   }
   else if(avg>=60 && avg<=69)
   {
       grade='D';
   }
   else if(avg<=59)
   {
       grade='F';
   }
   grades[h]=grade;
   }//End of for loop
   //Getting the corresponding student grade
   for(int i=0;i<5;i++)
       if(names[i].equalsIgnoreCase(name))
       {
           grade=grades[i];
       }
   //Returns the grade
   return grade;
   }//End of method
   /* This will return the average test score of a student
   * whose name is passed as parameter to this method
   */
   public double getStudentAvgTestScore(String name)
   {
   double sum=0.0,avg=0.0;
   //For 5 students
   for(int i=0;i<5;i++)
       //Compares the names with ignore case
       if(names[i].equalsIgnoreCase(name))
       {
              //For 4 subject marks
   for(int k=0;k<4;k++)
   {
       //Calculates total
   sum+=tests[i][k];
   }//End of inner for loop
   }//End of if
   //Calculates average
   avg=sum/4;
   //Returns average
   return avg;
   }//End of method
  
   //toString(0 method displays each student name,average test score and grade
   @Override
   public String toString()
   {
       //For 5 students
   for(int i=0;i<5;i++)
   {
   System.out.println(" Student Name :"+names[i]);
   System.out.println("Average Test Score :"+avgarr[i]);
   System.out.println("Grade :"+grades[i]);
   }//End of for loop
   return "";
   }//End of method
     
   //Main method
   public static void main(String ss[])
   {
       //Creates an object of scanner class to accept name
       Scanner sc = new Scanner(System.in);
       //Creates an object of Teacher1 class
       Teacher1 tt = new Teacher1();
       tt.getStudentsTestScore();
       tt.getLowScorePosition();
       System.out.println("Enter the Student Name to see the Grade: ");
       String name1 = sc.nextLine();         
       System.out.println(tt.getStudentGrade(name1));
       System.out.println(Double.toString(tt.getStudentAvgTestScore(name1)));
   }//End of main method
  
   }//End of class

Output:

Enter Name of Student 1 :Pyari
Test 1 score :89

Test 2 score :78

Test 3 score :595
in appropriate value TRY AGAIN
Test 3 score :67

Test 4 score :88

Enter Name of Student 2 :Mohan
Test 1 score :78

Test 2 score :89

Test 3 score :56

Test 4 score :67

Enter Name of Student 3 :Sahu
Test 1 score :82

Test 2 score :71

Test 3 score :90

Test 4 score :70

Enter Name of Student 4 :Sasmita
Test 1 score :59

Test 2 score :68

Test 3 score :93

Test 4 score :44

Enter Name of Student 5 :Rasmita
Test 1 score :67

Test 2 score :45

Test 3 score :38

Test 4 score :82

Student Rasmita
Lowest Mark 38.0
Enter the Student Name to see the Grade:
Sahu
C
Enter the Student Name to see the Average:
78.25