jeudi 29 janvier 2015

Making a priority Class


Vote count:

0




I have 3 similar classes one with the highest priority, the medium priority and the lowest (bulk) priority. They should be compared with compareTo(Abstract Parcel), with higher priority = 1, same priority = 0 and lower priority = -1. Also we have to make a method TransportMode shipBy(), where items with high priority are shipped with PLANE, with medium priority with TRAIN and items with low priority with TRUCK. Now if I understand it right all classes are almost similar. So here is my example for the lowest priority.


It seems like I did have something wrong, but I don´t know what it is. For help I would be great full.


package parcel;


public abstract class BulkParcel extends AbstractParcel {



public BulkParcel() {
}

@Override
public int compareTo(AbstractParcel o) {
if (newitem = 1) {
return Priority.HIGH;
}
else {
if (newitem = 0) {
return Priority.MEDIUM;
}
}
else {
if (newitem = -1) {
return Priority.BULK;
}
}
}

@Override
public TransportMode shipBy() {
if (getPriority() = Priority.HIGH) {
return TransportMode.PLANE;
}
else {
if (getPriority() = Priority.MEDIUM) {
return TransportMode.TRAIN;
}
}
else {
if (getPriority() = Priority.BULK) {
return TransportMode.TRUCK;
}
}
}

/**
* Returns the priority of a parcel.
*
* @return the parcel's priority.
*/
@Override
Priority getPriority() {
return Priority.BULK;
}

/**
* Gives information about the parcel.
*
* @return some information about the parcel with Bulk parcel no. <id> with priority bulk.
*/
@Override
String getInfo() {
String info = "shipBy()" + "getpriority()";
return info;
}


}



asked 29 secs ago

Stef

10






Making a priority Class

Aucun commentaire:

Enregistrer un commentaire