Question

Account that contains: balance: double data field date: Date data field. Use Date class from the java.util package accountNumA method called deposit that takes a parameter of type double. This method will add the value of the parameter to the balance

in java

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer;

BankAccount.java

import java.util.Date;

public class BankAccount {

double balance;
Date date;
long accountNumber;
double annualInterestRate;
Customer customer;
public double getBalance() {
return balance;
}
public void setBalance(double balance) {
this.balance = balance;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public double getAnnualInterestRate() {
return annualInterestRate;
}
public void setAnnualInterestRate(double annualInterestRate) {
this.annualInterestRate = annualInterestRate;
}
public Customer getCustomer() {
return customer;
}
public void setCustomer(Customer customer) {
this.customer = customer;
}
public long getAccountNumber() {
return accountNumber;
}

BankAccount(Customer c,double bal,double interest)
{
this.customer=c;
this.balance=bal;
this.annualInterestRate=interest;
this.accountNumber=generateAccountNumber();
this.date=new Date();

}

public double getMonthlyInterestRate()
{
return this.annualInterestRate/12;

}

public double getMonthlyInterest()
{
return (balance*getMonthlyInterestRate())/100;
}

public long generateAccountNumber()
{
return (long) (Math.random() * 1000000000);
}

public boolean deposit(double no)
{
if(no>0)
{balance=balance+no;
return true;}
return false;
}

public boolean withdraw(double no)
{
if(no>0 && no<=balance)
{
balance=balance-no;
return true;
}
return false;
}

public String toString()
{
return "\nBankAccount[Balance= "+balance+"\ndate= "+date+"\nAccountNumber= "+accountNumber+"\nInterestRate="+annualInterestRate+"\n"+customer+"]";
}

}

Customer.java

package shreya;

public class Customer {

String firstName,lastName,address;
int age;
int id;
static int custcount;
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}

Customer(String firstName,String lastName,String address,int age)
{
this.firstName=firstName;
this.lastName=lastName;
this.age=age;
this.address=address;
custcount++;
this.id=32000+((custcount-1)*10);


}

public String toString()
{
return "\nCustomer[ID="+id+"\nFirstName="+firstName+"\nLastName="+lastName+"\nAge="+age+"\nAddress="+address+"]";
}

public boolean equals(Customer c)
{
if(this==c)
return true;
else
return false;

}

}


MainImplementation.java

package shreya;

public class MainImplementation {

public static void main(String[] args) {
// TODO Auto-generated method stub
Customer c1=new Customer("Sarah","Smith","319 grand ave",24);
Customer c2=new Customer("John","Smith","12 nicollect",34);

System.out.println("customer-1 toString:");
System.out.println(c1);
System.out.println("\ncustomer-2 toString:");
System.out.println(c2);
BankAccount b1=new BankAccount(c1,1330.0,4.5);
System.out.println("Current balance :"+b1.getBalance());
b1.deposit(200);
System.out.println("Current balance :"+b1.getBalance());
System.out.println("Account Number : "+b1.getAccountNumber());
System.out.println("Account created date : "+b1.getDate());
System.out.println("Customer id : "+b1.getCustomer().id);
System.out.println("Monthly interest Rate : "+b1.getMonthlyInterestRate());
System.out.println("Monthly Interest : "+b1.getMonthlyInterest());
System.out.println("Account-1 toString output : ");
System.out.println(b1);


}

}


Output:

customer-1 toString:

Customer[ID=32000
FirstName=Sarah
LastName=Smith
Age=24
Address=319 grand ave]

customer-2 toString:

Customer[ID=32010
FirstName=John
LastName=Smith
Age=34
Address=12 nicollect]
Current balance :1330.0
Current balance :1530.0
Account Number : 909290549
Account created date : Fri Feb 08 15:20:12 IST 2019
Customer id : 32000
Monthly interest Rate : 0.375
Monthly Interest : 5.7375
Account-1 toString output :

BankAccount[Balance= 1530.0
date= Fri Feb 08 15:20:12 IST 2019
AccountNumber= 909290549
InterestRate=4.5

Customer[ID=32000
FirstName=Sarah
LastName=Smith
Age=24
Address=319 grand ave]]

Add a comment
Know the answer?
Add Answer to:
in java Account that contains: balance: double data field date: Date data field. Use Date class...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • (The Account class) Design a class named Account that contains: A private int data field named...

    (The Account class) Design a class named Account that contains: A private int data field named id for the account (default 0). A private double data field named balance for the account (default 0). A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. A private Date data field named dateCreated that stores the date when the account was created. A no-arg constructor that creates a default...

  • 9.7 (The Account class) Design a class named Account that contains: • A private int data...

    9.7 (The Account class) Design a class named Account that contains: • A private int data field named id for the account (default o). • A private double data field named balance for the account (default o). • A private double data field named annualInterestRate that stores the current interest rate (default o). Assume that all accounts have the same interest rate. • A private Date data field named dateCreated that stores the date when the account was created. •...

  • Design a class named BankAccount that contains: 1. A private int data field named accountId for...

    Design a class named BankAccount that contains: 1. A private int data field named accountId for the account. 2. A private double data field named accountBalance for the account (default 0). 3. A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. 4. A private Date data field named dateCreated that stores the date when the account was created. 5. A private int data field named numberOfDeposits...

  • Need help creating a Java program with mandatory requirements! VERY IMPORTANT: The George account class instance...

    Need help creating a Java program with mandatory requirements! VERY IMPORTANT: The George account class instance must be in the main class, and the requirement of printing a list of transactions for only the ids used when the program runs(Detailed in the Additional simulation requirements) is extremely important! Thank you so very much! Instructions: This homework models after a banking situation with ATM machine. You are required to create three classes, Account, Transaction, and the main class (with the main...

  • PYTHON PROGRAMMING LANGUAGE Design a class named Savings Account that contains: A private int data field...

    PYTHON PROGRAMMING LANGUAGE Design a class named Savings Account that contains: A private int data field named id for the savings account. A private float data field named balance for the savings account. A private float data field named annuallnterestRate that stores the current interest rate. A_init_ that creates an account with the specified id (default 0), initial balance (default 100), and annual interest rate (default 0). . The accessor and mutator methods for id, balance, and annuallnterestRate. A method...

  • JAVA PLEASE Create a class called Account with the following instance data Integer id Double balance...

    JAVA PLEASE Create a class called Account with the following instance data Integer id Double balance Provides the following methods Default constructor (defaults balance to 100) Constructor with parameters for the ID and the starting balance Accessor and mutator methods for id and balance Method to perform a withdrawal Method to perform a deposit Create a class called Bank which has an array of Account objects. This class will manage the accounts. It must provide methods Do withdrawal Do deposits...

  • Design a class named BankAccount containing the following data field and methods. • One double data...

    Design a class named BankAccount containing the following data field and methods. • One double data field named balance with default values 0.0 to denote the balance of the account. • A no-arg constructor that creates a default bank account. • A constructor that creates a bank account with the specified balance.  throw an IllegalArgumentException when constructing an account with a negative balance • The accessor method for the data field. • A method named deposit(double amount) that deposits...

  • This is for java programming Please Show plenty of comments so I can follow the steps...

    This is for java programming Please Show plenty of comments so I can follow the steps Design a class named Account that contains: • A private int data field named id for the account (default 0) • A private double data field named balance for the account (default 0) • A private double data field named annualInterestRate that stores the current interest rate (default 0). Assume all accounts have the same interest rate. • A private Date data field named...

  • JAVA PROGRAMMING LANGUAGE!!!! JAVA PROGRAMMING LANGUAGE!!!! JAVA PROGRAMMING LANGUAGE!!!! Bank Account and Savings Account Classes Design...

    JAVA PROGRAMMING LANGUAGE!!!! JAVA PROGRAMMING LANGUAGE!!!! JAVA PROGRAMMING LANGUAGE!!!! Bank Account and Savings Account Classes Design an abstract class named BankAccount to hold the following data for a bank account: • Balance • Number of deposits this month • Number of withdrawals • Annual interest rate • Monthly service charges The class should have the following methods: Constructor:   The constructor should accept arguments for the balance and annual interest rate. deposit:             A method that accepts an argument for the amount of...

  • Implement a Java class that is called RainFall that uses a double array to store the...

    Implement a Java class that is called RainFall that uses a double array to store the amount of rainfall for each month of the year. The class should have only one instance variable of type double[]. Implement the following methods in the RainFall class: 1. A constructor that creates and initializes all entries in the array to be -1. 2. toString: a method that returns a one-line String representation of the object that includes 12 double numbers that represent the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT