1- Create class called Account that has id(int), name (String), balance (double).
2- Add parametrized constructor, setter, getter methods. Validate that balance is always positive.
3- Add method toString that returns account information as a string.
public class Account {
private int id;
private String name;
private double balance;
public Account(int id, String name, double balance) {
setId(id);
setName(name);
setBalance(balance);
}
int getId() {
return id;
}
void setId(int id) {
this.id = id;
}
String getName() {
return name;
}
void setName(String name) {
this.name = name;
}
double getBalance() {
return balance;
}
void setBalance(double balance) {
if(balance > 0)
this.balance = balance;
else balance = 1;
}
@Override
public String toString() {
return "Account. Id: " + getId() + ", name: " + getName() + ", balance: " + getBalance();
}
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
JavaJSPJSF