Show Table of Contents
22.7. Banking Example: Class Cashflow
public class Cashflow {
private Date date;
private double amount;
public Cashflow() {
}
public Cashflow(Date date, double amount) {
this.date = date;
this.amount = amount;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public double getAmount() {
return amount;
}
public void setAmount(double amount) {
this.amount = amount;
}
public String toString() {
return "Cashflow[date=" + date + ",amount=" + amount + "]";
}
}- Class
Cashflowhas two simple attributes, a date and an amount. (Using the typedoublefor monetary units is generally bad practice because floating point numbers cannot represent most numbers accurately.) - There is an overloaded constructor to set the values and a method
toStringto print a cashflow.

Where did the comment section go?
Red Hat's documentation publication system recently went through an upgrade to enable speedier, more mobile-friendly content. We decided to re-evaluate our commenting platform to ensure that it meets your expectations and serves as an optimal feedback mechanism. During this redesign, we invite your input on providing feedback on Red Hat documentation via the discussion platform.