The question is about the relationships between bank, customers, and accounts.Cu
ID: 3698402 • Letter: T
Question
The question is about the relationships between bank, customers, and accounts.Customers may have more than one account and these accounts are saving account and checking account. Each customer’s account has current balance it is based on deposit and withdrawal activities. The balance of the bank account must never go below zero. A savings account gain interest. The bank permits customers to store money in a savings account and, on a monthly basis, the savings account will accumulate based on the following formula:
balance = balance + (interest rate x balance)
A checking account enables the customer to make any number of deposits and withdrawals. To protect their customers, the bank will permit a fixed amount of overdraft protection. This protection enables the customer’s balance to drop below zero, but not below the amount of overdraft protection. The account’s overdraft amount is decremented as it is used Based on the UML diagram, develop a complete program to solve the problem.
(I need complete java program. thanks)
Explanation / Answer
ScreenShot
---------------------------------------------------------------------------------
Code
/**Packages**/
import java.util.*;
import java.lang.*;
import java.io.*;
import java.text.DecimalFormat;
/**Class Account
* to generate account type and details**/
class Account{
int cId;
String cName,accType;
private double sBalance,cBalance;
private double interest=0.1;
double overdraft;
public void setValues(){
Random rand = new Random();
sBalance=rand.nextDouble()*100+1;
cBalance=rand.nextDouble()*100+1;
overdraft=rand.nextDouble()*10000;
}
/**Default constructor**/
public Account()
{
accType="";
cName="";
cId=0;
sBalance = 0;
interest = 0;
}
/**Parameterisedconstructor**/
public Account(String cusName,int cusId,String aType)
{
cName=cusName;
cId=cusId;
accType=aType;
}
/** deposit calculations
Add deposit amount,withdrow and balnce calculation**/
public void deposit(double amount)
{
if(accType=="savings"){
sBalance =sBalance + amount;
}
else{
cBalance =cBalance + amount;
}
}
public void withdraw(double amount)
{
if(accType=="savings"){
if(sBalance<amount){
System.out.println("Insufficient Balance");
System.exit(0);
}
else{
sBalance = sBalance - amount;
}
}
else{
if((cBalance+overdraft)<amount){
System.out.println("Insufficient Balance");
System.exit(0);
}
else{
cBalance = cBalance - amount;
}
}
}
/**Add interest in savings account**/
public void addInterest()
{
sBalance = sBalance + sBalance * interest;
}
/**Add overdraft in checking account **/
public void addOverdraft(){
cBalance=cBalance+overdraft;
}
/**According to account type get balance **/
public double getSBalance()
{
// DecimalFormat df = new DecimalFormat(".##");
//sBalance=df.format(sBalance);
return sBalance;
}
public double getCBalance()
{
// DecimalFormat df = new DecimalFormat(".##");
//cBalance=df.format(cBalance);
return cBalance;
}
/**Display the values **/
public void display(){
if(accType=="savings"){
addInterest();
System.out.println("Customer Name= "+cName+" CustomerId="+cId+" Account Type ="+accType+" Available Balance="+sBalance);
}
else{
addOverdraft();
System.out.println("Customer Name= "+cName+" CustomerId="+cId+" Account Type ="+accType+" Available Balance="+cBalance);
}
}
}
/**Main class
* Main method**/
class Ideone
{
public static void main (String[] args) throws java.lang.Exception
{
/** Object creation and method calls **/
Account acc = new Account("Jimmy",1234,"checking");
acc.setValues();
acc.withdraw(250);
acc.deposit(400);
acc.display();
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.