













Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!














●
●
●
●
●
●
public class Checking extends Account{ Checking(String name, double amount){ this.name = name; if (amount > 0){ this.balance = amount; } else { // error reporting code omitted this.balance = 0; } } public boolean withdraw(double amount){ if (amount > 0 && amount <= balance) { balance = balance - amount; return true; } else if ( amount > balance){ // error reporting code omitted return false; } else { // error reporting code omitted return false; } } public void display(){ System.out.println(" ****** Current Account Details ****** "); System.out.println(" Name: "+ this.getName()); System.out.println(" Current Balance: "+ this.getBalance()); System.out.println("\t\t\t\t ****** Current Account Details ****** "); } }
public class Savings extends Account{ double minimumBalance; Savings(String name, double amount, double minBalance){ this.name = name; if (amount > 0){ this.balance = amount; } else { // error reporting code omitted this.balance = 0; } if (minBalance > 0){ this.minimumBalance = minBalance; } else { // error reporting code omitted this.minimumBalance = 0; } } Savings(String name, double amount){ this.name = name; if (amount > 0){ this.balance = amount; } else { this.balance = 0; } this.minimumBalance = 0; } }
public class Main{ public static void main(String[] args){ Savings mySavings = new Savings(“John”,100.00,50.00); Savings anotherSavings = new Savings(“Mary”,200.00); } } public class Savings extends Account{ double minimumBalance; Savings(String name, double amount, double minBalance){ this.name = name; if (amount > 0){ this.balance = amount; } else { // error reporting code omitted this.balance = 0; } if (minBalance > 0){ this.minimumBalance = minBalance; } else { // error reporting code omitted this.minimumBalance = 0; } } Savings(String name, double amount){ this.name = name; if (amount > 0){ this.balance = amount; } else { this.balance = 0; } this.minimumBalance = 0; } }
●
interface IAccount { public double getBalance(); public String getName(); public void setName(String aName); public void setBalance(double amount); public boolean deposit(double amount); public boolean withdraw(double amount); public void display(); } ●
public class Checking implements IAccount{ double minimumBalance; double balance; String name; // Same as Slide 7 public double getBalance(){ } public void setBalance(double val){ } public String getName(){ } public void setName(String aName){ } public boolean deposit(double amount){ } // Same as Slide 8 public boolean withdraw(double amount){ } public void display(){ } }
●
●
●
●
●
public class Main{ public static void main(String[] args){ Savings mySavings = new Savings(“John”,100.00,50.00); Savings anotherSavings = new Savings(“Mary”,200.00); Checking cAccount = new Checking(“Michael”, 89.00); mySavings.display(); mySavings.display(“Today”); Account oneAC = (Account) mySavings; Account secondAC= (Account) cAccount; Account[] allAccounts = new Account[10]; allAccounts[0] = oneAC; allAccounts[1] = secondAC; } }