Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can I get UML diagram, and a testplan with 5 examples for my follwing JAVA code?: import java.io . File; import java.io . FileNotFoundException; import

Can I get UML diagram, and a testplan with 5 examples for my follwing JAVA code?: import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
// Base class representing a student
class Student {
private String name;
private int creditHours;
private int qualityPoints;
// Constructor to initialize student attributes
public Student(String name, int creditHours, int qualityPoints){
this.name = name;
this.creditHours = creditHours;
this.qualityPoints = qualityPoints;
}
// Method to calculate GPA
public double gpa(){
return (double) qualityPoints / creditHours;
}
// Method to check eligibility for honor society based on GPA threshold
public boolean eligibleForHonorSociety(){
return gpa()> HonorSociety.getGpaThreshold();
}
// Method to return a string representation of the student
@Override
public String toString(){
return "Name: "+ name +", GPA: "+ gpa();
}
// Static method to set GPA threshold in the HonorSociety class
public static void setGpaThreshold(double threshold){
HonorSociety.setGpaThreshold(threshold);
}
}
// Class representing an undergraduate student, inheriting from Student
class Undergraduate extends Student {
private String year;
// Constructor to initialize undergraduate student attributes
public Undergraduate(String name, int creditHours, int qualityPoints, String year){
super(name, creditHours, qualityPoints);
this.year = year;
}
// Overridden method to check eligibility for honor society
@Override
public boolean eligibleForHonorSociety(){
return super.eligibleForHonorSociety() && (year.equals("Junior")|| year.equals("Senior"));
}
// Overridden method to return a string representation of the undergraduate student
@Override
public String toString(){
return super.toString()+", Year: "+ year;
}
}
// Class representing a graduate student, inheriting from Student
class Graduate extends Student {
private String degree;
// Constructor to initialize graduate student attributes
public Graduate(String name, int creditHours, int qualityPoints, String degree){
super(name, creditHours, qualityPoints);
this.degree = degree;
}
// Overridden method to check eligibility for honor society
@Override
public boolean eligibleForHonorSociety(){
return super.eligibleForHonorSociety() && degree.equals("Masters");
}
// Overridden method to return a string representation of the graduate student
@Override
public String toString(){
return super.toString()+", Degree: "+ degree;
}
}
// Class representing the honor society with a static GPA threshold
class HonorSociety {
private static double gpaThreshold;
// Method to get the GPA threshold
public static double getGpaThreshold(){
return gpaThreshold;
}
// Method to set the GPA threshold and print it
public static void setGpaThreshold(double threshold){
gpaThreshold = threshold;
System.out.println("Honor Society GPA Threshold set to: "+ gpaThreshold);
}
}
// Main class for the project
public class CMSC215PROJ2NW {
public static void main(String[] args){
ArrayList students = new ArrayList<>();
try {
// Specify the path to the students.txt file
Scanner scanner = new Scanner(new File("students.txt"));
double totalGpa =0;
int count =0;
// Read student data from the file
while (scanner.hasNextLine()){
String line = scanner.nextLine();
String[] data = line.split("");
String name = data[0]+""+ data[1];
int creditHours = Integer.parseInt(data[2]);
int qualityPoints = Integer.parseInt(data[3]);
if (data.length ==5){
// Create and add an undergraduate student
String year = data[4];
students.add(new Undergraduate(name, creditHours, qualityPoints, year));
} else if (data.length ==4){
// Create and add a graduate student
String degree = data[3];
students.add(new Graduate(name, creditHours, qualityPoints, degree));
}
// Accumulate total GPA
totalGpa += students.get(count).gpa();
count++;
}
// Calculate average GPA and set the GPA threshold
if

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions