Question: May I get a testplan with 5 examples for my java code: import java.io . BufferedReader; import java.io . FileReader; import java.io . IOException; import

May I get a testplan with 5 examples for my java code: import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class Project2{
private static final String FILE_NAME = "students.txt";
private static final double MAX_GPA =4.0;
private static double gpaThreshold;
public static void main(String[] args){
List students = new ArrayList<>();
double totalGpa =0;
int numStudents =0;
try (BufferedReader br = new BufferedReader(new FileReader(FILE_NAME))){
String line;
while ((line = br.readLine())!= null){
String[] studentInfo = line.split("\\s+");
String name = studentInfo[0]+""+ studentInfo[1];
int creditHours = Integer.parseInt(studentInfo[2]);
int qualityPoints = Integer.parseInt(studentInfo[3]);
String yearOrDegree = studentInfo[4];
Student student;
if (yearOrDegree.equals("Freshman")|| yearOrDegree.equals("Sophomore")|| yearOrDegree.equals("Junior")|| yearOrDegree.equals("Senior")){
student = new Undergraduate(name, creditHours, qualityPoints, yearOrDegree);
} else {
student = new Graduate(name, creditHours, qualityPoints, yearOrDegree);
}
students.add(student);
totalGpa += student.calculateGpa();
numStudents++;
}
} catch (IOException e){
System.err.println("Error: File not found.");
System.exit(1);
}
double averageGpa = totalGpa / numStudents;
gpaThreshold =(averageGpa + MAX_GPA)/2;
System.out.println("GPA threshold: "+ gpaThreshold);
System.out.println("
Students eligible for honor society:");
for (Student student : students){
if (student.eligibleForHonorSociety()){
System.out.println(student);
}
}
}
}
abstract class Student {
private String name;
private int creditHours;
private int qualityPoints;
public Student(String name, int creditHours, int qualityPoints){
this.name = name;
this.creditHours = creditHours;
this.qualityPoints = qualityPoints;
}
public double calculateGpa(){
return (double) qualityPoints / creditHours;
}
public boolean eligibleForHonorSociety(){
return calculateGpa()> gpaThreshold;
}
@Override
public String toString(){
return name +": "+ calculateGpa();
}
public static void setGpaThreshold(double threshold){
gpaThreshold = threshold;
}
}
class Undergraduate extends Student {
private String year;
public Undergraduate(String name, int creditHours, int qualityPoints, String year){
super(name, creditHours, qualityPoints);
this.year = year;
}
@Override
public boolean eligibleForHonorSociety(){
return super.eligibleForHonorSociety() && (year.equals("Junior")|| year.equals("Senior"));
}
@Override
public String toString(){
return super.toString()+","+ year;
}
}
class Graduate extends Student {
private String degree;
public Graduate(String name, int creditHours, int qualityPoints, String degree){
super(name, creditHours, qualityPoints);
this.degree = degree;
}
@Override
public boolean eligibleForHonorSociety(){
return super.eligibleForHonorSocie() && degree.equals("PhD");
}
@Override
public String toString(){
return super.toString()+","+ degree;
}
}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!