Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(JAVA QUESTION) create 5 classes ( all short programs) Policeman Patrolman Sergeant Lieutenant Driver 1.You are to begin with an abstract class called Policeman that

(JAVA QUESTION)

create 5 classes ( all short programs)

Policeman

Patrolman

Sergeant

Lieutenant

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).

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 squad = new ArrayList();

Create 2 Patrolman, 2 Sergeants and 1 Lieutenant. Put those officers in the array

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 array of Policeman and should return a double.

public static double avgPay(ArrayList p)

Go through the array 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.21

benefit level =3

Lieutenant : Donald Duck

years of service=15

earnings=$6217.82

benefit level=6

The average base pay for all Police is $

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Advances In Databases And Information Systems 22nd European Conference Adbis 2018 Budapest Hungary September 2 5 2018 Proceedings Lncs 11019

Authors: Andras Benczur ,Bernhard Thalheim ,Tomas Horvath

1st Edition

3319983970, 978-3319983974

More Books

Students also viewed these Databases questions

Question

15. What is TCO?

Answered: 1 week ago