Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package assignments;
- import java.util.Scanner;
- class dwivedi {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- System.out.println("-----------Welcome to the Webshop-----------");
- //Asking for Input
- Scanner input=new Scanner(System.in);
- System.out.print("Enter you Name and Surname with a space");
- String S= input.next();
- String P=input.next();
- //DOB
- Scanner input2 = new Scanner(System.in);
- System.out.print("Date of Birth in DD/MM/YY");
- String DOB= input2.nextLine();
- String datafromDOB=DOB.substring(0,2).concat(DOB.substring(3,5)).concat(DOB.substring(6,8));//adding the DOB digits
- //CPR
- Scanner input4=new Scanner(System.in);
- System.out.print("CPR number in XXXXXX-XXXX");
- String CPR= input4.nextLine();
- int x= CPR.length();
- char n= CPR.charAt(6);
- String extractforcheck=CPR.substring(0,6);
- if(extractforcheck.equals(datafromDOB)){ //checking if DOB digits are in CPR
- while ((x!=11)||(n!='-')) {
- System.out.println("Enter proper CPR");
- CPR= input4.nextLine();
- x= CPR.length();
- n= CPR.charAt(6);
- extractforcheck=CPR.substring(0,6);
- }
- }
- //Zipcode
- Scanner input1 =new Scanner(System.in);
- System.out.print("Enter your Zipcode");
- String Zipcode= input1.nextLine();
- int Zipcode1 = Integer.parseInt(Zipcode);
- while ( Zipcode1 > 2500){ //chcking for pincode in copenhagen
- System.out.println("Enter a code in Copenhagen");
- Zipcode= input1.nextLine();
- Zipcode1 = Integer.parseInt(Zipcode);
- };
- //telephone
- Scanner input3=new Scanner(System.in);
- System.out.print("Enter you telepnone number");
- String tele= input3.nextLine();
- while((tele.length())!= 8) {
- System.out.print("Please enter 8 digits");
- tele= input3.nextLine();}
- //Creating username
- char user = S.charAt(0);
- String namepart=P.substring(0, 3);
- String un= user + namepart;
- System.out.println("Username is:" + un);
- //creating password
- String ps=P.substring(0,3);
- String q= CPR.substring(7,10);
- String pw= ps.concat(q);
- System.out.println("passowrd is: " +pw);
- //asking to login // use do while loop
- int attempt=0;
- System.out.println("you can now login or exit");
- Scanner input8= new Scanner(System.in);
- System.out.println("enter yes if you want to login");
- System.out.println("enter no if you want to exit");
- String answer= input8.nextLine();
- switch (answer){
- case "no" : System.out.println("you decided not to login");System.exit(0);
- case "yes":
- System.out.println("Enter your username and password ");
- Scanner input10= new Scanner(System.in);
- Scanner input11=new Scanner(System.in);
- String username=input10.nextLine();
- String password=input11.nextLine();
- if (username.equals(un) && password.equals(pw)) {
- System.out.println("your enteries are correct"); System.exit(0);}
- while(((username!=un)||(password!=pw)) && (attempt<3))
- {
- System.out.println("Re-enter username and password.");
- input10= new Scanner(System.in);
- username=input10.nextLine();
- input11=new Scanner(System.in);
- password=input11.nextLine();
- if (username.equals(un) && password.equals(pw)) {
- System.out.println("It took time but you got it right");System.exit(0);}
- attempt++;
- }
- System.out.print("--------You have exceeded the number of tries-------"); System.exit(0);
- System.out.println("Your enteries are correct"); System.exit(0);
- Default : System.out.println("Invalid input");System.exit(0);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement