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

I keep getting an error. I asked a question yesterday and it was posted but I ge

ID: 3818683 • Letter: I

Question

I keep getting an error. I asked a question yesterday and it was posted but I get an error What am I doing wrong. Also I am to drop the lowest score when I determine the grade. This one counts all scores. thanks Here is my program and my issues. +++++++++++++++++++++++++++ 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 } } +++++++++++++++++++++++++++ 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=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; } } +++++++++++++++++++++++++++ ClassDemo.java:17: error: cannot find symbol MyClass c1 = new MyClass(); ^ symbol: class MyClass location: class ClassDemo ClassDemo.java:17: error: cannot find symbol MyClass c1 = new MyClass(); ^ symbol: class MyClass location: class ClassDemo 2 errors ----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete. My stupis errors they are in the same folder. And i tried to change wording but that didnt work, so I am at a loss. thanks ahead of time

Explanation / Answer

MyClass.java

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 } }
   }

   public void setNames(String names, int i) {
       this.names[i] = names;
   }

   public void setGrades(char grade, int i) {
       this.grades[i]= grade;
   }

   public void setScores(int scores, int i, int j) {
       this.scores[i][j] = scores;
   }

}

ClassDemo.java

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();
           c1.setNames(names[i], i);//setting the name;
           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 {
                   c1.setScores(score, i, j);//sets scores
                   if(low>score){
                       low=score;
                   }
               }
           }
           scores=c1.getScores();
           avg=calculateAvg(scores[i], low);
           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';
           }
           c1.setGrades(grades[i], i);
          
       }
       c1.displayDetails();
   }
   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:
a
Enter Score:1
10
Enter Score:2
20
Enter Score:3
30
Enter Score:4
40
Enter details of Student 2:-
Enter name:
b
Enter Score:1
10
Enter Score:2
20
Enter Score:3
30
Enter Score:4
40
Enter details of Student 3:-
Enter name:
c
Enter Score:1
10
Enter Score:2
20
Enter Score:3
30
Enter Score:4
40
Enter details of Student 4:-
Enter name:
d
Enter Score:1
10
Enter Score:2
20
Enter Score:3
30
Enter Score:4
40
Enter details of Student 5:-
Enter name:
e
Enter Score:1
10
Enter Score:2
20
Enter Score:3
30
Enter Score:4
40


************ Details Entered Are ************
Student Name:a Average Score:25 Grade Scored:F
Student Name:b Average Score:25 Grade Scored:F
Student Name:c Average Score:25 Grade Scored:F
Student Name:d Average Score:25 Grade Scored:F
Student Name:e Average Score:25 Grade Scored:F

----------------output----------------------

Note: please keep both files in the same folder. also i have updated the program based on your requirement. Please let me know if you face any issue. God bless you!!