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

a) PART I: Create an abstract Java class named “ Student ” in a package named “

ID: 3912651 • Letter: A

Question

a)

PART I:

Create an abstract Java class named “Student” in a package named “STUDENTS”. This class has 4 attributes:

(1)student ID: protected, an integer of 10 digits

(2)student name: protected

(3)student group code: protected, an integer (1 for undergraduates, 2 for graduate students)

(4)student major: protected (e.g.: Business, Computer Sciences, Engineering)

Class Student declaration provides a default constructor, get-methods and set-methods for the attributes, a public abstract method (displayStudentData()).

b)

Create a Java class named “Undergraduate” in the same package, i.e. STUDENTS, that extends the above class Student. Class Undergraduate has its own one attribute:

undergradLevel: private,a String, to indicate the student level: freshman, sophomore, junior, or senior

Class Undergraduate declaration provides:

a default constructor,

another constructor that accepts 4 parameters: student ID, student full name, major, and undergraduate level

get-method and set-method of its own attribute

a method to return the priority code to register classes (return 1 if senior, 2 if junior, and so on)

a method (displayStudentData()) that implements the abstract method of the same name of the super class and prints out information of a student in a format like the following sample (all in one line):

Student ID: 1234567890; John Smith; senior undergraduate; Business

c )

Create a Java class named “Graduate” in the same package, i.e. STUDENTS, that extends the above abstract class Student. This class has one attribute:

isTaRa: private, a boolean, to indicate whether the student is a TA (Teaching Assistant) or RA (Research Assistant)

Class Graduate declaration provides:

a default constructor,

another constructor that accepts 4 parameters: student ID, student full name, major, and a boolean parameter to indicate whether the student is a TA or a RA.

get-method and set-method of its own attribute

a method (displayStudentData()) that implements the abstract method of the same name of the superclass Student and prints out information of the student in a format like the following sample (all in one line):

            If a graduate student is not a TA/RA:

            Student ID: 1234567890; John Smith; graduate; Information Technology and Management

            If a graduate student is a TA/RA:

            Student ID: 1234567890; John Smith; graduate; TA; Information Technology and Management


d)

Write a Java program that can get data of a studentand print outthe data. The student can be either an undergraduate or a graduate. First, the program reads an input of a numeric code that identifies which course work level of student that the user wants to work with.

The values of course work level code are:

1 for undergraduate

2 for graduate

The input of the numeric code must be verifiedto be sure that it is valid, i.e. can only be either 1 or 2.

For the undergraduate, then the user enters the following pieces of student data from the console:

Student ID

Student full name (first name first)

Student's major

Student's undergraduate level

For the graduate, the user enters the following pieces of student data from the console:

Student ID

Student full name (first name first)

Student's major

Student's status of being aTA/RA: enter 1 for YES; enter 0 for NO

For the input verification:

The input of student ID should be verified that it is not negative or 0.

The input of the full name and major should be verified that they are not empty string.

The input of the undergraduate level should be verified that it can only be "freshman", "sophomore", "junior", or "senior".

The input of the status of being aTA/RA should be verified that it can only be 0 or 1.

The Java program is another Java class named “StudentDisplayer” in the same package, i.e. STUDENTS. To provide a solution to the problem, it is expected thatinheritance and polymorphism are used in the coding.

IMPORTANT NOTES:

The following Notepad files are expected to be submitted as the solution to Problem 1:

Student.txt

Undergraduate.txt

Graduate.txt

StudentDisplayer.txt

Explanation / Answer

STUDENT.TXT public abstract class Student { protected int s_id; protected String s_name; protected int g_code; protected String s_major; public Student(String name, String address, int number) { System.out.println("Constructing an Employee"); this.s_id = s_id; this.s_name = s_name; this.g_code = g_code; this.s_major = s_major; } public abstract displayStudentData(); } public String toString() { return s_id+” “+s_name + " " + g_code + " " + s_major; } public int getId() { return id; } public String getName() { return name; } public int getId() { return id; } public String getMajor() { return major; } public void setAddress(int newid) { id = newid; } public void setName(String newName) { name = newName; } public void setgid(String newgid) { gid = newgid; } public void setMajor(String newmajor) { major = newMajor; } } UNDERGRAUATE.TXT public class Undergraduate extends Student { private String undergradLevel; public Undergraduate(int id,String name,int gid, String major, String undergradLevel) { super(id,name,gid); setUndergradLevel(UndergradLevel); } public String getUndergradLevel () { return UndergradLevel; } public String setUndergradLevel (String newUndergradLevel) { { UndergradLevel = newUndergradLevel; } public double prioritycode() { System.out.println("Computing prioritycode for " + getName()); If(UndergradLevel==”Freshman”); { System.out.println(“3”); } If(UndergradLevel==”Sophomore”); { System.out.println(“4”); } If(UndergradLevel==”Junior”); { System.out.println(“2”); } If(UndergradLevel==”Senior”); { System.out.println(“1”); } public String displayStudentData(); System.out.println("s_id " + getid()+"s_name " + getName()+"g_id " + getgid()+"s_major " + getmajor()); } GRADUATE.TXT public class Graduate extends Student { private Boolean isTaRa; public Graduate(int id,String name,int gid, String major, Boolean isTaRa) { super(id,name,gid); setisTaRa (isTaRa); } public String getisTaRa () { return isTaRa; } public String setisTa (String newisTa) { { isTaRa = new isTaRa; } public double chkTaRa() { System.out.println("Computing TaRa " + getName()); If(isTaRa ==”Ra”); { isTaRa= System.out.println(“0”); } If(isTaRa ==”Ta”); { isTaRa=System.out.println(“1”); } } public String displayStudentData(); { While(isTaRa==1) { System.out.println("s_id " + getid()+"s_name " + getName()+"graduate " + getgid()+"s_major " + getmajor()+isTaRa); } System.out.println("s_id " + getid()+"s_name " + getName()+"graduate " + getgid()+"s_major " + getmajor()); }} STUDENT DISPLAYER.TXT public class StudentDisplayer { public static void main(String [] args) { public int ip; System.out.println(“ Enter 1for Undergraduate or 2 for Graduate”); ip= scanner.nextLine(); if(ip=1) { { System.out.println(“ Enter StudentId”); id= scanner.nextLine(); System.out.println(“ Enter Name”); Name=scanner.nextLine(); System.out.println(“ Enter Student major”); Major=scanner.nextLine(); System.out.println(“ Enter Undergraduate Level”); undergraduateLevel=scanner.nextLine(); Undergraduate ug=new Undergraduate(id,Name,major,undergraduateLevel”); } Else if(ip==2) { System.out.println(“ Enter StudentId”); id= scanner.nextLine(); System.out.println(“ Enter Name”); Name=scanner.nextLine(); System.out.println(“ Enter is Ta enter 1 or 0”); isTaRa=scanner.nextLine(); Graduate gr=new Undergraduate(id,Name,isTaRa”); } else { System.out.println(“ wrong input :press 0 or 1 ”); } } } }