Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

public class PremiumAccount extends JavaAccount { public static double minimumBalanceRequired = 20; public static double checkFee = 2; private static String PIN = XXXYYYZZZ; private

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.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

Students also viewed these Databases questions