Question: create 5 classes ( all short programs). Policeman Patrolman Sergeant Lieutenant Driver Attach all programs(commented with output added as a comment at the bottom of
create 5 classes ( all short programs).
Policeman
Patrolman
Sergeant
Lieutenant
Driver
Attach all programs(commented with output added as a comment at the bottom of the driver). .
1.You are to begin with an abstract class called Policeman that might describe some of the policeman on a police force.
The instance variables are
String firstName
String lastName
int yearsOf Service
Write two constructors(no argument and fully qualified). Setters and getters for each Variable.
Write a toString that returns
firstName lastName
years of service = yearsOfService
Have two abstract methods
public abstract double earnings(); public abstract int benefitLevel();
2 There will be three classes, Patrolman(extends Policeman), Sergeant which extends Patrolman, and Lieutenant which extends Sergeant..
The two abstract methods, earnings() and benefitLevel(), will be defined in each of the classes.
The benefitLevel() method gives a measure of the benefits for each rank. It will start at 1 for a Patrolman, go up by 2 for a Sergeant, and go up another 3 steps for a Lieutenant.Use the super command
The start of the class Patrolman is:
public class Patrolman extends Policeman { static double basePatrolPay = 3600; public Patrolman(String first, String last, int y) { super(first,last,y); }
Implement the earnings and benefitLevel in each class.
The method earnings will return a double equal to the net take home pay of a patrolman is 85% of the base monthly pay(defined as a static variable above) + 6% of the (square root of the basePatrolPay) times the (number of years of service). To find square root use Math.sqrt(basePatrolPay)
The benefitLevel method will return a 1.
Then you have to implement a toString here(use a call to super.toString for the name and pay). See bottom of lab for sample output.
To get the actual class begin your toString with this.getClass().getSimpleName() which will return the class. This is important because sometimes Patrolmans toString will be used on a Patrolman and others times on a Sergeant or Lieutenant.
To get the pay to only have two decimal places use a line similar to this:
str=str+String.format("%.2f", this.earnings());
3. The start of the class Sergeant is public class Sergeant extends Patrolman { static double baseSgtPay = 4700; public Sergeant(String first, String last,int y) { super(first, last, y); }
Do the same as above using this data:
The base pay of a sergeant is $4700 a month. The net take home pay of a sergeant is 82% of the base pay + 1.2 times (the square root of the baseSgtPay) times the (number of years of service). His benefitLevel is two units higher than a patrolman's, and should be implemented by a "super" call.(super.benefitLevel() +2)
THERE IS NO NEED FOR A toString . (The method they inherit from Patrolman will work fine).
4. The start of the class Lieutenant is
public class Lieutenant extends Sergeant {
static double baseLieutenantPay = 5900; public Lieutenant(String first, String last,int y) { super(first, last, y); } The net take home pay of a lieutenant is 80% of the baseLieutenantPay + 1.3 times the (square root of the baseLieutenantPay) times the (number of years of service). His benefitLevel is 3 units higher than a sergeants and, again, should be implemented by a "super" call.
5. You are to test out your structure by writing an application called TestPolice. You should create an ArrayList of Policeman.
ArrayList
Create 2 Patrolman, 2 Sergeants and 1 Lieutenant. Put those officers in the arrayList
Patrolman p1 = new Patrolman( firstname, lastname, years);<------- obviously fill in
squad.add(pi1)
In your driver write a method called avgPay. It should have as a parameter an ArrayList of Policeman and should return a double.
public static double avgPay(ArrayList
Go through the ArrayList to get the avg earnings. Pass this back to the driver and print out.
Its output will be:
Patrolman: Road Runner
Years of Service =5
earnings=$3078.00
benefit level =1
Sergeant: Elmer Fudd
Years of Service=12
earnings=$4841.12
benefit level =3
Lieutenant : Donald Duck
years of service=15
earnings=$6217.80
benefit level=6
The average base pay for all Police is $____________
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
