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
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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
