2
私のBill
クラスの私のDate
クラスにboolean isAfter(Date compareTo)
を呼び出す方法を理解しようとしています。ここで2つの値を比較する異なるクラスからメソッドを呼び出す方法は?
私は私のsetPaid
方法で新しいDate
オブジェクトを作成する必要がありますか私は右ではありません持っているものを知っている方法のisAfter(日)からメソッドです - ?。。私は、「シンボルを見つけることができないというエラーメッセージが出続けます私Date
クラスは - 正常に動作し、全体Bill
クラス - ない
public boolean isAFter (Date compareTo) {
return compareTo(compareTo) > 0;
}
public int compareTo (Date x) {
if (year != x.year) return year - x.year;
if (month != x.month) return month - x.month;
return day - x.day;
}
public class Bill
{
private Money amount;
private Date dueDate;
private Date paidDate;
private String originator;
//paidDate set to null
public Bill (Money amount, Date dueDate, String originator) {
this.amount = amount;
this.dueDate = dueDate;
this.originator = originator;
paidDate = null;
}
public Bill (Bill toCopy) {
/*this.amount = toCopy.amount;
this.dueDate = toCopy.dueDate;
this.paidDate = toCopy.paidDate;
this.originator = toCopy.originator;*/
}
public Money getAmount() {
return amount;
}
public Date getDueDate() {
return dueDate;
}
public String getOriginator() {
return originator;
}
//returns true if bill is paid, else false
public boolean isPaid() {
if (paidDate != null) {
return true;
}
return false;
}
//if datePaid is after the dueDate, the call does not update anything and returns false.
//Else updates the paidDate and returns true
//If already paid, we will attempt to change the paid date.
public boolean setPaid (Date datePaid) {
Date after = new Date(datePaid);
if (after.isAfter(datePaid) == true) {
return false;
}
else {
paidDate = datePaid;
return true;
}
}
//Resets the due date – If the bill is already paid, this call fails and returns false.
//Else it resets the due date and returns true.
public boolean setDueDate (Date newDueDate) {
if (isPaid() == false) {
dueDate = newDueDate;
return true;
}
else {
return false;
}
}
//Change the amount owed.
//If already paid returns false and does not change the amount owed else changes
//the amount and returns true.
public boolean setAmount (Money amount) {
}
public void setOriginator() {
}
//Build a string that reports the amount, when due, to whom, if paid, and if paid
//the date paid
public String toString() {
return "Amount: " + amount + " Due date: " + dueDate + " To: " + "originator" + " Paid?" + isPaid() + "Paid date: " + paidDate;
}
//Equality is defined as each field having the same value.
public boolean equals (Object toCompare) {
}
}
Ummm ...独自の「Date」クラスを実装しましたか? 'Date'オブジェクトは' Bill'で何を使っていますか?自分自身か 'java.util.Date'ですか? –
はい、これは割り当て要件の一部です。 javaのDateクラスを使用することはできません –
あなたの 'Bill'クラスで' java.util.Date'を引っ張っていないのですか? –