Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have written three java classes, and now need to sort the input array by the name stored in each object. This is a case-sensitive

I have written three java classes, and now need to sort the input array by the name stored in each object. This is a case-sensitive lexicographic order sort. This is the assignment http://cs.sou.edu/~nordquip/cs257/labs/l6/doc/index.html and this is what I have written previously. My program runs fine, I just cannot figure out how to sort the array, and I don't understand how implementing comparable in manager or worker helps me in the new class i am creating.

public class Manager extends Worker {

// do not produce anything

private int numberSubordinates;

private boolean wellLiked;

public Manager(String name, int numberSubordinates, boolean wellLiked) {

super(name);

this.numberSubordinates = numberSubordinates;

this.wellLiked = wellLiked;

}

public boolean liked(boolean liked) {

if (liked = true) {

wellLiked = true;

return wellLiked;

}

else {

wellLiked = false;

return wellLiked;

}

}

public long work(long units) {

if (units <= 0) {

getUnitsWorked();

return getUnitsWorked();

}

else {

setUnitsWorked(Math.round(units * numberSubordinates * .75) + getUnitsWorked());

return getUnitsWorked();

}

}

public String toString() {

return super.toString() + " , " + numberSubordinates + " ," + wellLiked;

}

public static void main(String[] args) {

Manager m1 = new Manager("BM", 2, false);

m1.work(3);

}

}

public class Worker {

private long unitsWorked;

private String name;

// store name and number of units earned

public Worker(String name) {

this.name = name;

}

public String getName() {

this.name = name;

return name;

}

public long work(long units) {

if (units <= 0) {

return unitsWorked;

}

else {

unitsWorked = units + unitsWorked;

return unitsWorked;

}

}

public String toString() {

return super.toString() + "," + unitsWorked + "," + name;

}

public double pay(double multiplier) {

multiplier = unitsWorked * multiplier;

unitsWorked = 0;

return multiplier;

}

public static void main(String[] args) {

Worker w = new Worker("Jm");

w.work(3);

}

public long getUnitsWorked() {

return unitsWorked;

}

public void setUnitsWorked(long unitsWorked) {

this.unitsWorked = unitsWorked;

}

}

public class Producer extends Worker {

private int productionTarget;

public Producer(String name, int productionTarget) {

super(name);

this.productionTarget = productionTarget;

}

// do not manage anything

public int getProductionTarget() {

this.productionTarget = productionTarget;;

return productionTarget;

}

public String toString() {

return super.toString() + " , " + productionTarget;

}

public long work(long units) {

if (units <= 0) {

getUnitsWorked();

return getUnitsWorked();

}

else {

setUnitsWorked(Math.round(productionTarget * .5 * units) + getUnitsWorked());

return getUnitsWorked();

}

}

}

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

Online Market Research Cost Effective Searching Of The Internet And Online Databases

Authors: John F. Lescher

1st Edition

0201489295, 978-0201489293

More Books

Students also viewed these Databases questions

Question

Question What are the requirements for a safe harbor 401(k) plan?30

Answered: 1 week ago