Answer to Question #59532 in Java | JSP | JSF for Nithya

Question #59532
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.
1
Expert's answer
2016-04-29T09:40:03-0400

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!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS