This code will be used to answer the question at the bottom.
public class AccountBalance {private long accountNumber;private String ownersName;private double balance;public AccountBalance(long accountNumber, String ownersName, double balance) {this.accountNumber = accountNumber;this.ownersName = ownersName;setBalance(balance);}public long getAccountNumber() {return accountNumber;}public void setAccountNumber(long accountNumber) {this.accountNumber = accountNumber;}public String getOwnersName() {return ownersName;}public void setOwnersName() {this.ownersName = ownersName;}public double getBalance() {return balance;}public void setBalance(double balance) {if (balance < 0)="">System.out.println("Balance Cannot be Negative.");balance = 0;}this.balance = balance;}}class CheckingAccount extends AccountBalance{CheckingAccount(long a, String b, double c){super(a,b,c);displayAccount();}public boolean deposit(double a) {if(a<>System.out.println("Invalid amount");elsesuper.setBalance(super.getBalance()+a);return false;}public boolean withdraw(double a) {if (a<=0 ||="" a="">super.getBalance()) {return false;}else {super.setBalance(super.getBalance()-a);return true;}}public void displayAccount() {System.out.println("Account Number: " + super.getAccountNumber());System.out.println("Owner Name: " + super.getOwnersName());System.out.println("Balance: " + super.getBalance());}}
import java.util.Scanner;public class AccountBalanceDemo {public static void main(String[] args) {Scanner sc = new Scanner(System.in);System.out.print("Enter the name of the account holder: ");String name = sc.nextLine();System.out.print("Enter the Account Number: ");long an = sc.nextLong();System.out.println("Enter the account balance: ");double balance = sc.nextDouble();CheckingAccount ab = new CheckingAccount(an,name, balance);ab.deposit(100);ab.displayAccount();if(ab.deposit(1000))ab.displayAccount();elseSystem.out.println("Invalid.");if(ab.withdraw(100));ab.displayAccount();}
}
1. Use your Account class codes as in your Lab 8.
2. Modify the main method in your CheckingAccountDemo class:
Already registered? Login
Not Account? Sign up
Enter your email address to reset your password
Back to Login? Click here