2016-10-26 6 views
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) { 

} 

}

+0

Ummm ...独自の「Date」クラスを実装しましたか? 'Date'オブジェクトは' Bill'で何を使っていますか?自分自身か 'java.util.Date'ですか? –

+0

はい、これは割り当て要件の一部です。 javaのDateクラスを使用することはできません –

+0

あなたの 'Bill'クラスで' java.util.Date'を引っ張っていないのですか? –

答えて

1

あなたのメソッド名にタイプミスがありますあなたの方法は、(大文字Fに注意してください)と呼ばれています:。。

public boolean isAFter (Date compareTo) {} 

あなたがそれを呼び出している間(小文字Fに注意してください):サイドノートで

if (after.isAfter(datePaid) == true) {} 

、あなたはここに新しいDateを作成している理由は全く分からない:

Date after = new Date(datePaid); 

ロジックが間違っているように見えますが、基本的には日付を自分と比較するだけです。おそらくdueDateと比較したいですか?

関連する問題