You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
58 lines
1.8 KiB
58 lines
1.8 KiB
import java.text.DateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.time.Duration;
|
|
import java.time.LocalDate;
|
|
import java.time.LocalDateTime;
|
|
import java.time.format.DateTimeFormatter;
|
|
import java.time.temporal.ChronoUnit;
|
|
import static java.lang.Math.abs;
|
|
|
|
public class PackageInfo implements Comparable<PackageInfo>{
|
|
private String name;
|
|
private String note;
|
|
private double price;
|
|
private double weight;
|
|
private boolean delivered;
|
|
private LocalDateTime expectedDate;
|
|
|
|
public PackageInfo(String name, String note, double price, double weight, boolean delivered, LocalDateTime expectedDate) {
|
|
this.name =name;
|
|
this.note = note;
|
|
this.price = price;
|
|
this.weight =weight;
|
|
this.delivered =delivered;
|
|
this.expectedDate = expectedDate;
|
|
}
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
public boolean getDelivered() {
|
|
return delivered;
|
|
}
|
|
|
|
public LocalDateTime getExpectedDate() {
|
|
return expectedDate;
|
|
}
|
|
|
|
public void setDelivered(boolean delivered) {
|
|
this.delivered = delivered;
|
|
}
|
|
|
|
@Override
|
|
public int compareTo(PackageInfo p){
|
|
return this.expectedDate.compareTo(p.getExpectedDate());
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
DateTimeFormatter format = DateTimeFormatter.ofPattern("yyy-MM-dd HH:mm");
|
|
LocalDateTime today = LocalDateTime.now();
|
|
today.format(format);
|
|
long diff = ChronoUnit.DAYS.between(today, expectedDate);
|
|
String isDelivered = delivered ? "yes" : "no";
|
|
return "Name: " + name + "\n" + "Notes: " + note + "\n" + "Price: " + price + "\n" + "Weight: " + weight + "\n" + "Expected Delivery Date: " + expectedDate.toString() + "\n" + "Delivered? " + isDelivered + "\n" + ((diff > 0 && !delivered) ? diff + " days remaining" : abs(diff) + " days overdue");
|
|
}
|
|
}
|