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

So I have to modify the grade book application in Programming challange 7 (java)

ID: 3818367 • Letter: S

Question

So I have to modify the grade book application in Programming challange 7 (java) sp that it drops the lowest score when determining the average test score averages and letter grades. I have the first part done but I keep getting an error on the second part. I am not sure but I think it has to do with the way that I am stating the array.

class demo

import java.util.Scanner; // for scanner import still not worthy
import java.util.Collections; // wahoo a new util i found that did my trick
public class ClassDemo { // i had have not idea what i should call this

public static void main(String[] args) {
  
// for the scanner class
Scanner sc = new Scanner(System.in);
MyClass c1=new MyClass();
  
//For local purpose
int avg=0,sum=0;

//To get instance variables of MyClass object
String [] names;
char [] grades;
int [][] scores;
double calculateAvg;

grades=c1.getGrades();
names=c1.getNames();
scores=c1.getScores();
  
//To get details from User for 5 Students:
for(int i=0;i<5;i++){
System.out.println("Enter details of Student "+(i+1)+":-");
System.out.println("Enter name:");
names[i]=sc.next();
avg=0;
sum=0;
int score=0;
  
for(int j=0;j<4;j++){
System.out.println("Enter Score:"+(j+1));
score=sc.nextInt();

//Validating Score reallly had an issue with this not sure why
if(score <0 || score >100)
{
System.out.println("Invalid Score try again...");
j--; //Setting j back by 1 as this was wrong entry - found out this was a big issue... dumb!
continue;
}
}

  
scores[i][j]=score;
sum+=score;
}
}

public static double calculateAvg(double.GetGrades; int lowNum)
{
double sum = 0;
double average = 0;
int i = 0;
// Calcuates the average of the array list with the lowest numbers dropped

for (i = 0; i < inputs.size(); i++)
{
if (inputs.get(i) > lowNum) {
sum = sum + inputs.get(i);
}
}
average = (sum / inputs.size());
System.out.println(average);
return average;






  
//sum contains total of 4 scores
//Calculating average using sum
avg=sum/4;
//To store the grade for respective student i saved space by moving the braces.... but i dont like it
if(avg>=90 && avg<=100){
grades[i]='A';
}else if(avg>=80 && avg<=89){
grades[i]='B';
}else if(avg>=70 && avg<=79){
grades[i]='C';
}else if(avg>=60 && avg<=69){
grades[i]='D';
}else if(avg>=0 && avg<=59){
grades[i]='F';
}
}
}
******************************************************************************************************************************************************

public class MyClass {
private String [] names; //names of the studi (sorry a fall back on a former life)
private char [] grades; // self explanatory
private int [][] scores; //one for the gipper


  
  
//To my class and to initialize the new vaiables
public MyClass() {
names=new String[5];
grades=new char[5];
scores=new int[5][4];
}

// to return names
public String[] getNames() {
return names;
}
// to return the grade... but not stats
public char[] getGrades() {
return grades;
}
// to return the scores
public int[][] getScores() {
return scores;
}

//To display details of 5 students
public void displayDetails() {
int avg,sum;
System.out.println(" ************ Details Entered Are ************");
for(int i=0;i<5;i++){
avg=0;
sum=0;
for(int j=0;j<4;j++){
sum+=scores[i][j];
}
//sum contains total of 4 scores
//Calculating average using sum
avg=sum/4;

System.out.println("Student Name:"+names[i]+" Average Score:"+avg+" Grade Scored:"+grades[i]);
}
}

public String getStudentByName(String name) { //As specified,a method to return details of a given Student
for (int i = 0; i < names.length; i++) {
if(names[i].equalsIgnoreCase(name)){ //If the Student name matches in the stored names
float avg=0.0f;
for (int j = 0; j < 4; j++) {
avg+=scores[i][j];
}
avg=avg/4; //Calculated the average
return "Student Name:"+names[i]+" Average Score:"+avg+" Grade:"+grades[i]; //It will return the details as the student was found
}
}
return "Student not available"; //If Student is not found in the Stored array
}

}

i am getting the following errors and I cant seem to fix it no matter what I do. Please assist.

thanks

Ann

Explanation / Answer

Cleared all the errors and shaped the ClassDemo. I didnt touch MyClass.

You can see the output below.

PROGRAM CODE:

package util;

import java.util.Scanner; // for scanner import still not worthy

import java.util.Collections; // wahoo a new util i found that did my trick

public class ClassDemo { // i had have not idea what i should call this

   public static void main(String[] args) {

  

   // for the scanner class

   Scanner sc = new Scanner(System.in);

   MyClass c1=new MyClass();

  

   //For local purpose

   double avg,sum;

   //To get instance variables of MyClass object

   String [] names;

   char [] grades;

   int [][] scores;

   grades=c1.getGrades();

   names=c1.getNames();

   scores=c1.getScores();

  

   //To get details from User for 5 Students:

   for(int i=0;i<5;i++){

   System.out.println("Enter details of Student "+(i+1)+":-");

   System.out.println("Enter name:");

   names[i]=sc.next();

   avg = 0;

   sum=0;

   int low = 100;

   int score=0;

  

   for(int j=0;j<4;j++){

   System.out.println("Enter Score:"+(j+1));

   score=sc.nextInt();

//Validating Score reallly had an issue with this not sure why

   if(score <0 || score >100)

   {

System.out.println("Invalid Score try again...");

   j--; //Setting j back by 1 as this was wrong entry - found out this was a big issue... dumb!

   continue;

   }

   else

   {

       if(score<low)

           low = score;

       scores[i][j]=score;

   sum+=score;

   }

}

   avg = calculateAvg(scores[i], low);

   //sum contains total of 4 scores

   //Calculating average using sum

  

   //To store the grade for respective student i saved space by moving the braces.... but i dont like it

   if(avg>=90 && avg<=100){

   grades[i]='A';

   }else if(avg>=80 && avg<=89){

   grades[i]='B';

   }else if(avg>=70 && avg<=79){

   grades[i]='C';

   }else if(avg>=60 && avg<=69){

   grades[i]='D';

   }else if(avg>=0 && avg<=59){

   grades[i]='F';

   }

   }

   }

  

   public static double calculateAvg(int inputs[], int lowNum)

   {

double sum = 0;

double avg = 0;

int i = 0;

// Calcuates the average of the array list with the lowest numbers dropped

for (i = 0; i < inputs.length; i++)

{

if (inputs[i] > lowNum) {

sum = sum + inputs[i];

}

}

avg = (sum / inputs.length);

   System.out.println(avg);

   return avg;

   }

}

OUTPUT:

Enter details of Student 1:-

Enter name:

Mary

Enter Score:1

79

Enter Score:2

78

Enter Score:3

76

Enter Score:4

78

58.75

Enter details of Student 2:-

Enter name:

Peter

Enter Score:1

66

Enter Score:2

67

Enter Score:3

67

Enter Score:4

78

53.0

Enter details of Student 3:-

Enter name:

Roman

Enter Score:1

65

Enter Score:2

56

Enter Score:3

66

Enter Score:4

77

52.0

Enter details of Student 4:-

Enter name:

Rihanna

Enter Score:1

6

Enter Score:2

88

Enter Score:3

76

Enter Score:4

78

60.5

Enter details of Student 5:-

Enter name:

James

Enter Score:1

45

Enter Score:2

56

Enter Score:3

76

Enter Score:4

66

49.5

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote