SlideShare a Scribd company logo
1 of 15
Download to read offline
Bank Program in Java
Below is my code(haven't finished, but it be run without error messages.)
My problem is in Case 1. For example, if I enter two customers:
Name: John Kangas Account Number: A123 Balance: 300
Name: Mary White Account Number: B321 Balance: 600
In the output -- For testing, I expected it to be like this:
***For Testing!
John Kangas
Balance: 300.0
****
***For Testing!
Mary White
Balance: 600.0
****
However, it actually came out like this:
***For Testing!
Mary White
Balance: 600.0
****
***For Testing!
Mary White
Balance: 600.0
****
It seems that the second information replace the first one. Could anyone help me figure it out??
Thank you so much!!
=========
Bank Class
=========
import java.util.ArrayList;
import java.util.Scanner;
public class Bank {
String routingNum;
static Customer customer;
static ArrayList customerList = new ArrayList();
private static int numOfCustomers = 0;
private static double bal;
public Bank(){
routingNum = "000000";
}
public static void newCustomer(String f, String l, String accNum, double bal){
Account acc = Customer.OpenAccount(accNum,bal);
customer = new Customer(f,l,acc);
customerList.add(customer);
numOfCustomers ++;
//For Testing
for (int i = 0; i < numOfCustomers; i++ ){
System.out.println(" ***For Testing! "+ customerList.get(i).getName());
System.out.println("Balance: " + customerList.get(i).getAccount().getBalance());
System.out.println("****");
}
}
public static double findCustomer(String f, String l, String accNum){
//For Testing
System.out.println("***For Testing! "+ "numOfCustomers: " + numOfCustomers);
for (int i = 0; i < numOfCustomers; i++){
String name = customerList.get(i).getName();
int n = name.indexOf(" ");
int L = name.length();
String first = name.substring(0, n); //In order to separate
String last = name.substring(n+1, L); //first and last name
String accN = customerList.get(i).getAccount().getAccountNum();
//For Testing
System.out.println("***For Testing! " + "acc num: " + accN);
if ( f.equals(first) && l.equals(last) || accNum.equals(accN) ){
bal = customerList.get(i).getAccount().getBalance();
System.out.print(" Balance: " + bal +"  ");
}else{
System.out.println("No Found Account.");
}
}
return bal;
}
public static void main(String[] args){
Scanner s = new Scanner(System.in);
boolean control = true;
while(control){
System.out.println("Hello! Welcome to New Century Bank!");
System.out.println("Enter('1'): Open an Account");
System.out.println("Enter('2'): Get your balance");
System.out.println("Enter('3'): Deposit");
System.out.println("Enter('4'): Withdraw");
System.out.println("Enter('5'): Close an Account");
System.out.println("Enter('6'): Exit");
int user_choice = s.nextInt();
String input1, input2, input3;
double input4;
switch(user_choice){
case 1: System.out.println("Your name(first last): ");
input1 = s.next();
input2 = s.next();
System.out.println("Enter an account number: ");
input3 = s.next();
System.out.println("Enter an opening balance: ");
input4 = s.nextDouble();
newCustomer(input1, input2, input3, input4);
break;
case 2: System.out.println("Your name(first last): ");
input1 = s.next();
input2 = s.next();
System.out.println("Enter an account number: ");
input3 = s.next();
bal = findCustomer(input1, input2, input3);
System.out.println(" Your current balance is $" + bal + ". ");
break;
case 3: System.out.println("Your name(first last): ");
input1 = s.next();
input2 = s.next();
System.out.println("Enter an account number: ");
input3 = s.next();
System.out.println("Enter a deposit amount: ");
input4 = s.nextDouble();
break;
case 4: System.out.println("Your name(first last): ");
input1 = s.next();
input2 = s.next();
break;
case 5: System.out.println("Your name(first last): ");
input1 = s.next();
input2 = s.next();
break;
case 6: control = false;
default: control = false;
}
}
System.out.println("Thank you for using New Century Bank!");
}
}
========
Customer
========
public class Customer {
static Account account;
static String first, last;
public Customer(String f, String l, Account acc){
first = f;
last = l;
account = acc;
}
public String getName(){
return first + " " + last;
}
public Account getAccount(){
return account;
}
public static Account OpenAccount(String accNum, double bal){
account = new Account(accNum, bal);
return account;
}
public void CloseAccount(String f, String l, String accNum, double bal){
f = first;
l = last;
accNum = account.getAccountNum();
bal = account.getBalance();
}
}
======
Account
======
public class Account {
String accountNum;
double balance, minBalance, overDraftFee;
public Account(){
accountNum = "000000";
balance = 0.0;
minBalance = 100;
overDraftFee = 10;
}
public Account(String accNum, double bal){
accountNum = accNum;
balance = bal;
}
public String getAccountNum(){
return accountNum;
}
public double getBalance(){
return balance;
}
public double getOverDraftFee(){
return overDraftFee;
}
public double minBalance(){
return minBalance;
}
public void DepositFunds(Customer customer, double amount){
if (amount < 0){
System.out.println("Deposit amount should not be negative.");
}else{
double bal = customer.account.getBalance();
bal += amount;
}
}
public void WithdrawFunds(Customer customer, double amount){
if (amount < 0){
System.out.println("Withdraw amount should not be negative.");
}else{
double bal = customer.account.getBalance();
bal -= amount;
if (bal < 0){
System.out.println("***Your balance is less then withdraw amount; " +
"***Overdraft fee($10) is charged now.");
bal -= overDraftFee;
}
}
}
public void PrintAccountInfo(Customer customer){
System.out.println("**** Account Information *** "+
"Name: " + customer.getName() + "  " +
"Current Balance: " + customer.account.getBalance() + "  " +
"Account Number: " + customer.account.getAccountNum());
}
}
Solution
public class Account {
String accountNum;
double balance, minBalance, overDraftFee;
public Account() {
accountNum = "000000";
balance = 0.0;
minBalance = 100;
overDraftFee = 10;
}
public Account(String accNum, double bal) {
accountNum = accNum;
balance = bal;
}
public String getAccountNum() {
return accountNum;
}
public double getBalance() {
return balance;
}
public double getOverDraftFee() {
return overDraftFee;
}
public double minBalance() {
return minBalance;
}
public void DepositFunds(Customer customer, double amount) {
if (amount < 0) {
System.out.println("Deposit amount should not be negative.");
} else {
double bal = customer.account.getBalance();
bal += amount;
}
}
public void WithdrawFunds(Customer customer, double amount) {
if (amount < 0) {
System.out.println("Withdraw amount should not be negative.");
} else {
double bal = customer.account.getBalance();
bal -= amount;
if (bal < 0) {
System.out
.println("***Your balance is less then withdraw amount; "
+ "***Overdraft fee($10) is charged now.");
bal -= overDraftFee;
}
}
}
public void PrintAccountInfo(Customer customer) {
System.out.println("**** Account Information *** " + "Name: "
+ customer.getName() + "  " + "Current Balance: "
+ customer.account.getBalance() + "  " + "Account Number: "
+ customer.account.getAccountNum());
}
}
public class Customer {
Account account;
String first, last;
public Customer(String f, String l, Account acc) {
first = f;
last = l;
account = acc;
}
public String getName() {
return first + " " + last;
}
public Account getAccount() {
return account;
}
public Account OpenAccount(String accNum, double bal) {
account = new Account(accNum, bal);
return account;
}
public void CloseAccount(String f, String l, String accNum, double bal) {
f = first;
l = last;
accNum = account.getAccountNum();
bal = account.getBalance();
}
}
import java.util.ArrayList;
import java.util.Scanner;
public class Bank {
String routingNum;
static Customer customer;
static ArrayList customerList = new ArrayList();
private static int numOfCustomers = 0;
private static double bal;
public Bank() {
routingNum = "000000";
}
public static void newCustomer(String f, String l, String accNum, double bal) {
Account acc = new Account(accNum, bal);
System.out.println("acc==" + acc.getBalance());
customer = new Customer(f, l, acc);
customerList.add(customer);
numOfCustomers++;
// For Testing
for (int i = 0; i < numOfCustomers; i++) {
System.out.println(" ***For Testing! "
+ customerList.get(i).getName());
System.out.println("Balance: "
+ customerList.get(i).getAccount().getBalance());
System.out.println("****");
}
}
public static double findCustomer(String f, String l, String accNum) {
// For Testing
System.out.println("***For Testing! " + "numOfCustomers: "
+ numOfCustomers);
for (int i = 0; i < numOfCustomers; i++) {
String name = customerList.get(i).getName();
int n = name.indexOf(" ");
int L = name.length();
String first = name.substring(0, n); // In order to separate
String last = name.substring(n + 1, L); // first and last name
String accN = customerList.get(i).getAccount().getAccountNum();
// For Testing
System.out.println("***For Testing! " + "acc num: " + accN);
if (f.equals(first) && l.equals(last) || accNum.equals(accN)) {
bal = customerList.get(i).getAccount().getBalance();
System.out.print(" Balance: " + bal + "  ");
} else {
System.out.println("No Found Account.");
}
}
return bal;
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
boolean control = true;
while (control) {
System.out.println("Hello! Welcome to New Century Bank!");
System.out.println("Enter('1'): Open an Account");
System.out.println("Enter('2'): Get your balance");
System.out.println("Enter('3'): Deposit");
System.out.println("Enter('4'): Withdraw");
System.out.println("Enter('5'): Close an Account");
System.out.println("Enter('6'): Exit");
int user_choice = s.nextInt();
String input1, input2, input3;
double input4;
switch (user_choice) {
case 1:
System.out.println("Your name(first last): ");
input1 = s.next();
input2 = s.next();
System.out.println("Enter an account number: ");
input3 = s.next();
System.out.println("Enter an opening balance: ");
input4 = s.nextDouble();
newCustomer(input1, input2, input3, input4);
break;
case 2:
System.out.println("Your name(first last): ");
input1 = s.next();
input2 = s.next();
System.out.println("Enter an account number: ");
input3 = s.next();
bal = findCustomer(input1, input2, input3);
System.out.println(" Your current balance is $" + bal + ". ");
break;
case 3:
System.out.println("Your name(first last): ");
input1 = s.next();
input2 = s.next();
System.out.println("Enter an account number: ");
input3 = s.next();
System.out.println("Enter a deposit amount: ");
input4 = s.nextDouble();
break;
case 4:
System.out.println("Your name(first last): ");
input1 = s.next();
input2 = s.next();
break;
case 5:
System.out.println("Your name(first last): ");
input1 = s.next();
input2 = s.next();
break;
case 6:
control = false;
default:
control = false;
}
}
System.out.println("Thank you for using New Century Bank!");
}
}
OUTPUT:
Hello! Welcome to New Century Bank!
Enter('1'): Open an Account
Enter('2'): Get your balance
Enter('3'): Deposit
Enter('4'): Withdraw
Enter('5'): Close an Account
Enter('6'): Exit
1
Your name(first last):
John Kangas
Enter an account number:
A123
Enter an opening balance:
300
acc==300.0
***For Testing!
John Kangas
Balance: 300.0
****
Hello! Welcome to New Century Bank!
Enter('1'): Open an Account
Enter('2'): Get your balance
Enter('3'): Deposit
Enter('4'): Withdraw
Enter('5'): Close an Account
Enter('6'): Exit
1
Your name(first last):
Mary White
Enter an account number:
B321
Enter an opening balance:
600
acc==600.0
***For Testing!
John Kangas
Balance: 300.0
****
***For Testing!
Mary White
Balance: 600.0
****
Hello! Welcome to New Century Bank!
Enter('1'): Open an Account
Enter('2'): Get your balance
Enter('3'): Deposit
Enter('4'): Withdraw
Enter('5'): Close an Account
Enter('6'): Exit
6
Thank you for using New Century Bank!

More Related Content

Similar to Bank Program in JavaBelow is my code(havent finished, but it be .pdf

Java programI made this Account.java below. Using the attached cod.pdf
Java programI made this Account.java below. Using the attached cod.pdfJava programI made this Account.java below. Using the attached cod.pdf
Java programI made this Account.java below. Using the attached cod.pdffathimafancy
 
main.cpp #include iostream #include iomanip #include fs.pdf
main.cpp #include iostream #include iomanip #include fs.pdfmain.cpp #include iostream #include iomanip #include fs.pdf
main.cpp #include iostream #include iomanip #include fs.pdfarwholesalelors
 
#include iostream #include BankAccountClass.cpp #include .pdf
#include iostream #include BankAccountClass.cpp #include .pdf#include iostream #include BankAccountClass.cpp #include .pdf
#include iostream #include BankAccountClass.cpp #include .pdfANJANEYAINTERIOURGAL
 
This what Im suppose to do and this is what I have so far.In thi.pdf
This what Im suppose to do and this is what I have so far.In thi.pdfThis what Im suppose to do and this is what I have so far.In thi.pdf
This what Im suppose to do and this is what I have so far.In thi.pdfkavithaarp
 
Tmpj3 01 201181102muhammad_tohir
Tmpj3 01 201181102muhammad_tohirTmpj3 01 201181102muhammad_tohir
Tmpj3 01 201181102muhammad_tohirpencari buku
 
Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd marchRajeev Sharan
 
Automatically Repairing Test Cases for Evolving Method Declarations
Automatically Repairing Test Cases for Evolving Method DeclarationsAutomatically Repairing Test Cases for Evolving Method Declarations
Automatically Repairing Test Cases for Evolving Method DeclarationsICSM 2010
 
public class NegativeAmountException extends Exception {    .pdf
public class NegativeAmountException extends Exception {     .pdfpublic class NegativeAmountException extends Exception {     .pdf
public class NegativeAmountException extends Exception {    .pdfARYAN20071
 
public class InsufficientFundsException extends Exception{Insuffic.pdf
public class InsufficientFundsException extends Exception{Insuffic.pdfpublic class InsufficientFundsException extends Exception{Insuffic.pdf
public class InsufficientFundsException extends Exception{Insuffic.pdfankitcom
 
Can you fix the problem with the following code #include -iostream- #.pdf
Can you fix the problem with the following code  #include -iostream- #.pdfCan you fix the problem with the following code  #include -iostream- #.pdf
Can you fix the problem with the following code #include -iostream- #.pdfvinaythemodel
 

Similar to Bank Program in JavaBelow is my code(havent finished, but it be .pdf (12)

Java programI made this Account.java below. Using the attached cod.pdf
Java programI made this Account.java below. Using the attached cod.pdfJava programI made this Account.java below. Using the attached cod.pdf
Java programI made this Account.java below. Using the attached cod.pdf
 
main.cpp #include iostream #include iomanip #include fs.pdf
main.cpp #include iostream #include iomanip #include fs.pdfmain.cpp #include iostream #include iomanip #include fs.pdf
main.cpp #include iostream #include iomanip #include fs.pdf
 
#include iostream #include BankAccountClass.cpp #include .pdf
#include iostream #include BankAccountClass.cpp #include .pdf#include iostream #include BankAccountClass.cpp #include .pdf
#include iostream #include BankAccountClass.cpp #include .pdf
 
This what Im suppose to do and this is what I have so far.In thi.pdf
This what Im suppose to do and this is what I have so far.In thi.pdfThis what Im suppose to do and this is what I have so far.In thi.pdf
This what Im suppose to do and this is what I have so far.In thi.pdf
 
Tmpj3 01 201181102muhammad_tohir
Tmpj3 01 201181102muhammad_tohirTmpj3 01 201181102muhammad_tohir
Tmpj3 01 201181102muhammad_tohir
 
Jva
Jva Jva
Jva
 
Rajeev oops 2nd march
Rajeev oops 2nd marchRajeev oops 2nd march
Rajeev oops 2nd march
 
Automatically Repairing Test Cases for Evolving Method Declarations
Automatically Repairing Test Cases for Evolving Method DeclarationsAutomatically Repairing Test Cases for Evolving Method Declarations
Automatically Repairing Test Cases for Evolving Method Declarations
 
Bank account in java
Bank account in javaBank account in java
Bank account in java
 
public class NegativeAmountException extends Exception {    .pdf
public class NegativeAmountException extends Exception {     .pdfpublic class NegativeAmountException extends Exception {     .pdf
public class NegativeAmountException extends Exception {    .pdf
 
public class InsufficientFundsException extends Exception{Insuffic.pdf
public class InsufficientFundsException extends Exception{Insuffic.pdfpublic class InsufficientFundsException extends Exception{Insuffic.pdf
public class InsufficientFundsException extends Exception{Insuffic.pdf
 
Can you fix the problem with the following code #include -iostream- #.pdf
Can you fix the problem with the following code  #include -iostream- #.pdfCan you fix the problem with the following code  #include -iostream- #.pdf
Can you fix the problem with the following code #include -iostream- #.pdf
 

More from izabellejaeden956

Explain the advantages and disadvantages of misuse-based and anomaly.pdf
Explain the advantages and disadvantages of misuse-based and anomaly.pdfExplain the advantages and disadvantages of misuse-based and anomaly.pdf
Explain the advantages and disadvantages of misuse-based and anomaly.pdfizabellejaeden956
 
E. coli takes up plasmid DNA by which of the following methodsple.pdf
E. coli takes up plasmid DNA by which of the following methodsple.pdfE. coli takes up plasmid DNA by which of the following methodsple.pdf
E. coli takes up plasmid DNA by which of the following methodsple.pdfizabellejaeden956
 
Consider the two genes described in Question 7. What is the probabili.pdf
Consider the two genes described in Question 7. What is the probabili.pdfConsider the two genes described in Question 7. What is the probabili.pdf
Consider the two genes described in Question 7. What is the probabili.pdfizabellejaeden956
 
A wireless technology that may someday replace barcodes through the u.pdf
A wireless technology that may someday replace barcodes through the u.pdfA wireless technology that may someday replace barcodes through the u.pdf
A wireless technology that may someday replace barcodes through the u.pdfizabellejaeden956
 
The director of special events for Sun City believed that he amount o.pdf
The director of special events for Sun City believed that he amount o.pdfThe director of special events for Sun City believed that he amount o.pdf
The director of special events for Sun City believed that he amount o.pdfizabellejaeden956
 
Write an application containing three parallel arrays that hold 10 e.pdf
Write an application containing three parallel arrays that hold 10 e.pdfWrite an application containing three parallel arrays that hold 10 e.pdf
Write an application containing three parallel arrays that hold 10 e.pdfizabellejaeden956
 
Which type of project risk is the most relevantStand-alone risk.pdf
Which type of project risk is the most relevantStand-alone risk.pdfWhich type of project risk is the most relevantStand-alone risk.pdf
Which type of project risk is the most relevantStand-alone risk.pdfizabellejaeden956
 
Which of the following is an advantage businesses have over citizens.pdf
Which of the following is an advantage businesses have over citizens.pdfWhich of the following is an advantage businesses have over citizens.pdf
Which of the following is an advantage businesses have over citizens.pdfizabellejaeden956
 
what is the pseudoautosomal regionA. the region on the Y chromose.pdf
what is the pseudoautosomal regionA. the region on the Y chromose.pdfwhat is the pseudoautosomal regionA. the region on the Y chromose.pdf
what is the pseudoautosomal regionA. the region on the Y chromose.pdfizabellejaeden956
 
What is a flat file database How can it be used for forecasting.pdf
What is a flat file database How can it be used for forecasting.pdfWhat is a flat file database How can it be used for forecasting.pdf
What is a flat file database How can it be used for forecasting.pdfizabellejaeden956
 
What is, in your opinion, the minimum firewall placement for a SCADA.pdf
What is, in your opinion, the minimum firewall placement for a SCADA.pdfWhat is, in your opinion, the minimum firewall placement for a SCADA.pdf
What is, in your opinion, the minimum firewall placement for a SCADA.pdfizabellejaeden956
 
What factor(s) do not contribute to the development of mutations tha.pdf
What factor(s) do not contribute to the development of mutations tha.pdfWhat factor(s) do not contribute to the development of mutations tha.pdf
What factor(s) do not contribute to the development of mutations tha.pdfizabellejaeden956
 
Urinary Tract infections commonly caused by E. Coli is a common illn.pdf
Urinary Tract infections commonly caused by E. Coli is a common illn.pdfUrinary Tract infections commonly caused by E. Coli is a common illn.pdf
Urinary Tract infections commonly caused by E. Coli is a common illn.pdfizabellejaeden956
 
Two samples of sizes 15 and 20 are randomly and independently select.pdf
Two samples of sizes 15 and 20 are randomly and independently select.pdfTwo samples of sizes 15 and 20 are randomly and independently select.pdf
Two samples of sizes 15 and 20 are randomly and independently select.pdfizabellejaeden956
 
True or False The Coefficient of Determination shows the direction .pdf
True or False The Coefficient of Determination shows the direction .pdfTrue or False The Coefficient of Determination shows the direction .pdf
True or False The Coefficient of Determination shows the direction .pdfizabellejaeden956
 
Mechanical Engineer    A technology that had being since the last .pdf
Mechanical Engineer    A technology that had being since the last .pdfMechanical Engineer    A technology that had being since the last .pdf
Mechanical Engineer    A technology that had being since the last .pdfizabellejaeden956
 
The following transactions occurred for London Engineering O (Click .pdf
The following transactions occurred for London Engineering O (Click .pdfThe following transactions occurred for London Engineering O (Click .pdf
The following transactions occurred for London Engineering O (Click .pdfizabellejaeden956
 
Regulation of prokaryotic gene expression is simpler than that in eu.pdf
Regulation of prokaryotic gene expression is simpler than that in eu.pdfRegulation of prokaryotic gene expression is simpler than that in eu.pdf
Regulation of prokaryotic gene expression is simpler than that in eu.pdfizabellejaeden956
 
Q4. We used remote port forwarding in this scenario. How does local .pdf
Q4. We used remote port forwarding in this scenario. How does local .pdfQ4. We used remote port forwarding in this scenario. How does local .pdf
Q4. We used remote port forwarding in this scenario. How does local .pdfizabellejaeden956
 
PYTHON Lottery Number GeneratorQuestion Design a program that ge.pdf
PYTHON Lottery Number GeneratorQuestion Design a program that ge.pdfPYTHON Lottery Number GeneratorQuestion Design a program that ge.pdf
PYTHON Lottery Number GeneratorQuestion Design a program that ge.pdfizabellejaeden956
 

More from izabellejaeden956 (20)

Explain the advantages and disadvantages of misuse-based and anomaly.pdf
Explain the advantages and disadvantages of misuse-based and anomaly.pdfExplain the advantages and disadvantages of misuse-based and anomaly.pdf
Explain the advantages and disadvantages of misuse-based and anomaly.pdf
 
E. coli takes up plasmid DNA by which of the following methodsple.pdf
E. coli takes up plasmid DNA by which of the following methodsple.pdfE. coli takes up plasmid DNA by which of the following methodsple.pdf
E. coli takes up plasmid DNA by which of the following methodsple.pdf
 
Consider the two genes described in Question 7. What is the probabili.pdf
Consider the two genes described in Question 7. What is the probabili.pdfConsider the two genes described in Question 7. What is the probabili.pdf
Consider the two genes described in Question 7. What is the probabili.pdf
 
A wireless technology that may someday replace barcodes through the u.pdf
A wireless technology that may someday replace barcodes through the u.pdfA wireless technology that may someday replace barcodes through the u.pdf
A wireless technology that may someday replace barcodes through the u.pdf
 
The director of special events for Sun City believed that he amount o.pdf
The director of special events for Sun City believed that he amount o.pdfThe director of special events for Sun City believed that he amount o.pdf
The director of special events for Sun City believed that he amount o.pdf
 
Write an application containing three parallel arrays that hold 10 e.pdf
Write an application containing three parallel arrays that hold 10 e.pdfWrite an application containing three parallel arrays that hold 10 e.pdf
Write an application containing three parallel arrays that hold 10 e.pdf
 
Which type of project risk is the most relevantStand-alone risk.pdf
Which type of project risk is the most relevantStand-alone risk.pdfWhich type of project risk is the most relevantStand-alone risk.pdf
Which type of project risk is the most relevantStand-alone risk.pdf
 
Which of the following is an advantage businesses have over citizens.pdf
Which of the following is an advantage businesses have over citizens.pdfWhich of the following is an advantage businesses have over citizens.pdf
Which of the following is an advantage businesses have over citizens.pdf
 
what is the pseudoautosomal regionA. the region on the Y chromose.pdf
what is the pseudoautosomal regionA. the region on the Y chromose.pdfwhat is the pseudoautosomal regionA. the region on the Y chromose.pdf
what is the pseudoautosomal regionA. the region on the Y chromose.pdf
 
What is a flat file database How can it be used for forecasting.pdf
What is a flat file database How can it be used for forecasting.pdfWhat is a flat file database How can it be used for forecasting.pdf
What is a flat file database How can it be used for forecasting.pdf
 
What is, in your opinion, the minimum firewall placement for a SCADA.pdf
What is, in your opinion, the minimum firewall placement for a SCADA.pdfWhat is, in your opinion, the minimum firewall placement for a SCADA.pdf
What is, in your opinion, the minimum firewall placement for a SCADA.pdf
 
What factor(s) do not contribute to the development of mutations tha.pdf
What factor(s) do not contribute to the development of mutations tha.pdfWhat factor(s) do not contribute to the development of mutations tha.pdf
What factor(s) do not contribute to the development of mutations tha.pdf
 
Urinary Tract infections commonly caused by E. Coli is a common illn.pdf
Urinary Tract infections commonly caused by E. Coli is a common illn.pdfUrinary Tract infections commonly caused by E. Coli is a common illn.pdf
Urinary Tract infections commonly caused by E. Coli is a common illn.pdf
 
Two samples of sizes 15 and 20 are randomly and independently select.pdf
Two samples of sizes 15 and 20 are randomly and independently select.pdfTwo samples of sizes 15 and 20 are randomly and independently select.pdf
Two samples of sizes 15 and 20 are randomly and independently select.pdf
 
True or False The Coefficient of Determination shows the direction .pdf
True or False The Coefficient of Determination shows the direction .pdfTrue or False The Coefficient of Determination shows the direction .pdf
True or False The Coefficient of Determination shows the direction .pdf
 
Mechanical Engineer    A technology that had being since the last .pdf
Mechanical Engineer    A technology that had being since the last .pdfMechanical Engineer    A technology that had being since the last .pdf
Mechanical Engineer    A technology that had being since the last .pdf
 
The following transactions occurred for London Engineering O (Click .pdf
The following transactions occurred for London Engineering O (Click .pdfThe following transactions occurred for London Engineering O (Click .pdf
The following transactions occurred for London Engineering O (Click .pdf
 
Regulation of prokaryotic gene expression is simpler than that in eu.pdf
Regulation of prokaryotic gene expression is simpler than that in eu.pdfRegulation of prokaryotic gene expression is simpler than that in eu.pdf
Regulation of prokaryotic gene expression is simpler than that in eu.pdf
 
Q4. We used remote port forwarding in this scenario. How does local .pdf
Q4. We used remote port forwarding in this scenario. How does local .pdfQ4. We used remote port forwarding in this scenario. How does local .pdf
Q4. We used remote port forwarding in this scenario. How does local .pdf
 
PYTHON Lottery Number GeneratorQuestion Design a program that ge.pdf
PYTHON Lottery Number GeneratorQuestion Design a program that ge.pdfPYTHON Lottery Number GeneratorQuestion Design a program that ge.pdf
PYTHON Lottery Number GeneratorQuestion Design a program that ge.pdf
 

Recently uploaded

Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajanpragatimahajan3
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxShobhayan Kirtania
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...Pooja Nehwal
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 

Recently uploaded (20)

Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
social pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajansocial pharmacy d-pharm 1st year by Pragati K. Mahajan
social pharmacy d-pharm 1st year by Pragati K. Mahajan
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
The byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptxThe byproduct of sericulture in different industries.pptx
The byproduct of sericulture in different industries.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...Russian Call Girls in Andheri Airport Mumbai WhatsApp  9167673311 💞 Full Nigh...
Russian Call Girls in Andheri Airport Mumbai WhatsApp 9167673311 💞 Full Nigh...
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 

Bank Program in JavaBelow is my code(havent finished, but it be .pdf

  • 1. Bank Program in Java Below is my code(haven't finished, but it be run without error messages.) My problem is in Case 1. For example, if I enter two customers: Name: John Kangas Account Number: A123 Balance: 300 Name: Mary White Account Number: B321 Balance: 600 In the output -- For testing, I expected it to be like this: ***For Testing! John Kangas Balance: 300.0 **** ***For Testing! Mary White Balance: 600.0 **** However, it actually came out like this: ***For Testing! Mary White Balance: 600.0 **** ***For Testing! Mary White Balance: 600.0 **** It seems that the second information replace the first one. Could anyone help me figure it out?? Thank you so much!! ========= Bank Class ========= import java.util.ArrayList; import java.util.Scanner; public class Bank { String routingNum; static Customer customer; static ArrayList customerList = new ArrayList();
  • 2. private static int numOfCustomers = 0; private static double bal; public Bank(){ routingNum = "000000"; } public static void newCustomer(String f, String l, String accNum, double bal){ Account acc = Customer.OpenAccount(accNum,bal); customer = new Customer(f,l,acc); customerList.add(customer); numOfCustomers ++; //For Testing for (int i = 0; i < numOfCustomers; i++ ){ System.out.println(" ***For Testing! "+ customerList.get(i).getName()); System.out.println("Balance: " + customerList.get(i).getAccount().getBalance()); System.out.println("****"); } } public static double findCustomer(String f, String l, String accNum){ //For Testing System.out.println("***For Testing! "+ "numOfCustomers: " + numOfCustomers);
  • 3. for (int i = 0; i < numOfCustomers; i++){ String name = customerList.get(i).getName(); int n = name.indexOf(" "); int L = name.length(); String first = name.substring(0, n); //In order to separate String last = name.substring(n+1, L); //first and last name String accN = customerList.get(i).getAccount().getAccountNum(); //For Testing System.out.println("***For Testing! " + "acc num: " + accN); if ( f.equals(first) && l.equals(last) || accNum.equals(accN) ){ bal = customerList.get(i).getAccount().getBalance(); System.out.print(" Balance: " + bal +" "); }else{ System.out.println("No Found Account."); } } return bal; } public static void main(String[] args){ Scanner s = new Scanner(System.in); boolean control = true; while(control){ System.out.println("Hello! Welcome to New Century Bank!"); System.out.println("Enter('1'): Open an Account");
  • 4. System.out.println("Enter('2'): Get your balance"); System.out.println("Enter('3'): Deposit"); System.out.println("Enter('4'): Withdraw"); System.out.println("Enter('5'): Close an Account"); System.out.println("Enter('6'): Exit"); int user_choice = s.nextInt(); String input1, input2, input3; double input4; switch(user_choice){ case 1: System.out.println("Your name(first last): "); input1 = s.next(); input2 = s.next(); System.out.println("Enter an account number: "); input3 = s.next(); System.out.println("Enter an opening balance: "); input4 = s.nextDouble(); newCustomer(input1, input2, input3, input4); break; case 2: System.out.println("Your name(first last): "); input1 = s.next(); input2 = s.next(); System.out.println("Enter an account number: "); input3 = s.next(); bal = findCustomer(input1, input2, input3); System.out.println(" Your current balance is $" + bal + ". "); break;
  • 5. case 3: System.out.println("Your name(first last): "); input1 = s.next(); input2 = s.next(); System.out.println("Enter an account number: "); input3 = s.next(); System.out.println("Enter a deposit amount: "); input4 = s.nextDouble(); break; case 4: System.out.println("Your name(first last): "); input1 = s.next(); input2 = s.next(); break; case 5: System.out.println("Your name(first last): "); input1 = s.next(); input2 = s.next(); break; case 6: control = false; default: control = false; } } System.out.println("Thank you for using New Century Bank!"); } } ======== Customer
  • 6. ======== public class Customer { static Account account; static String first, last; public Customer(String f, String l, Account acc){ first = f; last = l; account = acc; } public String getName(){ return first + " " + last; } public Account getAccount(){ return account; } public static Account OpenAccount(String accNum, double bal){ account = new Account(accNum, bal); return account; } public void CloseAccount(String f, String l, String accNum, double bal){ f = first; l = last; accNum = account.getAccountNum(); bal = account.getBalance(); }
  • 7. } ====== Account ====== public class Account { String accountNum; double balance, minBalance, overDraftFee; public Account(){ accountNum = "000000"; balance = 0.0; minBalance = 100; overDraftFee = 10; } public Account(String accNum, double bal){ accountNum = accNum; balance = bal; } public String getAccountNum(){ return accountNum; } public double getBalance(){ return balance; } public double getOverDraftFee(){ return overDraftFee; }
  • 8. public double minBalance(){ return minBalance; } public void DepositFunds(Customer customer, double amount){ if (amount < 0){ System.out.println("Deposit amount should not be negative."); }else{ double bal = customer.account.getBalance(); bal += amount; } } public void WithdrawFunds(Customer customer, double amount){ if (amount < 0){ System.out.println("Withdraw amount should not be negative."); }else{ double bal = customer.account.getBalance(); bal -= amount; if (bal < 0){ System.out.println("***Your balance is less then withdraw amount; " + "***Overdraft fee($10) is charged now."); bal -= overDraftFee; } } } public void PrintAccountInfo(Customer customer){ System.out.println("**** Account Information *** "+ "Name: " + customer.getName() + " " + "Current Balance: " + customer.account.getBalance() + " " + "Account Number: " + customer.account.getAccountNum()); } } Solution
  • 9. public class Account { String accountNum; double balance, minBalance, overDraftFee; public Account() { accountNum = "000000"; balance = 0.0; minBalance = 100; overDraftFee = 10; } public Account(String accNum, double bal) { accountNum = accNum; balance = bal; } public String getAccountNum() { return accountNum; } public double getBalance() { return balance; } public double getOverDraftFee() { return overDraftFee; } public double minBalance() { return minBalance; } public void DepositFunds(Customer customer, double amount) { if (amount < 0) { System.out.println("Deposit amount should not be negative."); } else { double bal = customer.account.getBalance(); bal += amount; } } public void WithdrawFunds(Customer customer, double amount) { if (amount < 0) {
  • 10. System.out.println("Withdraw amount should not be negative."); } else { double bal = customer.account.getBalance(); bal -= amount; if (bal < 0) { System.out .println("***Your balance is less then withdraw amount; " + "***Overdraft fee($10) is charged now."); bal -= overDraftFee; } } } public void PrintAccountInfo(Customer customer) { System.out.println("**** Account Information *** " + "Name: " + customer.getName() + " " + "Current Balance: " + customer.account.getBalance() + " " + "Account Number: " + customer.account.getAccountNum()); } } public class Customer { Account account; String first, last; public Customer(String f, String l, Account acc) { first = f; last = l; account = acc; } public String getName() { return first + " " + last; } public Account getAccount() { return account; } public Account OpenAccount(String accNum, double bal) { account = new Account(accNum, bal); return account;
  • 11. } public void CloseAccount(String f, String l, String accNum, double bal) { f = first; l = last; accNum = account.getAccountNum(); bal = account.getBalance(); } } import java.util.ArrayList; import java.util.Scanner; public class Bank { String routingNum; static Customer customer; static ArrayList customerList = new ArrayList(); private static int numOfCustomers = 0; private static double bal; public Bank() { routingNum = "000000"; } public static void newCustomer(String f, String l, String accNum, double bal) { Account acc = new Account(accNum, bal); System.out.println("acc==" + acc.getBalance()); customer = new Customer(f, l, acc); customerList.add(customer); numOfCustomers++; // For Testing for (int i = 0; i < numOfCustomers; i++) { System.out.println(" ***For Testing! " + customerList.get(i).getName()); System.out.println("Balance: " + customerList.get(i).getAccount().getBalance()); System.out.println("****"); } } public static double findCustomer(String f, String l, String accNum) { // For Testing
  • 12. System.out.println("***For Testing! " + "numOfCustomers: " + numOfCustomers); for (int i = 0; i < numOfCustomers; i++) { String name = customerList.get(i).getName(); int n = name.indexOf(" "); int L = name.length(); String first = name.substring(0, n); // In order to separate String last = name.substring(n + 1, L); // first and last name String accN = customerList.get(i).getAccount().getAccountNum(); // For Testing System.out.println("***For Testing! " + "acc num: " + accN); if (f.equals(first) && l.equals(last) || accNum.equals(accN)) { bal = customerList.get(i).getAccount().getBalance(); System.out.print(" Balance: " + bal + " "); } else { System.out.println("No Found Account."); } } return bal; } public static void main(String[] args) { Scanner s = new Scanner(System.in); boolean control = true; while (control) { System.out.println("Hello! Welcome to New Century Bank!"); System.out.println("Enter('1'): Open an Account"); System.out.println("Enter('2'): Get your balance"); System.out.println("Enter('3'): Deposit"); System.out.println("Enter('4'): Withdraw"); System.out.println("Enter('5'): Close an Account"); System.out.println("Enter('6'): Exit"); int user_choice = s.nextInt(); String input1, input2, input3; double input4; switch (user_choice) { case 1:
  • 13. System.out.println("Your name(first last): "); input1 = s.next(); input2 = s.next(); System.out.println("Enter an account number: "); input3 = s.next(); System.out.println("Enter an opening balance: "); input4 = s.nextDouble(); newCustomer(input1, input2, input3, input4); break; case 2: System.out.println("Your name(first last): "); input1 = s.next(); input2 = s.next(); System.out.println("Enter an account number: "); input3 = s.next(); bal = findCustomer(input1, input2, input3); System.out.println(" Your current balance is $" + bal + ". "); break; case 3: System.out.println("Your name(first last): "); input1 = s.next(); input2 = s.next(); System.out.println("Enter an account number: "); input3 = s.next(); System.out.println("Enter a deposit amount: "); input4 = s.nextDouble(); break; case 4: System.out.println("Your name(first last): "); input1 = s.next(); input2 = s.next(); break; case 5: System.out.println("Your name(first last): "); input1 = s.next(); input2 = s.next();
  • 14. break; case 6: control = false; default: control = false; } } System.out.println("Thank you for using New Century Bank!"); } } OUTPUT: Hello! Welcome to New Century Bank! Enter('1'): Open an Account Enter('2'): Get your balance Enter('3'): Deposit Enter('4'): Withdraw Enter('5'): Close an Account Enter('6'): Exit 1 Your name(first last): John Kangas Enter an account number: A123 Enter an opening balance: 300 acc==300.0 ***For Testing! John Kangas Balance: 300.0 **** Hello! Welcome to New Century Bank! Enter('1'): Open an Account Enter('2'): Get your balance Enter('3'): Deposit Enter('4'): Withdraw Enter('5'): Close an Account
  • 15. Enter('6'): Exit 1 Your name(first last): Mary White Enter an account number: B321 Enter an opening balance: 600 acc==600.0 ***For Testing! John Kangas Balance: 300.0 **** ***For Testing! Mary White Balance: 600.0 **** Hello! Welcome to New Century Bank! Enter('1'): Open an Account Enter('2'): Get your balance Enter('3'): Deposit Enter('4'): Withdraw Enter('5'): Close an Account Enter('6'): Exit 6 Thank you for using New Century Bank!