Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Introduce Student, UndergradStudent and GradStudent classes as defined in the di

ID: 3708304 • Letter: I

Question

Introduce Student, UndergradStudent and GradStudent classes as defined in the diagram above. Also define a StudentFactory class as explained below.

Student is an abstract class with abstract getGPA() method. UndergradStudent and GradStudent are final classes. Information about students is entered by the user using the following format:

G|Adam Smith|123-4567|CISC|Network Management

U|Chris Smith|987-6543|MATH|ENGL|3.98

The fields are separated by the | character. The first field is either a G representing a graduate student or a U representing an undergraduate student. Graduate student entries have name, id, major and research area fields, whereas the undergraduate entries have name, id, major, minor and gpa fields. The getGPA() method for the graduate students should always return 4.0.

Introduce the StudentFactory class with the main method and another static method of the form:

This function should take the string entered by the user representing the student info and parse it to extract the student’s information and create either a Graduate or Undergraduate Student objects based on the entry (G or U). The method should return the newly created Student object.

Define your main function in StudentFactory class. Your main function should invoke the createStudent() method for each user entry and store all the students into a local Student array. It should then loop over the array list and print out the information about each student on a separate line onto the console.

Explanation / Answer

Explanation: Below is the Java code for above problem with proper description provided within comments itself. Below code some sample output screenshots are attached. If you need any other help for this Comment me below. Thanks Java code : public abstract class Student { private String name; private String Id; private String major; public Student(String name, String id, String major) { super(); this.name = name; Id = id; this.major = major; } @Override public String toString() { return "Student Name = " + name + ", Id = " + Id + ", major = " + major + ", GPA = " + getGPA(); } public abstract double getGPA(); public String getName() { return name; } public void setName(String name) { this.name = name; } public String getId() { return Id; } public void setId(String id) { Id = id; } public String getMajor() { return major; } public void setMajor(String major) { this.major = major; } } public final class UndergradStudent extends Student { private String minor; private double gpa; @Override public double getGPA() { return this.gpa; } public UndergradStudent(String name, String id, String major, String minor, double gpa) { super(name, id, major); this.minor = minor; this.gpa = gpa; } public String getMinor() { return minor; } public void setMinor(String minor) { this.minor = minor; } public double getGpa() { return gpa; } public void setGpa(double gpa) { this.gpa = gpa; } } public final class GradStudent extends Student { private String researchArea; @Override public double getGPA() { return 4.0; } public GradStudent(String name, String id, String major, String researchArea) { super(name, id, major); this.researchArea = researchArea; } public String getResearchArea() { return researchArea; } public void setResearchArea(String researchArea) { this.researchArea = researchArea; } } import java.util.ArrayList; import java.util.Scanner; public class StudentFactory { public static Student createStudent(String studentInfo) { String arr[] = studentInfo.split(":"); if (arr[0].equals("G")) { Student student = new GradStudent(arr[1], arr[2], arr[3], arr[4]); return student; } else if (arr[0].equals("U")) { Student student = new UndergradStudent(arr[1], arr[2], arr[3], arr[4], Double.parseDouble(arr[5])); return student; } return null; } public static void main(String[] args) { Scanner sc = new Scanner(System.in); ArrayList arrayList = new ArrayList(); String input = sc.nextLine(); arrayList.add(createStudent(input)); input = sc.nextLine(); arrayList.add(createStudent(input)); for (Student student : arrayList) { System.out.println(student); } sc.close(); } }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote