hi danpost and super_Hippo
I know this would sound kinda weird, but this is my second assignment. it supposed toe same way as assignment. I know you have seen it before but bear with me. I have to hand this up on Sunday 18 December. so I am looking for all the help i can get before so it can be fixed.
I would like to know what is the cause for it to be increasing the amount instead of decreasing. what is it in my calculation or method that is causing that error. as I checked for the balance it says 50 but when i make a withdrawal, it says a higher number which is wrong, it supposed to say 25. with every withdrawal it goes up instead of down. here is the codes and the output. can you guys explain what is happening
package Project;
import java.text.DecimalFormat;
import java.util.Scanner;
public class ATM {
DecimalFormat df = new DecimalFormat("#.00");
//this account hold 10 account
Account[] acct = new Account[10];
public static void main(String[] args) {
//create account method
new ATM().createAccount();
}
public void createAccount()
{
Scanner input = new Scanner(System.in);
int i = 0;
final double bal = 50.0;
//creating a new person
Person[] p = new Person[i++];
//acquiring the user information
for(i=0; i<acct.length; i++){
System.out.println("Enter your first name");
String fn = input.next();
System.out.println("Enter your address");
String a = input.next();
System.out.println("Enter your contact");
String c = input.next();
System.out.println("Enter the client number");
int cn = input.nextInt();
//creating a new client each time the program runs
Clients client = new Clients(fn, a, c, cn);
//asking the user to enter the type of account they want to utilize
System.out.println("Welcome to the Account Type:\n ");
System.out.println("Please select from the following menu:\n");
System.out.println("===================================");
System.out.println("| Please select your account type |");
System.out.println("===================================");
System.out.println("| [\n1] Savings Account |");
System.out.println("| [\n2] Checking Account |");
System.out.println("| [\n3] CreditCard Account |");
System.out.println("===================================");
int acctType = input.nextInt();
if(acctType == 1)
{
acct[i] = new SavingsAccount(i, bal, client);
}
else if(acctType == 2)
{
acct[i] = new CheckingAccount(i, bal, client);
}
else if(acctType == 3)
{
acct[i] = new CreditCardAccount(i, bal, client);
}
}
while(true)
{
System.out.println("Enter your account id");
int id = input.nextInt();
//this will let user break out of the loop to end the program
if(id == -1)
{
break;
}
//this loop indicate that the id should be between 1 - 9
while(id < 0 || id > 9)
{
//indicating to the user that the id enter is wrong and to try again
System.out.println("ID is incorect, try again");
id = input.nextInt();
}
while(true)
{
showMenu();
if(!useMenu(acct[id],input))
{
System.out.println();
break;
}
System.out.println("\n");
}
}
}
public boolean useMenu(Account acct, Scanner input)
{
int userchoice = input.nextInt();
//everytime it runs it shall be false until it is true
double amt;
if(userchoice == 5)
{
return false;
}
else if(userchoice == 1)
{
//user checking their balances
System.out.println("The account balance is: "+ acct.getbalance());
return true;
}
else if(userchoice == 2)
{
//asking the user what amount to be withdrawn
System.out.println("Enter the amount to withdraw");
amt =input.nextDouble();//hold the amt to be withdrawn
if(amt > acct.getbalance())//indicating if the amt withdrawn is over the limit
{
//indicating that there is not enough funds in the account
System.out.println("Insufficient funds " + "Balance is "+acct.getbalance());
}
else
{
//letting the user know that thre is enough in the account
acct.withdraw(amt);
//balance is printed out after transaction
System.out.println("Balance is: "+ acct.getbalance());
}
}
else if(userchoice == 3)
{
//user is asked to enter the amount to be deposited
System.out.println("Enter the amount to deposit");
acct.deposit(input.nextDouble());//hold the amt deposited
System.out.println("Balance is "+ acct.getbalance());//gathering the balance after the transactions
return true;
}
else if(userchoice == 4)
{
//gathering the user information
System.out.println(acct.getClient().toString());
}
else
{
//this indicated that the user enter a choice that is not there.
System.out.println("invalid choice");
}
return true;
}
public static void showMenu()
{
//displaying the menu where the user has to choose from
System.out.println("Welcome to the Automated Teller Machine!\n");
System.out.println("Select from the following menu options below:\n");
System.out.println("===================================");
System.out.println("| Main Menu |");
System.out.println("===================================");
System.out.println("| [1] Check Balance |");
System.out.println("| [2] Withdraw |");
System.out.println("| [3] Deposit |");
System.out.println("| [4] Display owner's Details |");
System.out.println("| [5] Exist |");
System.out.println("Please select your choice now!! |");
System.out.println("====================================");
}
}
this is the output
Main Menu |
===================================
| [1] Check Balance |
| [2] Withdraw |
| [3] Deposit |
| [4] Display owner's Details |
| [5] Exist |
Please select your choice now!! |
====================================
1
The account balance is: 50.0
Welcome to the Automated Teller Machine!
Select from the following menu options below:
===================================
| Main Menu |
===================================
| [1] Check Balance |
| [2] Withdraw |
| [3] Deposit |
| [4] Display owner's Details |
| [5] Exist |
Please select your choice now!! |
====================================
2
Enter the amount to withdraw
30
Balance is: 16.775
Welcome to the Automated Teller Machine!
Select from the following menu options below:
===================================
| Main Menu |
===================================
| [1] Check Balance |
| [2] Withdraw |
| [3] Deposit |
| [4] Display owner's Details |
| [5] Exist |
Please select your choice now!! |
====================================
4
name wilma
address carenage
contact 4410020
Person null
Client Number 489
Welcome to the Automated Teller Machine!
Select from the following menu options below:
===================================
| Main Menu |
===================================
| [1] Check Balance |
| [2] Withdraw |
| [3] Deposit |
| [4] Display owner's Details |
| [5] Exist |
Please select your choice now!! |
====================================
5
Enter your account id
-1
BUILD SUCCESSFUL (total time: 6 minutes 5 seconds)

