In: Computer Science
Write a Java program to process the information for a bank customer. Create a class to manage an account, include the necessary data members and methods as necessary. Develop a tester class to create an object and test all methods and print the info for 1 customer. Your program must be able to read a record from keyboard, calculate the bonus and print the details to the monitor. Bonus is 2% per year of deposit, if the amount is on deposit for 5 years the bonus is 5 * 2% = 10%. The year is calculated by dividing months on deposit by 12 and rounding down the results. If the length of deposit is 65, then 65 / 12 rounded down result is 5 years. The account also gets annual interest compounded monthly, prompt user for the rate. To calculate the compounded interest, refer to the formula and example on the next page.
This program will prompt the user for input from the keyboard. Process the data and print them on the monitor. This program will be used as the base for the next assignment.
Inputted data: Sample input:
Name Henry Smith
Address 456 Torrance Blvd.
City Torrance
State CA
Amount 3400.80
Months of deposit 65
Annual Interest Rate 5%
Output format:
Name: Smith, Henry
Address: 456 Torrance Blvd.
Torrance, CA
Deposit: $3400.80
Bonus: $340.08
Interest: $1055.33
Total: $4796.21
Requirements:
Compound Interest Formula
P = principal amount (the initial amount you borrow or deposit)
r = annual rate of interest (as a decimal)
t = number of years the amount is deposited or borrowed for.
A = amount of money accumulated after n years, including interest.
n = number of times the interest is compounded per year
Example:
An amount of $1,500.00 is deposited in a bank paying an annual interest rate of 4.3%, compounded quarterly. What is the balance after 6 years?
Solution:
Using the compound interest formula, we have that P = 1500, r = 4.3/100 = 0.043, n = 4, t = 6. Therefore,
So, the balance after 6 years is approximately $1,938.84.
The same problem with compounding monthly instead of quarterly:
A = $1500 (1+ 0.043/12)12(6)) = $1940.61
Java code for above problem
import java.util.Scanner;
class Account
{
String name,address,city,state;
int months;
double rate,amount,bonus,interest,total;
Account(String name,String address,String city,String
state,double amount,int months,double rate)
{
this.name=name;
this.address=address;
this.city=city;
this.state=state;
this.amount=amount;
this.months=months;
this.rate=rate;
this.bonus=(this.amount/10);
this.interest=this.amount*Math.pow(1.0+rate/1200,this.months)-this.amount;
this.total=this.amount+this.interest+this.bonus;
}
public String toString()
{
return "Name:
"+this.name+"\nAddress: "+this.address+", "+this.city+",
"+this.state+"\nDeposit:
$"+String.format("%.2f",this.amount) +"\nBonus:
$"+String.format("%.2f",this.bonus)+"\nInterest:
$"+String.format("%.2f",this.interest)+"\nTotal:
$"+String.format("%.2f",this.total);
}
}
class Main
{
public static void main(String args[])
{
Scanner input=new
Scanner(System.in);
System.out.print("Name: ");
String name=input.nextLine();
System.out.print("Address:
");
String
address=input.nextLine();
System.out.print("City: ");
String city=input.nextLine();
System.out.print("State: ");
String
state=input.nextLine();
System.out.print("Amount: ");
double
amount=input.nextDouble();
System.out.print("Months of
deposit: ");
int months=input.nextInt();
System.out.print("Annual Interest
Rate: ");
double rate=input.nextInt();
Account acc=new
Account(name,address,city,state,amount,months,rate);
System.out.println("\n"+acc);
}
}
Sample output
Mention in comments if any mistakes or errors are found. Thank you.