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

You\'re working a software engineering team that has been contracted to reprogra

ID: 3728189 • Letter: Y

Question

You're working a software engineering team that has been contracted to reprogram a database management system. Your team has decided to use Object Oriented Programming to represent the entities that exist within the database. Your colleague has written the abstract class Academic and the enum Title (both provided) as a starting point for this.

Abstract classes are similar to interfaces in that they contain unimplemented methods that must then be implemented by all subclasses. Unlike interfaces, however, abstract classes may also contain already implemented methods and fields. Methods that are not implemented are denoted by the abstract modifier. Abstract classes are useful if you want to specify a contract (like an interface), but also implement some general behaviour at the superclass level (because such behaviour is common to all subclasses anyway). Here, your colleague has decided that getName(), getID(), and getTitle() are methods that all subclasses would use, and so he has already implemented them. However, getWeeklyPay() and toString() are more complex and the details of such behaviour are only known at the subclass level (as discussed below).

While utilizing the provided Title enum, you task is to create two subclasses of Academic:

Student(String name, int id, Title title, double stipend)

Staff(String name, int id, Title title)

Because these are subclasses, they can call their superclass's constructor via the super keyword. Super construction should be used where possible to reduce code redundancy. This is because subclasses "extend" superclasses, and therefore have access to all the fields and methods of their superclass. After super is called, you may write additional code within the subclass constructor to express behaviour that is specific to the subclass.

Notice how, when you create these subclasses, Eclipse will automatically populate them with the necessary methods getWeeklyPay() and toString() as these methods are required by the Academic contract. You do not need to create any more methods (public or private) to complete this exercise, you should take advantage of the already implemented methods in Academic when required.

toString()

toString() should return a string representation of the object based on its class, id, and title; formatted as:

[class] [id] (studies a) / (works as a) [title]

For example:

To get the [title] component necessary for the string, you can simply use this.getTitle().toString();

Notice how we can use this.getTitle() without needing to write a getTitle() method in the current class, because it has already been implemented in the superclass Academic! This requires that you have implemented the constructor correctly using the super keyword (ask your t*tor for guidance with this if you're not sure!).

You should also inspect how the toString() method in Title works. It is very similar to PizzaType in oop.PizzaModified. Each of the enum values (e.g. BACHELOR_STUDENT) call the constructor Title(String text) which then assigns an internal field that can be retrieved with toString().

getWeeklyPay()

getWeeklyPay() is calculated based on the following information:

Students get paid a fixed weekly salary known as a stipend (see the Student constructor).

Lecturers get paid an annual salary of $80,000.

T*tors get paid an hourly rate of $40.

Because t*tors are paid hourly, you must implement an additional method public void setHours(int hours) in the Staff subclass that will allow administrators to set weekly hours for t*tors.

You are encouraged to ask your t*tor for comments on your code quality. There is often a better way to express behaviour than when you first get something to work (this is called refactoring).

Finally, upload and submit your 4 classes:

Academic
Staff
Student
Title

BELOW ARE THE ORIGINAL FILES:

package oop.University;

public class Staff extends Academic {

Staff(String name, int id, Title title) {

}

@Override

public double getWeeklyPay() {

// TODO Auto-generated method stub

return 0;

}

@Override

public String toString() {

return this.getTitle().toString();

}

}

package oop.University;

public enum Title {

BACHELOR_STUDENT("Bachelor degree."),

MASTERS_STUDENT("Masters degree."),

PHD_STUDENT("PhD."),

T*TOR("t*tor."),

LECTURER("lecturer.");

private final String text;

Title(String text) {

this.text = text;

}

public String toString() {

return text;

}

}

package oop.University;

public abstract class Academic {

private String name;

private int id;

private Title title;

public Academic(String name, int id, Title title) {

this.name = name;

this.id = id;

this.title = title;

}

public String getName() {

return name;

}

public int getID() {

return id;

}

public Title getTitle() {

return title;

}

public abstract double getWeeklyPay();

public abstract String toString();

}

package oop.University;

public class Student extends Academic {

Student(String name, int id, Title title, double stipend) {

}

@Override

public double getWeeklyPay() {

// TODO Auto-generated method stub

return 0;

}

@Override

public String toString() {

return this.getTitle().toString();

}

}

Cheers

Explanation / Answer

Hello, I have a solution for you. Implemented everything as per the requirements.

// Staff.java

package oop.University;

public class Staff extends Academic {

                //constants for storing important units

                private static final double LECTURER_ANNUAL_SALARY = 80000.0;

                private static final double WEEKS_IN_YEAR = 52.14;

                private static final double T_TOR_HOURLY_RATE = 40.0;

                //hours attribute for the T_tor

                private int hours;

                Staff(String name, int id, Title title) {

                                super(name, id, title); //passing data to super class

                }

                @Override

                public double getWeeklyPay() {

                                /**

                                * calculating weekly pay based on Title

                                */

                                if (getTitle() == Title.LECTURER) {

                                                /**

                                                * lecturer has fixed annual salary, so dividing by number of weeks

                                                * to get the weekly salary

                                                */

                                                return LECTURER_ANNUAL_SALARY / WEEKS_IN_YEAR;

                                } else if (getTitle() == Title.T_TOR) {

                                                /**

                                                * T_tor's weekly salary= hourly rate * number of hours worked

                                                */

                                                return T_TOR_HOURLY_RATE * hours;

                                }

                                return 0;

                }

                /**

                * will set the number of hours worked, (T_tor)

                */

                public void setHours(int hours) {

                                this.hours = hours;

                }

                @Override

                public String toString() {

                                /**

                                * returning a string in proper format

                                */

                                return "Staff " + getID() + " works as a " + getTitle();

                }

}

// Title.java

package oop.University;

public enum Title {

                BACHELOR_STUDENT("Bachelor degree."),

                MASTERS_STUDENT("Masters degree."),

                PHD_STUDENT("PhD."),

                T_TOR("T_tor."),

                LECTURER("lecturer.");

                private final String text;

                Title(String text) {

                                this.text = text;

                }

                public String toString() {

                                return text;

                }

}

// Academic.java

package oop.University;

public abstract class Academic {

                private String name;

                private int id;

                private Title title;

                public Academic(String name, int id, Title title) {

                                this.name = name;

                                this.id = id;

                                this.title = title;

                }

                public String getName() {

                                return name;

                }

                public int getID() {

                                return id;

                }

                public Title getTitle() {

                                return title;

                }

                public abstract double getWeeklyPay();

                public abstract String toString();

}

// Student.java

package oop.University;

public class Student extends Academic {

                private double stipend;//student's stipend rate

                Student(String name, int id, Title title, double stipend) {

                                super(name, id, title);//passing data to super class

                                this.stipend = stipend;

                }

                @Override

                public double getWeeklyPay() {

                                /**

                                * returning the stipend as weekly pay

                                */

                                return stipend;

                }

                @Override

                public String toString() {

                                /**

                                * returning a string in proper format

                                */

                                return "Student "+getID()+" studies a "+getTitle();

                }

}

// Test.java

package oop.University;

public class Test {

                public static void main(String[] args) {

                                /**

                                * Creating a few students and staffs

                                */

                                Student student4 = new Student("Bob", 4, Title.BACHELOR_STUDENT, 100);

                                Student student16 = new Student("Alice", 16, Title.MASTERS_STUDENT, 120);

                                Staff staff32 = new Staff("Chris", 32, Title.T_TOR);

                                Staff staff64 = new Staff("Dave", 32, Title.LECTURER);

                                /**

                                * Displaying details, toString() method will be invoked automatically

                                */

                                System.out.println(student4);

                                System.out.println(student16);

                                System.out.println(staff32);

                                System.out.println(staff64);

                                /**

                                * Displaying weekly pay

                                */

                                System.out.println(student4.getName() + "'s weekly pay: $"

                                                                + student4.getWeeklyPay());

                                System.out.println(student16.getName() + "'s weekly pay: $"

                                                                + student16.getWeeklyPay());

                                staff32.setHours(5); // setting 5 hours worked as staff32 is a T_tor

                                System.out.println(staff32.getName() + "'s weekly pay: $"

                                                                + staff32.getWeeklyPay());

                                System.out.println(staff64.getName() + "'s weekly pay: $"

                                                                + staff64.getWeeklyPay());

                }

}

/*OUTPUT*/

Student 4 studies a Bachelor degree.

Student 16 studies a Masters degree.

Staff 32 works as a T_tor.

Staff 32 works as a lecturer.

Bob's weekly pay: $100.0

Alice's weekly pay: $120.0

Chris's weekly pay: $200.0

Dave's weekly pay: $1534.3306482546989

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