Can you guys solve this for me : JAVA Classroom Grades Analyser


#1
import java.util.ArrayList;
class GRadeAnalyser{
  public GradeAnalyser(){
    }

public int getAverage(grades){
  ArrayList<Integer> grades=new ArrayList<Integer>();
  if(grades.size<1){
    System.out.println("Error! The ArrayList is not empty.");
    return 0;
  }else{
    int sum=0;
  }
    for(Integer grade:grades){
      sum=sum+grade;
    }
  int average= sum/grades.size;
  System.out.println(grades.get(average));
  return average;
  }
  
  public static void main(String[]args){
    ArrayList<Integer> myClassroom=new ArrayList<Integer>();
    myClassroom.add(98);
    myClassroom.add(92);
    myClassroom.add(88);
    myClassroom.add(75);
    myClassroom.add(61);
    myClassroom.add(89);
    myClassroom.add(95);
    GradeAnalyser myAnalysor=new GradeAnalyser();
    myAnalyser.getAverage(myClassroom);
    System.out.println(myClassroom.get(0));
    System.out.println(myClassroom.get(6));
    
  }
}


and here is the error I got…

GradeAnalyzer.java:3: error: invalid method declaration; return type required
public GradeAnalyser(){
^
GradeAnalyzer.java:6: error: expected
public int getAverage(grades){
^
2 errors


#2

Hello? Anyone pls…


#3

your constructor (which is also empty) doesn’t have the same name as the class, this will throw an error.

its a forum, getting a reply might take time.


#4

Can u show me how should I correct it pls… Thanks


#5

correct the typo of your GradeAnalyser class


#6

But… still can’t debug


#7

you can’t change an R into r because you made a typo in a class name?


#8

I changed it , but it still doesn’t work


#9

can i then see an updated version of your code? Maybe the new error gives you new clues on how to solve it?


#10

import java.util.ArrayList;
class GradeAnalyser{
public GradeAnalyser(){
}

public int getAverage(grades){
ArrayList grades=new ArrayList();
if(grades.size<1){
System.out.println(“Error! The ArrayList is not empty.”);
return 0;
}else{
int sum=0;
}
for(Integer grade:grades){
sum=sum+grade;
}
int average= sum/grades.size;
System.out.println(grades.get(average));
return average;
}

public static void main(String[]args){
ArrayList myClassroom=new ArrayList();
myClassroom.add(98);
myClassroom.add(92);
myClassroom.add(88);
myClassroom.add(75);
myClassroom.add(61);
myClassroom.add(89);
myClassroom.add(95);
GradeAnalyser myAnalysor=new GradeAnalyser();
myAnalyser.getAverage(myClassroom);
System.out.println(myClassroom.get(0));
System.out.println(myClassroom.get(6));

}
}


#11

The error:
GradeAnalyzer.java:6: error: expected
public int getAverage(grades){
^
1 error


#12

your constructor is empty, maybe it should have content?


#13

still cannot eh… I don’t know


#14

I am having the same error in the next project too: personal library…

import java.util.HashMap;
class Library{
public Library(){
}

public void getFinishedBooks(library){
HashMap<String, Boolean> library=new HashMap<String, Boolean>();
if(library.size<1){
System.out.println(“The HashMap is empty.”);
}else{

  for(String book : getFinishedBooks.keyset()){
    
    if(library.get(book)==true){
      System.out.println(book);
    }
  }
}

}

public static void main(String[]args){
HashMap<String,Boolean> myBooks=new HashMap<String,Boolean>();
myBooks.put(“Road Down The Funnel”, true);
myBooks.put(“Rat: A Biology”, false);
myBooks.put(“TimeIn”,true);
myBooks.put(“3D Food Printing”, false);
Library myLibrary=new Library();
myLibrary.getFinishedBooks(myBooks);
incompleteBooks=books-getFinishedBooks;
System.out.println(incompleteBooks);
}
}

The error is still Java 6:
Library.java:6: error: expected
public void getFinishedBooks(library){
^
1 error


#15

parameters have types


#16

Can u state in details with the answer… Thanks


#17

your parameter lacks a type.

You may want to write a far more basic method, perhaps one that adds two numbers together.

class Main {
    // create a static method called add that returns the sum of two Integers

    public static void main(String[] args) {
        System.out.println(add(3, 4));  // this should print 7
    }
}

#18

Can u kindly send me the full answer for this code…


#19

if you want the code, you can use the solution button (which appears after several failed attempts). The forum is for explanation.


#20

If you write something far more basic which will be much easier to debug and google examples for

Then, when you have that working, either you’ll have found what you did differently, or you can slowly turn this into the one you’re debugging and see when it stops compiling