Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.Random;
- public class SkillsDemo3 {
- boolean again = true;
- int action;
- public static void main(String[] args) throws IOException {
- //***************************
- //Login
- //***************************
- class User {
- User (String username, String password)
- {
- this.username = username;
- this.password = password;
- }
- String GetUsername() {return username;}
- String GetPassword() {return password;}
- private String username;
- private String password;
- }
- String greeting = "Hello";
- String username;
- String password;
- // Used to hold the instance of a user who successfully logged in
- User loggedInUser = null;
- // Create an empty list to hold users
- List<User> listOfUsers = new ArrayList<>();
- // Add 3 users to the list
- listOfUsers.add(new User("Gerry","spintown"));
- listOfUsers.add(new User("Evelyn","poker"));
- listOfUsers.add(new User("Joan","bonus"));
- BufferedReader br = new BufferedReader(
- new InputStreamReader(System.in));
- System.out.println("*** Welcome to the program ***n");
- System.out.println(greeting);
- System.out.println("Please type your username :");
- username = br.readLine();
- System.out.println("Please type your password :");
- password = br.readLine();
- for (User user : listOfUsers)
- {
- if (user.GetUsername().equals(username))
- {
- if (user.GetPassword().equals(password))
- {
- loggedInUser = user;
- // when a user is found, "break" stops iterating through the list
- break;
- }
- }
- }
- // if loggedInUser was changed from null, it was successful
- if (loggedInUser != null)
- {
- System.out.println("User successfully logged in: "+loggedInUser.GetUsername());
- }
- else
- {
- System.out.println("Invalid username/password combination");
- }
- //**********************************
- //Choice of Games
- //**********************************
- boolean again = true;
- int action = 0;
- if (action == 1)
- {
- System.out.println("nYou have chosen to play Rock, Paper, Scissors");
- }
- else if (action == 2)
- {
- System.out.println("nYou have chosen to Play pick up sticks");
- again = false;
- }
- SkillsDemo3 what = new SkillsDemo3();
- while (what.again)
- {
- System.out.println("Please type 0 to continue or 1 to stop :");
- what.action = Integer.parseInt(br.readLine());
- System.out.println("You typed : "+what.action);
- what.SkillsDemo3();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement