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...

  • 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...

  • 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...

  • In C++ Write a program that contains a BankAccount class. The BankAccount class should store the...

    In C++ Write a program that contains a BankAccount class. The BankAccount class should store the following attributes: account name account balance Make sure you use the correct access modifiers for the variables. Write get/set methods for all attributes. Write a constructor that takes two parameters. Write a default constructor. Write a method called Deposit(double) that adds the passed in amount to the balance. Write a method called Withdraw(double) that subtracts the passed in amount from the balance. Do not...

  • code must be in java. Assignment 5 Purpose In this assignment, you will implement a class...

    code must be in java. Assignment 5 Purpose In this assignment, you will implement a class hierarchy in Java. Instructions The class hierarchy you will implement is shown below account Package Account manager Package SavingAccount CheckingAccount AccountManager The descriptions of each class and the corresponding members are provided below. Please note that the Visibility Modifiers (public, private and protected) are not specified and you must use the most appropriate modifiers Class AccountManager is a test main program. Create it so...

  • Using JAVA* Design a class named Person with fields for holding a person’s name, address, and...

    Using JAVA* Design a class named Person with fields for holding a person’s name, address, and telephone number. Write one or more constructors and the appropriate mutator and accessor methods for the class’s fields. Next, design a class named Customer, which extends the Person class. The Customer class should have a field for a customer number and a boolean field indicating whether the customer wishes to be on a mailing list. Write one or more constructors and the appropriate mutator...

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
ADVERTISEMENT