Haviing trouble with my homework
(java)
1)Write the class CustomerAccount, which has fields/attributes called custID of type String, custName of type String and checkingBalance of type double and savingBalance of type double
2)Write the constructor for CustomerAccount class. The constructor takes parameters to initialize custID, custName, checkingBalance and savingBalance.
3)Write the mutator method for all attributes of the class CustomerAccount. then Write the toString method for class CustomerAccount.
I have created a project named CustomerAccount in NetBeans IDE.
package customeraccount;
public class CustomerAccount {
String custID;
String custName;
double checkingBalance;
double savingBalance;
//default constructor
public CustomerAccount() {
this.custID = "";
this.custName = "";
this.checkingBalance = 0;
this.savingBalance = 0;
}
//parameterized constructor
public CustomerAccount(String custID, String custName, double checkingBalance, double savingBalance) {
this.custID = custID;
this.custName = custName;
this.checkingBalance = checkingBalance;
this.savingBalance = savingBalance;
}
//mutator method for custID
public void setCustID(String custID) {
this.custID = custID;
}
//mutator method for custName
public void setCustName(String custName) {
this.custName = custName;
}
//mutator method for checkingBalance
public void setCheckingBalance(double checkingBalance) {
this.checkingBalance = checkingBalance;
}
//mutator method for savingBalance
public void setSavingBalance(double savingBalance) {
this.savingBalance = savingBalance;
}
//tostring method
@Override
public String toString() {
return "CustomerAccount{" + "custID=" + custID + ", custName=" + custName + ", checkingBalance=" + checkingBalance + ", savingBalance=" + savingBalance + '}';
}
//accessor method for custID
public String getCustID() {
return custID;
}
//accessor method for custName
public String getCustName() {
return custName;
}
//accessor method for checkingBalance
public double getCheckingBalance() {
return checkingBalance;
}
//accessor method for savingBalance
public double getSavingBalance() {
return savingBalance;
}
public static void main(String[] args) {
//reate object of CustomerAccount class
//invoke parameterized constructor and set value
CustomerAccount c = new CustomerAccount("A1","Henry",1000.0,500.3);
//invoke mutator of custName
c.setCustName("David");
//print the result returned by accessor of savingBalance
System.out.println("SavingBalance: "+ c.getSavingBalance());
//print the result returned by toString() method
System.out.println("" + c.toString());
}
}
OUTPUT:
Get Answers For Free
Most questions answered within 1 hours.