This is my specific instruction. so I want you to make a new class called StudentsService in
Fantastic news! We've Found the answer you've been seeking!
Question:
This is my specific instruction. so I want you to make a new class called StudentsService in the com.sait.itsc315.services package AND modify AppDriver. I will attach my appdriver, student, students class below. Thank you!
AppDriver.javapackage com.sait.itsc315.application;
import java.io.*;
import com.sait.itsc315.problemdomain.*;
public class AppDriver {
/**
* Entry point for program.
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
Students students = new Students();
// Create instance of StudentsService
// Print "Honor Students: "
// Loop through honor students
// Print each students information
// Print "Declining Students: "
// Loop through honor students
// Print each students information
}
}
Student.java
package com.sait.itsc315.problemdomain;
public class Student {
private int id;
private String name;
private double gpa;
/**
* Constructor for a student.
* @param id Student's ID
* @param name Name of student.
* @param gpa Student's GPA.
*/
public Student(int id, String name, double gpa) {
this.id = id;
this.name = name;
this.gpa = gpa;
}
/**
* @return the id
*/
public int getId() {
return id;
}
/**
* @param id the id to set
*/
public void setId(int id) {
this.id = id;
}
/**
* @return the name
*/
public String getName() {
return name;
}
/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
* @return the gpa
*/
public double getGpa() {
return gpa;
}
/**
* @param gpa the gpa to set
*/
public void setGpa(double gpa) {
this.gpa = gpa;
}
public String toString() {
return String.format("%d - %s - %.2f", this.id, this.name, this.gpa);
}
}
Students.java
package com.sait.itsc315.problemdomain;
import java.io.*;
import java.util.*;
public class Students {
public static final String TEXT_FILE = "res/students.csv";
private ArrayList students;
public Students() throws IOException {
this.students = new ArrayList<>();
this.loadFromTextFile();
}
/**
* Loads students from text file.
* @throws IOException
*/
private void loadFromTextFile() throws IOException {
BufferedReader br = new BufferedReader(new FileReader(TEXT_FILE));
String line = br.readLine();
while (line != null) {
String[] parts = line.split(",");
int id = Integer.parseInt(parts[0]);
String name = parts[1];
double gpa = Double.parseDouble(parts[2]);
Student student = new Student(id, name, gpa);
this.students.add(student);
line = br.readLine();
}
}
/**
* Gets the students.
* @return List of students.
*/
public ArrayList getStudents() {
return this.students;
}
}
Related Book For
Measurement Theory In Action
ISBN: 9780367192181
3rd Edition
Authors: Kenneth S Shultz, David Whitney, Michael J Zickar
Posted Date: