Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Assignments;
- import java.util.Scanner;
- public class Shern {
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- // Welcome Logo
- System.out.println("\n");
- System.out.println(" *** C B S W E B S H O P *** \n\n");
- System.out.println("Create User");
- System.out.print("\n\n");
- //FIRSTNAME
- System.out.print("First Name: \t");
- String firstname = input.nextLine();
- //LASTNAME
- System.out.print("Last Name: \t");
- String lastname = input.nextLine();
- //ADDRESS
- System.out.print("Street name: \t");
- String sn = input.nextLine();
- System.out.print("Street number (and block or floor if relevant) \t");
- String st = input.nextLine();
- //POSTAL CODE
- System.out.print("Postal Code: \t");
- int PC = input.nextInt();
- while (PC < 1000 || PC > 2991 ) {
- System.out.print("Postal code not found in Copenhagen region. Please try again ");
- PC = input.nextInt();
- }
- //PHONE NUMBER
- System.out.print("Phone Number: \t");
- //I Insert the following code of line due to issues with next line addressed here http://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-nextint-or-other-nextfoo
- String test = input.nextLine();
- String number = input.nextLine();
- while (number.length() != 8) {
- System.out.print("Telephone number should be 8 digits. Please try again ");
- number = input.nextLine();
- }
- //CPR NUMBER
- System.out.print("CPR-Number: \t");
- String cpr = input.nextLine();
- char dash = cpr.charAt(6);
- while (cpr.length() != 11 && dash !='-') {
- System.out.print("Error, use format XXXXXX-XXXX, please try again ");
- cpr = input.nextLine();
- }
- System.out.println("\n\nUser creation complete!\n");
- //USERNAME
- String s1 = firstname.substring(0,1);
- String s2 = lastname.substring(0,3);
- String username = s1 + s2;
- System.out.println("Your username is: " + username);
- //PASSWORD
- String s3 = lastname.substring(0,3);
- String s4 = cpr.substring(7, 11);
- String password = s3 + s4;
- System.out.println("Your password is: " + password);
- System.out.println("\n");
- //LOG-IN PROMPT
- System.out.println("To EXIT, please type 1 and enter \n");
- System.out.println("To LOG-IN, please type 2 and enter \n");
- String command = input.nextLine();
- System.out.println("\n");
- switch (command) {
- case "1": System.out.print("You have now exited. Goodbye!"); break;
- case "2": System.out.println("Please enter username below \n");
- }
- // LOG-IN
- {
- System.out.println("Enter Username");
- String loginusername = input.nextLine();
- while (!loginusername.equals(username))
- {
- System.out.println("Username not found, try again");
- loginusername = input.next();
- }
- System.out.println("Enter Password");
- String userpassword = input.nextLine();
- int count = 3;
- while (!userpassword.equals(password)) {
- count--;
- System.out.println("Wrong Password, you have " + count + " attempts left");
- if (count==0) {
- System.out.print("Sorry you have exceeded the number of tries. Please try again after few hours");
- System.exit(0);
- }
- userpassword = input.next();
- }
- }
- System.out.println("You are now logged in!");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement