1.

Solve : Java Banking Application Help Required?

Answer»

Hi, could someone please help me with my java code here is what i have so far but I'm getting compiling errors. It is an application to create a bank customer, set their initial deposit. It also needs to be able to withdraw only if funds permit. It also needs to be able to CALCULATE bank fees after the first initial transaction which is free. As well as do balance enquires I thought maybe storing customerName, balance, openingDate, accountNumber inside a VARIABLE but i have no idea how to do that yet. I'm new to java and programming in general maybe someone could help me out please? The main error I'm getting is "non-static variable this cannot be referenced from a static context" on lines 121-122-249-250

Code: [Select]/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package section3banking;


import java.util.Scanner;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class S3Banking {

public static void main(String[] args) throws IOException {

BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
int numberOfCustomers = 0;
Bank bank = new Bank();
String acc = null;
Customer[] c = bank.getCustomer();
while (true) {
System.out.println("****************************");
System.out.println("* Franks Bank *");
System.out.println("****************************");
System.out.println("* *");
System.err.println("* Please Enter Your Choice *");
System.out.println("* 1) Add Customer *");
System.out.println("* 2) Deposit Money *");
System.out.println("* 3) Withdraw Money *");
System.out.println("* 4) Check Balance *");
System.out.println("* 5) Calculate Interest *");
System.out.println("* 6) Exit *");
System.out.println("* *");
System.out.println("****************************");
int choice = Integer.parseInt(bufferedReader.readLine());
switch (choice) {
case 1:
System.err.println("\tEnter New Customers Name");
String name = bufferedReader.readLine();
System.err.println("\tEnter Opening Deposit Balance");
double bal = Double.parseDouble(bufferedReader.readLine());
System.out.println("\n");
Account account = new Account(bal, acc);
Customer customer = new Customer(name, account);
c[numberOfCustomers] = customer;

numberOfCustomers++;
System.out.println("<----------------------------------------->");
System.err.println(". Customer Account Created Successfully .");
System.out.println("...........................................");
System.out.println(". Opening Date : ");
if (numberOfCustomers == 0) {
System.err.println("Account Number Not Found");
System.out.println("\n");
} else {
boolean found = false;
for (int i = 0; i < numberOfCustomers; i++) {
Account temp = c[i].getAccount();
String accTemp = temp.getAccountNumber();
if (accTemp.equals(acc)) {
System.err.println("Enter Deposit Amount");
double money = Double.parseDouble(bufferedReader.readLine());
temp.deposit(money);
found = true;
break;
}
}
if (found == false) {
System.out.println("Account Number Not Found");
System.out.println("\n");
}
}
break;
case 3:
System.err.println("Enter Account Number");
acc = bufferedReader.readLine();
if (numberOfCustomers == 0) {
System.err.println("Account Number Not Found");
System.out.println("\n");
} else {
boolean found = false;
for (int i = 0; i < numberOfCustomers; i++) {
Account temp = c[i].getAccount();
String accTemp = temp.getAccountNumber();
if (accTemp.equals(acc)) {
System.err.println("Enter Amount To Withdraw");
double money = Double.parseDouble(bufferedReader.readLine());
temp.withdraw(money);
found = true;
}
}
if (found == false) {
System.out.println("Account Number Not Found");
System.out.println("\n");
}
}
break;
case 4:
System.err.println("Enter Account Number");
acc = bufferedReader.readLine();
if (numberOfCustomers == 0) {
System.err.println("Account Number Not Found");
System.out.println("\n");
} else {
boolean found = false;
for (int i = 0; i < numberOfCustomers; i++) {
Account temp = c[i].getAccount();
String accTemp = temp.getAccountNumber();
if (accTemp.equals(acc)) {
System.out.println("Balance is " + temp.getBalance());
found = true;
}
}
if (found == false) {
System.err.println("Account Number Not Found");
System.out.println("\n");
}
}
break;
case 5:
break;
case 6:
System.exit(0);
break;
default:
break;
}
}

}class Bank {

private double interestRateSavings = 2.5;
private double interestRateNegative = 12.75;
private double interestRatePositive = 0.5;
private double transactionFees = 1.00;
private Customer[] customers = new Customer[99999];

public void calculateInterest(Customer customer) {
Account a = customer.getAccount();
double bal = a.getBalance();
double interestAmount = bal * interestRatePositive / 100;
double totalBalance = bal + interestAmount;

}
String setDateTime() {
Date date = Calendar.getInstance().getTime();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
RETURN sdf.format(date);
}

public double getInterestRate() {
return interestRatePositive;
}

public double getTransactionFees() {
return transactionFees;
}

public Customer[] getCustomer() {
return customers;
}

}

class Account {

private double balance = 0.00;
private final String accountNumber;
private boolean firstTime = true;

public static Account(String acc) {
accountNumber = acc;
}

public Account(double bal, String acc) {
if (bal >= 0.00) {
balance = bal;
} else {
balance = 0.00;
}
accountNumber = acc;
}

public void deposit(double howMuch) {
if (howMuch > 0.00) {
balance = balance + howMuch;
System.out.println("\n");
System.out.println("New Balance:");
System.err.println(balance);
System.out.println("\n");
} else {
System.out.println("\n");
System.err.println("Incorrect Amount Entered");
System.out.println("\n");
}
}

public void withdraw(double howMuch) {
if (howMuch > 0.00) {
if (firstTime == true) {
double tempBalance = balance;
tempBalance = tempBalance - howMuch;
if (tempBalance >= 2.00) {
balance = balance - howMuch;
System.out.println("You Successfully Withdrawed " + howMuch);
System.err.println("Your New Current Balance is " + balance);
System.out.println("\n");
} else {
System.err.println("Insufficient Funds to withdraw " + howMuch);
System.out.println("\n");
}
firstTime = false;
} else {
Bank bank = new Bank();
double tempBalance = balance;
tempBalance = tempBalance - howMuch - bank.getTransactionFees();
if (tempBalance > 2.00) {
balance = balance - bank.getTransactionFees() - howMuch;
System.err.println("Withdraw " + howMuch + " from account " + accountNumber + "");
System.out.println("The transaction fee " + bank.getTransactionFees());
System.out.println("New Balance : " + tempBalance);
} else {
System.err.println("Insufficient Funds to withdraw" + howMuch);
System.out.println("\n");
}
}
} else {
System.err.println("Incorrect Amount Entered");
System.out.println("\n");
}
}

public double getBalance() {
return balance;
}

public String getAccountNumber() {
return accountNumber;
}
}

class Customer {

String date;
String name;
private final Account account;

Customer(String n, Account a) {
name = n;
account = a;
}

public void display() {
System.out.println("Name: " + name + ",Account Number: " + account.getAccountNumber());
}

public String getName() {
return name;
}

public Account getAccount() {
return account;
}

public String getOpeningDate() {
return date;
}

}
}
So you work for a bank, they need to you create a simple routine what's normally already usually created by a 3rd party company, and you don't know the language that the programming is in?

I have a friend who works for a bank and at least banks within the USA don't allow any information LIKE this to be shared outside of the bank. Additionally, they use a extremely secure system that was created by a 3rd party company outside of the bank that is liable for flaws in their programming, so its very well tested and penetration tested.

I would almost hope that this was homework and not an actual bank that needed to ACCOMPLISH this code goal to get this working. I do however like the 2.5% interest for savings private double interestRateSavings = 2.5; which is very generous compared to the less than 1% that I get on my savings.



Sounds like homework to me....Bank, Account, and Customer are nested classes of S3Banking. This means that in order to create instances of them you need an instance of S3Banking.

You can either split Bank, Account, and Customer into their own separate source files, or you can make the nested classes static. (You've also declared the Account constructor as "static" which isn't a valid modifier)



Discussion

No Comment Found