Sie sind auf Seite 1von 5

import java.util.

Scanner; public class ATM{ public static void main(String[] args){ //define scanner Scanner input = new Scanner(System.in); //call on menu method int choice; choice = getMenuOption(); while (choice != 4) { if (choice == 1) checkBalance(); else if (choice == 2) withdrawal(); else if (choice == 3) deposite(); choice = getMenuOption();} } //main menu method public static int getMenuOption() { System.out.println("Welcome!"); System.out.println("1: Check Balance"); System.out.println("2: Make a withdrawal"); System.out.println("3: Make a Deposite"); System.out.println("4 - Quit"); //ask user what they want to do System.out.print("Please choose an option 1-4"); Scanner reader = new Scanner(System.in); int x = reader.nextInt(); return x; } //create ten different accounts, ??each with a different password?? and each with $100.

public static double[] account(double[] accounts){ accounts = new double[10]; for(int i =0; i < accounts.length; i++){ accounts[i] = 100.00;} return accounts; } //check balance method public static double checkBalance(double b){ b = account(accounts[i]); System.out.print("Your account balance is $" + b + "."); } //make withdrawal method public static double withdrawal(double n){ Scanner withdraw = new Scanner(System.in); System.out.print("How much would you like to withdraw from your account?"); n = withdraw.nextDouble(); account[]= account[] - n; return account[]; } //make deposite method public static double deposite(double p){ Scanner deposite = new Scanner(System.in); System.out.print("How much would you like to deposite into your account?"); p = deposite.nextDouble(); account[] = account[] + p; return account[]; } }

Part 2

class Account { private String name; private int id; private String password; private double balance; private boolean isActive; // constructor public Account( String n, int i ) { name = n; id = i; balance = 100.0; isActive = false; } // methods protected void setPassword( String input ) { password = input; } protected String getPassword( ) { return password; } protected boolean checkPassword( input ) { if( input.equalsIgnoreCase( input ) { isActive = true; } else { System.out.println("Incorrect, try again"); isActive = false; } return isActive; } public boolean isActive() { return isActive; } protected double getBalance() { return balance; } protected void setBalance( double transaction ) {

balance += transaction; } protected void withdrawal( double transaction ) { if( balance > transaction ) balance -= transaction else System.out.println("Sorry, insufficient funds"); } protected String getBalance() { return String.format("$4.2f", balance ); } protected int getID() { return id; } protected void setActive() { isActive = true; } } // >====================/ then, I would do the ATM class with the main() class ATM { Account[] accounts = new Account[10]; // add a constructor, we want to get rid of static, static, static public ATM() { intro(); } public static void main(String[] args ) { new ATM(); } private void intro() { Scanner sc = new Scanner(); do{ // welcome() // menu() // make account( sc ) ... } while ( !sc.nextLine().equalsIgnoreCase("4") ); } private void makeAccount( Scanner sc ) { int acctsOnRecord = 0;

for(int i = 0; i<accounts.length; i++) { if( accounts[i] == null && i < 10 ) { acctsOnRecord = i; System.out.print("What is ur name? ==> ") accounts[ acctsOnRecord ] = new Account( sc.nextLine(), acctsOnRecord); System.out.print("Please enter a password: ==> "); String pword = sc.nextLine(); System.out.print("Please re-enter your password: ==> " ); if( pword.equalsIgnoreCase( sc.nextLine() ) account[ acctsOnRecord ].setPassword( pword ); account[ acctsOnRecord ].setActive(); } else System.out.println("We're sorry, but we are not taking any new accounts at the present time."); } ... } private Account getAcctByName( String inputName ) { for( int i = 0; i<accounts.length; i++) { if( accounts[i].getName().equalsIgnoreCase( inputName) return accounts[i]; return null; }

Das könnte Ihnen auch gefallen