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

The following is being done in Blue J and will need to incoperate inheritance. I

ID: 3553921 • Letter: T

Question

The following is being done in Blue J and will need to incoperate inheritance.


I need to Create 4 Classes (Student, Graduate, Undergraduate and Course)


Student class

Fields: studentid, fullname, credits and gpa.

Methods: getName, getCredits, setStudentId, getStudentId, addcredit, getGPA.


Undergraduate Class:

Fields: advisorname and major.

Methods: setAdvisorName, get AdvisorName and getMajor


Graduate Class:

Fields: previousDegrees, thesisTopic.

Methods: printpreviousdegrees, get thesistopic, setthesistopic


Course Class:

Fields: coursename, listofstudents, maxenrollment

Methods: enrollstudent, getenrollment, setcoursename, printlistofstudents


Take the following notes into consideration when creating the classes


Student Class


Explanation / Answer

Well Finally I have Coded and kept only 4 Classes with the same output:


//Course Class

import java.util.ArrayList;

import java.util.Scanner;


public class Course {

static String coursename;

static ArrayList listofstudents = new ArrayList();

static int maxenrollment;

Course(String name,int enrollCount)

{

maxenrollment=enrollCount;

coursename=name;

}

void enrollstudent(Course course1)

{

do{

//Creating New Course with name and maximum seats

System.out.println("Registering a Student:");

Scanner studentInput=new Scanner(System.in);

System.out.println("Enter Students Name:");

String name=studentInput.nextLine();

System.out.println("Students Id:");

String id=studentInput.nextLine();

Student s=new Student(name,id);

course1.listofstudents.add(name);

course1.printlistofstudents();

System.out.println(" Printing Student Details :");

System.out.println("Name: ID: GPA: Credit: ");

System.out.println(""+s.getName()+" "+s.getID()+" "+s.getGPA()+" "+s.getCredits()+" ");

System.out.println("Please select the task you need to perform from below options: ");

System.out.println("1.Register as Graduate:");

System.out.println("2.Register as UnderGraduate:");

Scanner task=new Scanner(System.in);

switch(task.nextInt())

{

case 1:

Graduate grad=new Graduate();

Scanner gradInput=new Scanner(System.in);

System.out.println("Enter Thesis Topic");

grad.setthesistopic(gradInput.nextLine());

grad.setpreviousdegrees();

System.out.println("Credit:");

s.addcredit(gradInput.nextInt());

System.out.println(" Printing Student Details :");

System.out.println("Name: ID: GPA: Credit: Thesis Topic:");

System.out.println(""+s.getName()+" "+s.getID()+" "+s.getGPA()+" "+s.getCredits()+" "+grad.getthesistopic());

grad.printpreviousdegrees();

break;

case 2:

Scanner ugInput=new Scanner(System.in);

System.out.println("Enter Major Subject");

Undergraduate ug=new Undergraduate(ugInput.nextLine());

System.out.println("Advisor Name:");

ug.setAdvisorName(ugInput.nextLine());

System.out.println("Credit:");

s.addcredit(ugInput.nextInt());

System.out.println(" Printing Student Details :");

System.out.println("Name: ID: GPA: Credit: Advisor: Major:");

System.out.println(""+s.getName()+" "+s.getID()+" "+s.getGPA()+" "+s.getCredits()+" "+ug.getAdvisorName()+" "+ug.getMajor());

break;

default:

System.out.println("Invalid option.Please try again later.");

break;

}

System.out.println(" Do you want to register another Student? Press : 1 for YES 2 for NO");

Scanner in = new Scanner(System.in);

int choice=in.nextInt();

if(choice==2)

{

System.out.println("Thank you.");

}

if(listofstudents.size()==maxenrollment)

{

System.out.println("Seats are full.Cannot add more students.Thank you");

break;

}

}while(listofstudents.size()<maxenrollment);

}

int getenrollment()

{

return listofstudents.size();

}

static void setcoursename(String course)

{

coursename=course;

}

static String gettcoursename()

{

return coursename;

}

void printlistofstudents()

{

System.out.println("List of students enrolled for "+coursename+" : ");

for(int i =0;i<listofstudents.size();i++)

{

System.out.println(listofstudents.get(i));

}

}

public static void main(String[]args)

{

Scanner in = new Scanner(System.in);

System.out.println("Welcome. Please enter the course details: 1.Course Name :");

String coursename=in.nextLine();

System.out.println("2.Maximum Seats:");

int maxSeats=Integer.parseInt(in.nextLine());

Course course1=new Course(coursename,maxSeats);

course1.enrollstudent(course1);

}

}


//Class UnderGraduate



public class Undergraduate {

String advisorname;

String major;

Undergraduate(String majorSubject)

{

major=majorSubject;

}

String getAdvisorName()

{

return advisorname;

}

void setAdvisorName(String name)

{

advisorname=name;

}

String getMajor()

{

return major;

}

}