I would greatly appreciate help on this study question. Thank you. Create a \"Ne
ID: 670923 • Letter: I
Question
I would greatly appreciate help on this study question. Thank you.
Create a "NewAccount" class that inherits the properties and behaviors of the Account class below.
-------------------------------------------------------------------
class Account
{
private int number;
private double balance;
private double annualInterestRate;
private java.util.Date dateCreated = new java.util.Date();
public Account()
{
java.util.Date dateCreated = new java.util.Date();
}
public Account (int id, double bal, double Rate)
{
number=id;
balance=bal;
annualInterestRate=Rate;
}
public void setDate(java.util.Date dateCreated)
{
this.dateCreated = dateCreated;
}
public java.util.Date getdate()
{
return dateCreated;
}
public int getID()
{
return number;
}
public double getBalance()
{
return balance;
}
public double getAnnualInterestRate()
{
return annualInterestRate;
}
public double deposit (double deposit)
{
balance += deposit;
return(deposit);
}
public double withdraw (double withdraw)
{
this.balance -= withdraw;
return(withdraw);
}
public void setAnnualInterestRate(double annualInterestrate)
{
this.annualInterestRate = annualInterestRate;
}
public double getMonthlyInterestRate()
{
double monthlyInterest = (annualInterestRate / 1200) * balance;
return monthlyInterest;
}
}
-------------------------------------------------------------------
The NewAccount class will have these properties:
-A constructor that constructs an account with the specified name, id, and balance
-A data field, name (of type String), which stores the name of the customer
-A data field, transactions of type (ArrayList; i.e. ArrayList). The Transaction is defined asMembers
date: java.util.Date
type: char
amount: double
balance: double
description: String
Constructor
Transaction(type: char, amount: double, balance: double, description: double)
Methods
getters for type, amount, balance, date, and description
setters for type, amount, balance, date, and description
Explanation / Answer
TestDemo.java
package com.student;//package student
/**
*
* @author Chegg
*/
class Account//super class Account
{
private int id;
private double bal;
private double annualInterestRate;
private java.util.Date dateCreated = new java.util.Date();
public Account()//constructor with no arguments
{
java.util.Date dateCreated = new java.util.Date();
}
public Account (int id, double bal, double annualInterestRate)//constructor with arguments
{
this.id=id;
this.bal=bal;
this.annualInterestRate=annualInterestRate;
}
public void setDate(java.util.Date dateCreated)
{
this.dateCreated = dateCreated;
}
public java.util.Date getdate()
{
return dateCreated;
}
public int getid()
{
return id;
}
public double getbal()
{
return bal;
}
public double getMonthlyInterestRate()
{
double monthlyInterest = (annualInterestRate / 1200) * bal;
return monthlyInterest;
}
public void setAnnualInterestRate(double annualInterestrate)
{
this.annualInterestRate = annualInterestRate;
}
public double getannualInterestRate()
{
return annualInterestRate;
}
public double deposit (double deposit)
{
bal += deposit;
return(deposit);
}
public double withdraw (double withdraw)
{
this.bal -= withdraw;
return(withdraw);
}
}
class NewAccount extends Account//Newaccount sub class of Account
{
int id;
double bal;
double annualInterestRate;
String custname;
NewAccount( String custname)
{
this.custname=custname;
System.out.println("customername"+custname);
}
NewAccount()
{
super();
}
NewAccount(int id,double bal,double annualInterestRate)
{
super(id,bal,annualInterestRate);
}
}
public class TestDemo extends NewAccount//TestDemo sub class of NewAccount
{
public static void main(String args[])
{
NewAccount obj=new NewAccount(100,23333,1.2);
NewAccount obj1=new NewAccount("Chegg");
obj.deposit(100000);
obj.withdraw(500);
System.out.println("Date="+obj.getdate());
System.out.println("balance"+obj.getbal());
System.out.println("annualinterestrate"+obj.getannualInterestRate());
System.out.println("id="+obj.getid());
// System.out.println("Annual interest rate"+ obj.getAnnualInterestRate());
System.out.println("Monthly interest rate"+obj.getMonthlyInterestRate());
}
}
output
run:
customernameChegg
Date=Wed Sep 30 14:52:00 PDT 2015
balance122833.0
annualinterestrate1.2
id=100
Monthly interest rate122.833
BUILD SUCCESSFUL (total time: 0 seconds)