Hello, this is homework, so I am looking for some hints, tips, resources for putting together a program that reads a text file (First name, Last name, score) and I need to print the information and include a class average and a message if a students score is more than 10 points below the average. I have started a StudentScoresApp, a StudentScores, and a IComparable.
1. I am not sure how to get the ArrayList to pass through or use the StudentScores class so I can pull out the student scores and do the average and figure out when a student falls below the class average by 10 points and print format properly the information.
2. I am not sure how to compare the data in the StudentScores class using the IComparable.
Thank you for any advice and help.
/>
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.io.File;
import java.io.FileNotFoundException;
public class StudentScoresApp {
public static void main(String[] args) {
File file = new File("myFile.txt");
ArrayList<String> myFile = new ArrayList<>();
Scanner in = null;
try {
in = new Scanner(file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
while (in.hasNextLine()){
myFile.add(in.nextLine());
}
Collections.sort(myFile);
for(int i=0; i<myFile.size(); ++i){
System.out.println(myFile.get(i));
}
}
}
public class StudentScores {
private String firstName;
private String lastName;
private int score;
public StudentScores() {
firstName = "";
lastName = "";
score = 0;
}
public void setfirstName(String firstName) {
this.firstName = firstName;
}
public String getfirstName() {
return firstName;
}
public void setlastName(String lastName) {
this.lastName = lastName;
}
public String getlastName() {
return lastName;
}
public void setScore(int score) {
this.score = score;
}
public int getscore() {
return score;
}
}
public interface IComparable {
int compareTo(Object obj);
}
1. I am not sure how to get the ArrayList to pass through or use the StudentScores class so I can pull out the student scores and do the average and figure out when a student falls below the class average by 10 points and print format properly the information.
2. I am not sure how to compare the data in the StudentScores class using the IComparable.
Thank you for any advice and help.