1. Create a class Account that has following instance variables:
a. private account number (string)
b. private account holder name (string)
c. private balance (floating-point)
d. private account opening date (string)
e. profitRate (final, floating-point): 5% for all accounts
Supply a default constructor, a parameterized constructor, and a clone constructor. Write a setter and a getter for each private instance variable. Also include following methods:
a. withdraw: deducts a specified amount from balance
b. deposit: adds a specified amount to the balance
c. accountStatement: displays all information of an account
d. creditProfit: calculates the profit using profitRate and updates account balance
Account class should also keep track of number of accounts that have been opened at any given time.
Write another class Bank, which acts as your main class. Inside main method, create a one-dimensional array of objects of Account type. At the start of your program, it should prompt for total number of accounts to be created. After creating an array of desired number of accounts, your program shall provide a console-based menu to user with following options:
1) Open an Account (required input: values for initialization of instance variables of new account object/instance)
2) Withdraw an Amount (required input: account number, amount to withdraw)
3) Deposit an Amount (required input: account number, amount to deposit)
4) Account Statement (required input: account number)
5) Credit Profit (required input: account number)
6) Total Number of Accounts Opened
7) Exit Program
and so far i did this .....
Account class :
class Account{
private String accountNumber;
private String accountHolder;
private float balance;
private String accountOpeningDate;
final float PROFIT_RATE = 0.5f ;
static int count=0;
Account(){
accountNumber = " " ;
accountHolder = " " ;
balance = 0.0f ;
accountOpeningDate = " " ;
count++;
}
Account(String a,String b, String c, Float d){
accountNumber = a ;
accountHolder = b ;
balance = d ;
accountOpeningDate = c ;
count++;
}
Account(Account ac)
{
accountNumber = ac.accountNumber ;
accountHolder = ac.accountHolder ;
balance = ac.balance ;
accountOpeningDate = ac.accountOpeningDate ;
}
void setaccountNumber(String acn){
Math.random();
accountNumber=acn;
}
void setaccountHolder(String ah)
{
accountHolder=ah;
}
void setbalance(float bal)
{
balance=bal;
}
void setaccountOpeningDate(String aod)
{
accountOpeningDate=aod;
}
String getaccountNumber()
{
return accountNumber;
}
String getaccountHolder()
{
return accountHolder;
}
String getaccountOpeningDate()
{
return accountOpeningDate;
}
float getbalance()
{
return balance;
}
void openAcc(String n,String d,String num,float bal)
{
setaccountHolder(n);
setaccountOpeningDate(d);
setaccountNumber(num);
setbalance(bal);
}void withDraw(String num,float bal)
{
[B]Account acc[]=new Account[count];
for(int i=0;i<count;i++){
acc[i]=new Account();
acc[i].getaccountNumber();
[/B]
}
}
}
and now the bank class where all methods are called ...
import javax.swing.JOptionPane;
class Bank{
public static void main(String []args){
String name,number,date;
float bal,profit;
int num=Integer.parseInt(JOptionPane.showInputDialog("Enter"));
Account acc[]=new Account[num];
for(int i=0;i<acc.length;i++)
{
acc[i]=new Account();
System.out.println(Account.count);
System.out.println("What do you want to do ? ");
System.out.println("Open an Account (1)");
System.out.println("WithDraw Amount (2)");
System.out.println("Deposit Amount (3)");
System.out.println("Account Statement (4)");
System.out.println("Credit Profit (5)");
System.out.println("Total Number of Accounts (6)");
System.out.println("Exit (7)");
int ch=Integer.parseInt(JOptionPane.showInputDialog("Enter your choice :"));
switch(ch)
{
case 1:
name=JOptionPane.showInputDialog("Enter your name:");
date=JOptionPane.showInputDialog("Enter Date:");
number=JOptionPane.showInputDialog("Enter Account Number:");
bal=Float.parseFloat(JOptionPane.showInputDialog("Deposting Amount:"));
acc[i].openAcc(name,date,number,bal);
System.out.println(acc[i].getaccountNumber());
break;
case 2:
number=JOptionPane.showInputDialog("Enter Account Number:");
bal=Float.parseFloat(JOptionPane.showInputDialog("Withdrawing Amount:"));
acc[i].withDraw(number,bal);
break;
.
.
.
.
.
.
.
case 7:
System.exit(0);
break;
}
}
}
}
plz anyone ! help me .... i have been trying it myself for long tym .