Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!