This homework will cover basic inheritance.
Georgia Tech is coming out with a new T-square called T-humans just for keeping track of the humans here at Tech. You will be responsible for implementing and organizing multiple classes in a coherent manner. You will need to familiarize yourself with super/subclasses and constructor chaining.
You will need to create and organize Person.java
, Student.java
, Undergrad.java
, Grad.java
, Professor.java
, and University.java
. Person should be at the top of the hierarchy with Professor and Student as direct subclasses. Student then has Undergrad and Grad as subclasses.
This class has the following instance variables:
private String name
: name of personprivate int age
: age of personprivate String homeTown
: hometown of personThis class has the following methods:
public String getName()
: returns namepublic int getAge()
: returns agepublic String getHometown()
: returns homeTownpublic String toString()
: returns a string with following format:
name
is age
years old from homeTown
name
, age
, and homeTown
.The constructors for this class should be able to accept one, two, or all three arguments (instance variable values).
name
): defaults age to 18 and homeTown to “Atlanta”name
and age
): defaults homeTown to “Atlanta”name
, age
, and homeTown
): no defaults needed for this one.NOTE: Use constructor chaining for this. Order matters!
Subclass of Person. This class has the following instance variables:
private double avgGPA
: average gpa of the studentprivate int gtID
: gtID of studentprivate String[] classes
: String array of classes that the student is currently takingThis class requires an explicit constructor that must take in and set avgGPA
, gtID
, and classes
along with any other instance data required by the superclass.
This class should have the following methods:
public double getAvgGPA()
: returns avgGPApublic String[] getClasses()
: returns an array of classespublic String toString()
: returns a string with the following format:public int getGTID()
: returns gtID
name
is age
years old from homeTown
with gtid gtID
name
, age
, homeTown
, and gtID
Subclass of Student. This class has the following instance variables:
private int sleepHours
: int representing the hours of sleep they getThis class requires an explicit constructor that must take in and set sleepHours
along with any other instance data required by the superclass.
This class has the following methods:
public int getSleepHours()
: returns the hours of sleep they getpublic String toString()
: returns a string with following format:
name
is age
years old from homeTown
with gtid gtID
is only sleeping sleepHours
hours per nightname
, age
, homeTown
, gtID
, and sleepHours
Subclass of Student. This class has the following instance variables:
private String thesisTitle
: title of defense thesisThis class requires an explicit constructor that must take in and set thesisTitle
along with any other instance data required by the superclass.
This class has the following methods:
public String getThesisTitle()
: returns defense thesis titlepublic String toString()
: returns a string with following format:
name
is age
years old from homeTown
with gtid gtID
name
, age
, homeTown
, gtID
, and thesisTitle
Subclass of Person. This class has the following instance variables:
private int classSize
: int that represent their class sizeprivate String[] classes
: String array of the classes that they teachThis class requires an explicit constructor that must take in and set classSize
and classes
along with any other instance data required by the superclass.
This class should have the following methods:
public String[] getClasses()
: returns an array of classespublic String toString()
: returns a string with following format:
name
has a class of classSize
studentsname
, age
, homeTown
, and classSize
This class has the following instance variables:
private String name
: the name of the universityprivate Student[] students
: stores an array of Studentsprivate Professor[] professors
: stores an array of ProfessorsThis class requires an explicit constructor that must take in and set name
as well as instantiate students
and professors
.
This class should have the following methods:
public void addStudent(Student student)
: checks that the student does not already exist in students
before adding student to the students
array. If the array is full it must be re-sized before adding the student.public void addProfessor(Professor professor)
: checks that the professor does not already exist in professors
before adding professor to its corresponding array. If the array is full it must be re-sized before adding the professor.public boolean removeStudent(Student student)
: returns true if it successfully finds and removes the student from students
, otherwise returns false. This method should make sure that there are no “null gaps” between the students and if there is a null, it is at the end of the array.public String toString()
: returns a String representation of all of the professors and students in the University along with its name
. The format of this is up to you, but make sure it’s legible.You should not import any libraries or packages that trivialize the assignment. This includes data structures other than arrays (so no List
, Map
, Set
, etc). If you are unsure of whether something is allowed, ask on Piazza. In general, if something does a large part of the assignment for you, it is probably not allowed. Important: java.util.Arrays
is not allowed. However, that is different from a Java array (e.g int[] nums = new int[10]
), which is necessary for this assignment.
We recommend you test your code by doing the following:
You will need to write Javadoc comments along with checkstyling your submission.
Every class should have a class level Javadoc that includes @author <GT Username>
and @version <version #>
.
Every method should have a Javadoc explaining what the method does and includes any of the following tags if applicable.
@param <parameter name> <brief description of parameter>
@returns <brief description of what is returned>
@throws <Exception> <brief explanation of when the given exception is thrown>
See the CS 1331 Style Guide section on Javadoc comments for examples.
You must run checkstyle on your submission. The checkstyle cap for this submission is 30 points. All hashcode() checkstyle will NOT be counted against you for this assignment.
A guide for setting up and running checkstyle can be found on this page on the course website. Make sure you click “Save” when downloading the jar file, and not “Run”. It is useful to copy the jar file to your homework directory or set up an alias for it. Run checkstyle for this assignment with java -jar checkstyle-6.2.2.jar -a *.java
. This will check for both checkstyle errors and javadoc errors.
When completing homeworks for CS1331 you may talk with other students about:
You may not discuss, show, or share by other means the specifics of your code, including screenshots, file sharing, or showing someone else the code on your computer, or use code shared by others.
Examples of approved/disapproved collaboration:
s 10:40 on Thursday... can I see your code? I won
t copy it directly I promise”Collaborating with others in a way that violates the approved means is a Georgia Tech Honor Code violation.
Export the hw3 folder to a .zip file and submit that on T-square. Make sure the zip file contains Grad.java
, Person.java
, Professor.java
, Student.java
, Undergrad.java
, and University.java
.
Practice safe submission! Verify that your HW files were truly submitted correctly, the upload was successful, and that your program runs with no syntax or runtime errors. It is solely your responsibility to turn in your homework and practice this safe submission safeguard.
This procedure helps guard against a few things.