Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- class Customer
- {
- public int balance;
- public String username;
- public int pinNumber;
- Customer()
- {
- }
- Customer(int b, String uName, int pin)
- {
- b = balance;
- username = uName;
- pinNumber = pin;
- }
- }
- class Main
- {
- public static void main(String[] args)
- {
- Scanner s = new Scanner(System.in);
- int loggedIn = 0;
- Customer loggedInCustomer = new Customer();
- Customer[] customers = new Customer[5];
- customers[0] = new Customer(1000, "Mike", 1234);
- customers[1] = new Customer(80000, "Mashraful", 1234);
- customers[2] = new Customer();
- customers[3] = new Customer();
- customers[4] = new Customer();
- System.out.println("Please enter your username.");
- //String input = s.nextLine();
- while(loggedIn == 0)
- {
- String input = s.nextLine();
- int pin_input = 0;
- int i;
- for(i = 0; i < 4; i++)
- {
- if(input.equals(customers[i].username))
- {
- System.out.println("Username found. Please enter your PIN.");
- pin_input = s.nextInt();
- if(pin_input == customers[i].pinNumber)
- {
- System.out.println("Successfully logged in.");
- loggedInCustomer = customers[i];
- loggedIn = 1;
- ///break;
- }
- }
- }
- if(!input.equals(customers[i].username) && loggedIn == 0)
- {
- System.out.println("Incorrect username. Please try again.");
- break;
- }
- if(pin_input != customers[i].pinNumber && loggedIn == 0)
- {
- System.out.println("Incorrect pin. Login attempt has been reset.");
- break;
- }
- }
- if(loggedIn == 1)
- {
- System.out.println("Welcome " + loggedInCustomer.username + ". Your balance is: " + loggedInCustomer.balance);
- String input = s.nextLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement