Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package test;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class thisClass {
- public static void main(String[] args){
- Scanner in = new Scanner (System.in);
- ArrayList<User> users = new ArrayList<>();
- User usr1 = new User(1,"Mark21","password1","mpereira@example.com","21/09/1998");
- users.add(usr1);
- User usr2 = new User(2,"Cristi01","password2","cAnastasiu@example.com","01/01/1998");
- users.add(usr2);
- int a = 1;
- while (a==1){
- System.out.println("\n\nTest Program to create a new User:");
- System.out.println("[1]Show list of Registered Usernames.");
- System.out.println("[2]Show list of Registered Emails.\n\n");
- System.out.println("[3]Test new username.");
- System.out.println("[4]Test new email.");
- System.out.println("[5]Test password validation.");
- String input = in.next();
- if (input.equals("1")){
- //Show all usernames
- for (User eachUser : users){
- System.out.println(eachUser.getName());
- }
- }
- if (input.equals("2")){
- //Show all emails
- for (User eachUser : users){
- System.out.println(eachUser.getEmail());
- }
- }
- if (input.equals("3")){
- //Input a username, and check if its in the list of recorded usernames
- //If its not, the test is successful
- System.out.println("Input a new username:");
- input = in.next();
- System.out.println(input);
- boolean isValid = false;
- for (User eachUser : users){
- if (input.equals(eachUser.getName())){
- isValid = true;
- System.out.println("This is not a valid username.");
- }
- }
- if (isValid == false){
- System.out.println("This is a valid username.");
- }
- }
- if (input.equals("4")){
- //Input a email, and check if its in the list of recorded emails
- //If its not, the test is successful
- //Never mind the email format (the @ and .com) just explain it in the presentation
- System.out.println("Input a new email:");
- input = in.next();
- boolean isValid = false;
- for (User eachUser : users){
- if (input.equals(eachUser.getEmail())){
- isValid = true;
- System.out.println("This is not a valid email.");
- }
- }
- if (isValid == false){
- System.out.println("This is a valid email.");
- }
- }
- if (input.equals("5")){
- System.out.println("Enter a password:");
- String input1 = in.next();
- System.out.println("Confirm password:");
- String input2 = in.next();
- if (input1.equals(input2)){
- System.out.println("This is a valid password.");
- }else{
- System.out.println("Invalid, ensure both inputs are equal.");
- }
- }
- }
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement