Ok I'm new to Java so this question might be boring to most of you...but I'm stuck. I know the code may not look great so please don't shoot me down, I'm trying! The code is not yet finished obviously but I cannot select int 1 or 2 in the menu list. It just takes any integer and displays integers 1 and 2 together. I'm not sure if it's my If statement or the kind of input that I'm using...any help would be much appreciated. The Pin number loop works fine.
import java.util.Scanner;
public class AtmMachine {
double balance = 1000;
int checkBalance = 1;
int withdrawCash = 2;
int returnCard = 3;
int cashTen = 10;
int cashTwenty = 20;
int cashFifty = 50;
public static void main(String[] args) {
System.out.println("Welcome To UK Bank Services");
//entering pin number//
Scanner keyboard = new Scanner(System.in);
int pin = 12345;
System.out.println("Please Enter Your Pin:");
int entry = keyboard.nextInt();
//while loop to check if pin is correct//
while (entry != pin) {
System.out.println("Incorrect pin, please try again");
System.out.print("ENTER CORRECT PIN: ");
entry = keyboard.nextInt();
}
if (entry == pin)
System.out.println("Welcome, please make your selection");
}
//Using the main menu to make a selection//
public void choices () {
Scanner keyboard = new Scanner(System.in);
System.out.println("Please Make A Selection");
System.out.println("[1] = Check Balance");
System.out.println("[2] = Withdraw Cash");
System.out.println("[3] = Return Card");
int entry = keyboard.nextInt();
if (checkBalance == 1) {
System.out.println("Your Current Balance Is:£" + balance);
}
else if(withdrawCash == 2) {
System.out.println("Please Choose Cash Amount:" +"\n" +cashTen +"\n" +cashTwenty + "\n" +cashFifty);
}
else {
System.out.println("Goodbye");
}
}
}
Aucun commentaire:
Enregistrer un commentaire