0
@Override
public org.joda.money.Money computeCharge(org.joda.time.DateTime from,
                                      org.joda.time.DateTime to){

}

Description copied from interface: Parkable

Compute the cost of parking in this lot between these times. Specified by:computeCharge in interface Parkable Parameters:from - The time the Vehicle is admitted. to - The time the vehicle is released. Returns:The cost of parking here.

For example, we charge 8 dollars per hour.

private void updateCharge() {
    jtc.setText(jcb.getSelectedItem() + " for " + jtf.getText());

    DateTime from = new DateTime(arriveTime.getDate());
    DateTime to = new DateTime(departTime.getDate());
    Period p = new Period(from, to);

    Parkable pk = (Parkable) jcb.getSelectedItem();
    pk.computeCharge(from, to);
    jtc.setText(pk.computeCharge(from, to).toString());
    System.out.println(jcb.getSelectedItem() + " for " + jtf.getText()
            + " costs " + pk.computeCharge(from, to));
}

The second coding is my calculator panel. So, the interface instance pk implements computeCharge method. Then, System.out.println(... "costs" + pk.computeCharge(from,to)). Please help me.

Grace Li
  • 9
  • 1

1 Answers1

0

I wrote something like this;

public static void main(String[] args) {
    DateTime to = new DateTime().minusHours(3).minusSeconds(30);
    DateTime from = new DateTime();
    System.out.println("Total Amount is = " + computeCharge(from, to));
}

public static Money computeCharge(DateTime from, DateTime to) {
    int hourlyAmount = 8;
    Money result = Money.of(CurrencyUnit.USD, hourlyAmount);
    Minutes minutes = Minutes.minutesBetween(to, from);
    return result.multipliedBy(minutes.getMinutes() / 60);
}

You can modify this for your case.

And the output is;

Total Amount is = USD 24.00
Semih Eker
  • 2,389
  • 1
  • 20
  • 29