import java.io.*;
import opencsv.*;
import org.apache.commons.math.*;
public class Main {
Main() {
grades = new StudentGrade[202];
}
StudentGrade[] grades;
void readScores() throws IOException {
String RAWSCORES="rawscores.csv";
CSVReader reader = new CSVReader(new FileReader(RAWSCORES));
String [] nextLine = reader.readNext(); // read the 1st line
while (nextLine != null) {
//
// there are 2 columns in the CSV, we access each column using the array index
//
System.out.println("Name: [" + nextLine[0] + "]");
System.out.println("Score: [" + nextLine[1] + "]");
nextLine = reader.readNext(); // read the following line
}
}
double calcMean() {
return 0;
}
class test{
public static void main(String argu[]){
int StudentGrade[] = {1,2,3,4,5};
double mean = 0, total = 0;
for (int i=0;itotal += StudentGrade[i];
}
mean = total/StudentGrade.length;
System.out.print(mean +"\n");
}
}Most importantly is this part only..
double mean = 0, total = 0;
for (int i=0;itotal += StudentGrade[i];
}
mean = total/StudentGrade.length;
Main() {
grades = new StudentGrade[202];
}
StudentGrade[] grades;Originally posted by MosPosterior:I don't have so dumb to copy and paste everything...
[b]code:Main() {
grades = new StudentGrade[202];
}
StudentGrade[] grades;
haha.. because of this line...
The StudentGrade is another class... for example, it should be StudentGrade[i].grade()
You need to parse the variables from that StudentGrade class here, either by extend or same package..
Haha... show me all your .java files? I help you write..![]()
[/b]
import java.io.*;
import opencsv.*;
import org.apache.commons.math.*; //redundant - can be deleted
public class Main {
static String RAWSCORES ="rawscores.csv";
public static void main(String argu[]){ //Main is deleted, redundant also
try{
readScores();
System.out.print("\n\n" +calcMean() +"\n");
}catch(IOException e){
System.err.println(RAWSCORES +" not found");
}
}
static void readScores() throws IOException {
CSVReader reader = new CSVReader(new FileReader(RAWSCORES));
String [] nextLine = reader.readNext();
while (nextLine != null) {
System.out.println("Name: [" + nextLine[0] + "]");
System.out.println("Score: [" + nextLine[1] + "]");
nextLine = reader.readNext();
}
}
static double calcMean() throws IOException{
CSVReader reader = new CSVReader(new FileReader(RAWSCORES));
String [] nextLine = reader.readNext();
double total = 0;
while (nextLine != null) {
total += Double.parseDouble(String.valueOf(nextLine[1]));
nextLine = reader.readNext(); //normal mean cal. here
}
return Math.round(total/202); //optional
}
}
Why this face? I don't know, ask here lor. Teacher not in class ma.Originally posted by stellazio:![]()
![]()
![]()