import java.util.Scanner;
import java.text.*;
public class S10091234_AssignmentTemplate
{
public static void main(String[] args);
{
Scanner scn = new Scanner(System.in);
int[] accNumber = new int[20]; // array to store account numbers
String[] accName = new String[20]; // array to store account names
double[] accBalance = new double[20] ; // array to store account balances
int count; // stores the number of bank accounts
int choice=1;
// initialize the arrays with some accounts
count = initAccounts(accNumber, accName, accBalance);
while(choice !=5)
{
displayMenu();
choice=scn.nextInt();
if(choice==1)
{
displayAllAccounts(accNumber, accName, accBalance, count);
}
else
if(choice==2)
{
displayAllAccounts(accNumber, accName, accBalance, count);
depositMoney(accBalance, count);
}
else
if(choice==3)
{
displayAllAccounts(accNumber, accName, accBalance, count);
withdrawMoney(accBalance, count);
}
else
if(choice==4)
{
double tempVar = findHighestBalance(accNumber, accName, accBalance);
for (int x = 0; x < accBalance.length; x++)
if (tempVar==accBalance[x])
{
System.out.println("Highest Balance Account :");
System.out.println("Account Number\tAccount Name\tBalance[$]");
System.out.println(accNumber[x]+"\t"+accName[x]+"\t"+accBalance[x]);
}
}
else
if(choice==5)
System.out.println("Exit");
else
System.out.println("Error! Please Key In The Correct Choice.");
}
}
// method to initialize some bank accounts
public static int initAccounts(int[] accNumber, String[] accName, double[] accBalance)
{
int count = 0;
accNumber[0] = 111111;
accName[0] = "Kevin Tan";
accBalance[0] = 10000.00;
count++;
accNumber[1] = 222222;
accName[1] = "Janice Ng";
accBalance[1] = 20000.00;
count++;
accNumber[2] = 333333;
accName[2] = "Wendy Sng";
accBalance[2] = 30000.00;
count++;
accNumber[3] = 444444;
accName[3] = "Brian Ong";
accBalance[3] = 40000.00;
count++;
accNumber[4] = 555555;
accName[4] = "Terry Lee";
accBalance[4] = 50000.00;
count++;
return count;
}
public static void displayMenu()
{
// display main menu
System.out.println("Main Menu");
System.out.println("[1] Display All Accounts.");
System.out.println("[2] Deposit Money.");
System.out.println("[3] Withdraw Money.");
System.out.println("[4] Locate The Highest Balance Of The Accounts.");
System.out.println("[5] Exit.");
System.out.print("Enter Your Option: ");
}
// Method to display account
public static void displayAllAccounts(int[] accNumber, String[] accName,double[] accBalance, int count)
{
System.out.println("Serial \tAccount\tName\t\tBalance");
for (int n=0 ;n<count; n++)
System.out.println((n+1)+ "\t" + accNumber[n] + "\t" +accName[n] + "\t" + accBalance[n]);
}
// Method To Deposit Money
public static void depositMoney(double[] accBalance, int count)
{
Scanner scn = new Scanner(System.in);
System.out.print("Select Account: ");
int y = scn.nextInt();
if (y > count)
{
System.out.println("Error! Please Key In The Correct Choice.");
}
else
{
System.out.print("Key In The Amount To Deposit: ");
double a = scn.nextDouble();
if (a < 0)
{
System.out.println("Error! Please Key In The Correct Amount.");
}
else
{
accBalance[y-1]+=a;
System.out.println("Money Is Deposited Successfully.");
}
}
}
// Method To Withdraw Money
public static void withdrawMoney(double[] accBalance, int count)
{
Scanner scn = new Scanner(System.in);
System.out.print("Select Account: ");
int y = scn.nextInt();
if (y > count)
{
System.out.println("Error! Please Key In The Correct Choice.");
}
else
{
System.out.print("Key In The Amount To Withdraw: ");
double a = scn.nextDouble();
if (a < 0 || a > accBalance[y-1])
{
System.out.println("Error! Please Key In The Correct Amount.");
}
else
{
accBalance[y-1]-=a;
System.out.println("Money Is Withdrew Successfully.");
}
}
}
// Method To Find The Highest Balance Of All
public static double findHighestBalance(int[] accNumber, String[] accName, double[] accBalance)
{
double highestBalance;
highestBalance = accBalance[0];
for (int b=0; b<accBalance.length; b++)
{
if (accBalance[b] > highestBalance)
highestBalance = accBalance[b];
}
return highestBalance;
}
}
HOW TO CREATE AND CLOSE ACCOUNT?
This post has been edited by no2pencil: 27 July 2010 - 07:17 PM
Reason for edit:: Added code tags

New Topic/Question
Reply




MultiQuote



|