Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public class PremiumAccount extends JavaAccount { public static double minimumBa

ID: 3848852 • Letter: P

Question

public class PremiumAccount extends JavaAccount {
public static double minimumBalanceRequired = 20;
public static double checkFee = 2;
private static String PIN = "XXXYYYZZZ";
private static int invalidPinCount = 0;
  
PremiumAccount(String customerName,long AccountNumber,double balance,double interestRate){
super( customerName, AccountNumber, balance, interestRate);
}
public void deposit(double amount, String pin){
if(invalidPinCount>=3){
System.out.println("3 consecutine inavlid PINs tried!");
return;
}
if(pin.equalsIgnoreCase(PIN)){
this.setBalance(this.getBalance()+amount);
System.out.println("Deposit Successful");
System.out.println("New Amount:"+this.getBalance());
invalidPinCount = 0;
}
else{
System.out.println("Invalid PIN!");
invalidPinCount++;
try {
throw new Exception("Invalid PIN!");
} catch (Exception e) {
e.printStackTrace();
}
}
return;
}
public void withdraw(double amount,String pin){
if(invalidPinCount>=3){
System.out.println("3 consecutine inavlid PINs tried!");
return;
}
if(pin.equalsIgnoreCase(PIN)){
if(this.getBalance()>=minimumBalanceRequired){
this.setBalance(this.getBalance()-amount);
System.out.println("Withdrawl Successful");
System.out.println("New Amount:"+this.getBalance());
}
else{
//deduct a fee whenever the balance is below the minimum.
this.setBalance(this.getBalance() - checkFee);
}
invalidPinCount = 0;
}
else{
System.out.println("Invalid PIN!");
invalidPinCount++;
try {
throw new Exception("Invalid PIN!");
} catch (Exception e) {
e.printStackTrace();
}
}
return;
}
public void checkBalance(String pin){
if(invalidPinCount>=3){
System.out.println("3 consecutine inavlid PINs tried!");
return;
}
if(pin.equalsIgnoreCase(PIN)){
System.out.println("Balance:"+getBalance());
invalidPinCount = 0;
}
else{
System.out.println("Invalid PIN!");
invalidPinCount++;
try {
throw new Exception("Invalid PIN!");
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static void resetMinimumBalanceRequired(double minAmt){
minimumBalanceRequired = minAmt;
}
  
public String toString(){
String retString;
retString = "customerName : "+this.getCustomerName()+" AccountNumber : "+this.getAccountNumber()+" Balance : "+this.getBalance();
return retString;   
}
}

sketch an .toSting() method to overide the default print output.

Explanation / Answer

You already have got the toString method defined for your derived class...


public String toString(){
String retString;
retString = "customerName : "+this.getCustomerName()+" AccountNumber : "+this.getAccountNumber()+" Balance : "+this.getBalance();
return retString;   
}

It will override the toString method defined in JavaAccount class.. you have not provided the code for JavaAccount class otherwise i would have shown you the output by executing the code.

Let me know in comments if you face any issues and i will surely help you. FOr the current code which you provided, it is absolutely fine.