Question: - Create a class called Student public class Student { private int id; private String name; public Student(int id, String name){ this.id = id; this.name
- Create a class called Student public class Student { private int id; private String name; public Student(int id, String name){ this.id = id; this.name = name; } public int getId() { return id; } public void setId(int id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } } //create a class called StudentManager and complete the missing codes per the instruction written in purple.
public class StudentManager { List studentList = new ArrayList(); // used to add a collection of student objects private void readAddress() throws IOException { FileReader fd = new FileReader("add inside here the full path to the file address.txt that you created above"); //something is missing here. Please add your code here to fix the missing code String line = br.readLine(); //This line reads the first line Student student; //variable declaration while (line != null){ String[] data = line.split(","); // this split each line read from the file. ex 1,Mike student = new Student(Integer.parseInt(data[0]),data[1]); // add the student object in the List studentList below line = br.readLine(); } } }
- Inside the StudentManager class, create a method called display
public void display(){ for(Student s : studentList){ // show each student name here } }
- What does the following method do if you run it inside the StudentManager Class?
public Student method(String name){ for(Student s : studentList){ if(s.getName().equalsIgnoreCase(name)) { return s; } } return null; } Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
