In Java a (Refer to class diagram 7-1.) Declare the Account class and its instan
ID: 3722038 • Letter: I
Question
In Java a (Refer to class diagram 7-1.) Declare the Account class and its instance variables. Then, code a constructor that assigns default values to these variables. The default value you assign to the customer variable should prevent a NullPointerException (hint: do not assign a default value of null to the customer variable). Write this code as concisely as possible.
in your answers plaease lable answer for a answer for b ect ect
Account uber: int -custarer: Custaner pe: String balance: double setNuber (int) tgetNurberO: int +setCustaner (custaner) tgetCustaner (int): Custamer +set ype(String) getType) String set Ballance(doublle) get Balance): doble tget FonattedBalance String getCusta): String creditAocount (doible)Explanation / Answer
//The class
// answer for a -- assigning default values to instance variables..
Public Account(){
this.number = 1230;
this.customer = new Customer () ;
this.type = "savings"
this.balance = 100;
}
// Answer for b -- parameterised constructor
Public Account (int number, Customer customer, String type, double balance){
this.number = number ;
this.customer =customer ;
this.type = type ;
this.balance = balance ;
}
// answer for c
String getType (){
return type;
}
// answer for d
void creditAccount(double amount){
this.balance = balance + amount ;
}
void debitAccount(double amount)
this.balance = balance - amount ;
}
// answer for e
String formattedBalance = account.getFormattedBalance();
// constructor name should be same as the class name
// a -- defualt constructor b-- parameterised constructor
// both can be defined inside a single class
// 'this' refering the instance variable
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.