Question
Lab 02 Inherit the Wind 1. Person: Project: Person Files: Person.java Fields: String firstName String lastName String ID // should never change String title //
Lab 02 Inherit the Wind
1. Person: Project: Person Files: Person.java Fields: String firstName String lastName String ID // should never change String title // a prefix: Mr. Mrs. Ms, Prof. Dr. Hon. Etc. int YOB // Year of birth Additional methods: public String fullName() // returns firstName, space, lastName public String formalName() // returns title, space, fullName public int getAge() // uses YOB to calculate age for the current year
Copyright 2021-present, University of Cincinnati, Ohio. All rights reserved. // Add this new overloaded method of getAge to the Person class public int getAge(int year) // uses YOB to calculate age for a specified year Revise your UML Class diagram for Person from the previous lab to reflect the new method. (You will need it to create a UML Class Diagram below. 2. Worker Class (inherits from Person): Files: Worker.java WorkerTest.java Fields: double hourlyPayRate Methods: double calculateWeeklyPay(double hoursWorked) String displayWeeklyPay(double hoursWorked) The constructor for Worker should use super() to call the constructor for Person and then go on to set the rest of the fields. calculateWeeklyPay should return the pay total. Hours under 40 are at the HourlyRate, hours above 40 are at time and a half (1.5) displayWeeklyPay should indicate the number of hours of regular pay (40) and the total and the number of hours of overtime pay and the total as well as the total combined pay. 3. SalaryWorker (inherits from Worker) Files: SalaryWorker.java SalaryWorkerTest.java Fields: double annualSalary Methods: The constructor for SalaryWorker should use super() to call the constructor for Worker double calculateWeeklyPay(double hoursWorked) Override calculateWeeklyPay and displayWeeklyPay calculateWeeklyPay returns the pay total. Note that the parameter hoursWorked is not used here but is retained for polymorphism. Take the annualSalary and divide by 52 to get the weekly pay. displayWeeklyPay should indicate that the weekly pay is a fraction of the yearly salary.
Copyright 2021-present, University of Cincinnati, Ohio. All rights reserved. 4. Main Program: Create a new java main class within your same IntelliJ IDEA project InheritanceDemo 1. Create 3 workers and 3 salaryWorker instances and add them to an ArrayList
FULL CODE ON INTELJI JAVA
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started