63 220
Assignments Done
99,3%
Successfully Done
In July 2018

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.
Expert's answer

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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions