I wonder if someone can help me with a simple ATM machine
that can deposit, withdrawl an show the 10 latest transactions in an array of 10 index values.
The problem is that i can't see the transactions after the 10:th.
the program don't take the amount or don't display the transactions after the 10:th operation.
Could someone help me with this.
I have written a code and i don't know wath wrong i doo in the soure code.
Here is the source code:
import java.util.Scanner;
public class BankoMat
{
public static void main(String[] args)
{
Scanner keyboard = new Scanner(System.in);
int amount = 0;
int choice = 0;
int [] transactions = new int[10];
int sum;
int balance = 0;
while (choice != 4)
{
choice = menu();
switch(choice)
{
case 1:
System.out.print("Enter amount to deposit? :");
sum = keyboard.nextInt();
if(sum == 0)
{
System.out.print("Wrong amount.");
System.out.println();
System.out.println();
}
else
{
amount = (int) + sum;
makeTransactions(amount, transactions);
}
break;
case 2:
System.out.print("Hoe much do you want to withdrawl?: ");
sum = keyboard.nextInt();
if(sum == 0)
{
System.out.print("Wrong amount.");
System.out.println();
System.out.println();
}
else
{
amount = (int) - sum;
makeTransactions(amount, transactions);
}
break;
case 3:
showTransactions(transactions, balance);
break;
case 4:
System.out.println("You chosed to end ");
break;
}
}
}
public static int menu()
{
Scanner keyboard = new Scanner(System.in);
int choice = 0;
System.out.println("Simple ATM");
System.out.println();
System.out.println("1. Deposit ");
System.out.println("2. Withdrawl ");
System.out.println("3. transactions ");
System.out.println("4. End ");
System.out.println();
System.out.println("Your choice ");
choice = keyboard.nextInt();
return choice;
}
public static void showTransactions(int [] transactions, int balance)
{
System.out.println();
System.out.println("Last transactions");
System.out.println();
for(int i = 0; i < transactions.length-1; i++)
{
if(transactions[i] == 0)
{
System.out.print("");
}
else
{
System.out.print(transactions[i] + "\n");
balance = balance + transactions[i];
}
}
System.out.println();
System.out.println("Balance: " + balance + " kr" + "\n" );
System.out.println();
}
public static void makeTransactions(int amount, int [] transactions)
{
int position = findNr(transactions);
if(position == -1)
{
moveTrans(transactions);
position = findNr(transactions);
transactions[position] = amount;
}
else
{
transactions[position] = amount;
}
}
public static int findNr(int [] transactions)
{
int position = -1;
for(int i = 0; i < transactions.length-1; i++)
{
if(transactions[i] == 0)
{
position = i;
break;
}
}
return position;
}
public static void moveTrans(int [] transactions)
{
for(int i = 0; i < transactions.length-1; i++)
transactions[0] = transactions[i + 1] ;
}
}
This post has been edited by baavgai: 07 December 2010 - 01:54 PM
Reason for edit:: tagged

New Topic/Question
Reply



MultiQuote








|