1. Quit (exit the program) 2. Add (to the ArrayList) all the marks information about a coursework or research student by reading it from another text file and determine the student's overall mark and grade. You will need to consider how to deal with the different assessment components for the coursework and research students. You may use two different text files, one for coursework students and another for research students. The program should read the correct text file for this purpose. 3. Given student number (ID), remove the specified student and relevant information from the ArrayList. It is always good to ask the user to confirm again before removing the record. For confirmation, output the student number (ID) and the name to the user. 4. Output from the ArrayList the details (all information including the overall mark and the grade) of all students currently held in the ArrayList. 5. Compute and output the overall mark and grade for coursework or research students 6. Determine and display how many coursework or research students obtained an overall mark equal to or above the average overall mark and how many obtained an overall mark below the average overall mark 7. Given a coursework or research student number (ID), view all details of the student with that number. If the student is not found in the ArrayList, an appropriate error message is to be displayed 8. Given a coursework or research student’s name (both surname and given name – ignoring case), view all details of that student. If the student is not found in the ArrayList, an appropriate error message is to be displayed. If more than one student having the same name, display all of them. Sort the ArrayList of the student objects into ascending order of the students' numbers (IDs), and output the sorted array - implement an appropriate sorting algorithm for this, and explain why such algorithm is selected (in internal and external documentation). 10. Output the sorted ArrayList from (9) to a CSV file. If the ArrayList is not sorted, this option cannot be selected. te that the program will loop around until the user selects the first option (Quit).
import java.io.*;
import java.util.*;
public class Client {
private ArrayList<Student> students;
private String dealWithType;
public Client() {
students = new ArrayList<Student> ();
dealWithType = "coursework";
dealWithType = "research";
readStudent();
readResult();
}
public void run() {
for(Student s : students) {
s.display();
System.out.println();
}
}
private void readResult() {
for(Student s : students) {
try {
String data = getResultData(s.getId());
if(data.equals("")) {
throw new StudentNotFoundException(s.getId());
}
s.setData(data);
}catch(StudentNotFoundException ex){
System.out.println(ex);
System.out.println();
}
}
}
private String getResultData(long id) {
String toReturnLine = "";
try {
Scanner file = new Scanner(new File(dealWithType+".csv"));
// read in header and throw away
file.nextLine();
while (file.hasNextLine()) {
String line = file.nextLine();
String[] data = line.split(",");
long studentID = Long.parseLong(data[0]);
if(studentID == id) {
toReturnLine = line;
break;
}
}
file.close();
}catch(FileNotFoundException ex) {
System.out.println("students.csv File not found");
}
return toReturnLine;
}
private void readStudent(){
students.clear();
try {
Scanner file = new Scanner(new File("students.csv"));
// read in header and throw away
file.nextLine();
while (file.hasNextLine()) {
String line = file.nextLine();
String[] data = line.split(",");
String type = data[0];
String title = data[1];
String firstName = data[2];
String lastName = data[3];
long studentID = Long.parseLong(data[4]);
int dbMonth = Integer.parseInt(data[5]);
int dbDay = Integer.parseInt(data[6]);
int dbYear = Integer.parseInt(data[7]);
if(type.equals("coursework") && dealWithType.equals("coursework")) {
CourseWorkStudent cw = new CourseWorkStudent(title, firstName, lastName, studentID, dbDay, dbMonth, dbYear,type);
students.add(cw);
}else if(type.equals("research") && dealWithType.equals("research")) {
ResearchStudent r = new ResearchStudent(title, firstName, lastName, studentID, dbDay, dbMonth, dbYear,type);
students.add(r);
}
}
}catch(FileNotFoundException ex) {
System.out.println("students.csv File not found");
}
}
public static void main(String[] args) {
new Client().run();
}
}
I am required to load a file name students into the program and after doing this code, I have an error that says "students.csv File not found". And I also have to make a menu like the one requested in the 2nd image. please help!
Trending now
This is a popular solution!
Step by step
Solved in 3 steps