This needs to be done in Netbeans! In this lab, you will extend your Account Cla
ID: 3806406 • Letter: T
Question
This needs to be done in Netbeans!
In this lab, you will extend your Account Class to create and use a CheckingAccount and SavingsAccout class.
The account class is below in between the dashed lines
-------------------------------------------------------------------------------
public class Account {
public static void main (String[] args) {
Account account = new Account(1122, 20000, 4.5);
account.withdraw(10000);
account.deposit(3000);
System.out.println("Balance is " + account.getBalance());
System.out.println("Monthly interest is " + account.getMonthlyInterest());
System.out.println("This account was created at " + account.getDateCreated());
}
}
public
class Account {
private int id;
private double balance;
private double annualInterestRate;
private java.util.Date dateCreated;
double data[] = new double[20];
public Account() {
dateCreated = new java.util.Date();
}
public Account(int id, double balance, double annualInterestRate) {
this.id = id;
this.balance = balance;
this.annualInterestRate = annualInterestRate;
dateCreated = new java.util.Date();
}
public int getId() {
return this.id;
}
public double getBalance() {
return balance;
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setId(int id) {
this.id =id;
}
public void setBalance(double balance) {
this.balance = balance;
}
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
public double getMonthlyInterest() {
return balance * (annualInterestRate / 1200);
}
public java.util.Date getDateCreated() {
return dateCreated;
}
public void withdraw(double amount) {
balance -= amount;
}
public void deposit(double amount) {
balance += amount;
}
}
--------------------------------------------------------------------------------------
1. Create a CheckingAccount class that extends Account with the following data members:
public int lastCheckNumber;
public boolean overdraftProection;
and which does the following:
Initializes lastCheckNumber to 0 in your constructor.
Initializes overdraftProtection to false in your constructor.
Creates accessor (get) and mutator (set) methods for both of these data members.
2. Create a SavingsAccount class that extends Account with the following data members:
public double highBalance;
public boolean premiumMember;
and which does the following:
Initializes highBalance to 0 in your constructor.
Initializes premiumMember to false in your constructor.
Creates accessor (get) and mutator (set) methods for both of these data members.
3. Create a test driver (main) that does the following:
Creates a CheckingAccount called newMemberChkAcct.
Creates a SavingsAccount called newSavingsChkAcct.
Sets the lastCheckNumber to 100.
Sets the overdraftProtection to true.
Sets the highBalance to 2300.55.
Outputs the data members values to the console:
Last Check Number: _________
Overdraft Protection: ________
High Balance: ______________
Premium Member: __________
Explanation / Answer
public class Account {
private int id;
private double balance;
private double annualInterestRate;
private java.util.Date dateCreated;
double data[] = new double[20];
public Account() {
dateCreated = new java.util.Date();
}
public Account(int id, double balance, double annualInterestRate) {
this.id = id;
this.balance = balance;
this.annualInterestRate = annualInterestRate;
dateCreated = new java.util.Date();
}
public int getId() {
return this.id;
}
public double getBalance() {
return balance;
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setId(int id) {
this.id =id;
}
public void setBalance(double balance) {
this.balance = balance;
}
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
public double getMonthlyInterest() {
return balance * (annualInterestRate / 1200);
}
public java.util.Date getDateCreated() {
return dateCreated;
}
public void withdraw(double amount) {
balance -= amount;
}
public void deposit(double amount) {
balance += amount;
}
public static void main (String[] args) {
/* Account account = new Account(1122, 20000, 4.5);
account.withdraw(10000);
account.deposit(3000);
System.out.println("Balance is " + account.getBalance());
System.out.println("Monthly interest is " + account.getMonthlyInterest());
System.out.println("This account was created at " + account.getDateCreated());
*/
CheckingAccount newMemberChkAcct=new CheckingAccount();
newMemberChkAcct.setLastCheckNumber(100);
newMemberChkAcct.setOverdraftProection(true);
SavingsAccount newSavingsChkAcct=new SavingsAccount();
newSavingsChkAcct.setHighBalance(2300.55);
System.out.println("Last Check Number : newMemberChkAcct :"+newMemberChkAcct.getLastCheckNumber());
System.out.println("OverDraft Protection : newMemberChkAcct :"+newMemberChkAcct.getOverdraftProection());
System.out.println("High Balance : newSavingsChkAcct :"+newSavingsChkAcct.getHighBalance());
System.out.println("Premium Number :newSavingsChkAcct :"+newSavingsChkAcct.getPremiumNumber());
}
}
class CheckingAccount extends Account{
public int lastCheckNumber;
public boolean overdraftProection;
public CheckingAccount(){
super();
lastCheckNumber=0;
overdraftProection=false;
}
public CheckingAccount(int id, double balance, double annualInterestRate, int lastCheckNumber, boolean overdraftProection){
super(id,balance,annualInterestRate);
this.lastCheckNumber=lastCheckNumber;
this.overdraftProection=overdraftProection;
}
public int getLastCheckNumber(){
return lastCheckNumber;
}
public boolean getOverdraftProection(){
return overdraftProection;
}
public void setLastCheckNumber(int lastCheckNumber){
this.lastCheckNumber=lastCheckNumber;
}
public void setOverdraftProection(boolean overdraftProection){
this.overdraftProection=overdraftProection;
}
}
class SavingsAccount extends Account{
public double highBalance;
public boolean premiumMember;
public SavingsAccount(){
super();
highBalance=0;
premiumMember=false;
}
public SavingsAccount(int id, double balance, double annualInterestRate, double highBalance, boolean premiumMember){
super(id,balance,annualInterestRate);
this.highBalance=highBalance;
this.premiumMember=premiumMember;
}
public double getHighBalance(){
return highBalance;
}
public boolean getPremiumNumber(){
return premiumMember;
}
public void setHighBalance(double highBalance){
this.highBalance=highBalance;
}
public void setPremiumNumber(boolean premiumMember){
this.premiumMember=premiumMember;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.