Advertisement
charudwivedi

dwivedi

Mar 3rd, 2017
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.71 KB | None | 0 0
  1. package assignments;
  2.  
  3. import java.util.Scanner;
  4.  
  5. class dwivedi {
  6.  
  7. public static void main(String[] args) {
  8. // TODO Auto-generated method stub
  9. System.out.println("-----------Welcome to the Webshop-----------");
  10.  
  11.  
  12. //Asking for Input
  13. Scanner input=new Scanner(System.in);
  14. System.out.print("Enter you Name and Surname with a space");
  15. String S= input.next();
  16. String P=input.next();
  17.  
  18. //DOB
  19. Scanner input2 = new Scanner(System.in);
  20. System.out.print("Date of Birth in DD/MM/YY");
  21. String DOB= input2.nextLine();
  22. String datafromDOB=DOB.substring(0,2).concat(DOB.substring(3,5)).concat(DOB.substring(6,8));//adding the DOB digits
  23.  
  24. //CPR
  25. Scanner input4=new Scanner(System.in);
  26. System.out.print("CPR number in XXXXXX-XXXX");
  27. String CPR= input4.nextLine();
  28. int x= CPR.length();
  29. char n= CPR.charAt(6);
  30. String extractforcheck=CPR.substring(0,6);
  31.  
  32.  
  33.  
  34. if(extractforcheck.equals(datafromDOB)){ //checking if DOB digits are in CPR
  35. while ((x!=11)||(n!='-')) {
  36. System.out.println("Enter proper CPR");
  37. CPR= input4.nextLine();
  38. x= CPR.length();
  39. n= CPR.charAt(6);
  40. extractforcheck=CPR.substring(0,6);
  41. }
  42. }
  43. //Zipcode
  44. Scanner input1 =new Scanner(System.in);
  45. System.out.print("Enter your Zipcode");
  46. String Zipcode= input1.nextLine();
  47. int Zipcode1 = Integer.parseInt(Zipcode);
  48. while ( Zipcode1 > 2500){ //chcking for pincode in copenhagen
  49. System.out.println("Enter a code in Copenhagen");
  50. Zipcode= input1.nextLine();
  51. Zipcode1 = Integer.parseInt(Zipcode);
  52. };
  53.  
  54. //telephone
  55. Scanner input3=new Scanner(System.in);
  56. System.out.print("Enter you telepnone number");
  57. String tele= input3.nextLine();
  58. while((tele.length())!= 8) {
  59. System.out.print("Please enter 8 digits");
  60. tele= input3.nextLine();}
  61.  
  62.  
  63. //Creating username
  64. char user = S.charAt(0);
  65. String namepart=P.substring(0, 3);
  66. String un= user + namepart;
  67. System.out.println("Username is:" + un);
  68.  
  69. //creating password
  70. String ps=P.substring(0,3);
  71. String q= CPR.substring(7,10);
  72. String pw= ps.concat(q);
  73. System.out.println("passowrd is: " +pw);
  74.  
  75. //asking to login // use do while loop
  76. int attempt=0;
  77. System.out.println("you can now login or exit");
  78. Scanner input8= new Scanner(System.in);
  79. System.out.println("enter yes if you want to login");
  80. System.out.println("enter no if you want to exit");
  81. String answer= input8.nextLine();
  82.  
  83. switch (answer){
  84. case "no" : System.out.println("you decided not to login");System.exit(0);
  85. case "yes":
  86.  
  87. System.out.println("Enter your username and password ");
  88. Scanner input10= new Scanner(System.in);
  89. Scanner input11=new Scanner(System.in);
  90. String username=input10.nextLine();
  91. String password=input11.nextLine();
  92.  
  93. if (username.equals(un) && password.equals(pw)) {
  94. System.out.println("your enteries are correct"); System.exit(0);}
  95.  
  96. while(((username!=un)||(password!=pw)) && (attempt<3))
  97. {
  98. System.out.println("Re-enter username and password.");
  99. input10= new Scanner(System.in);
  100. username=input10.nextLine();
  101. input11=new Scanner(System.in);
  102. password=input11.nextLine();
  103. if (username.equals(un) && password.equals(pw)) {
  104. System.out.println("It took time but you got it right");System.exit(0);}
  105. attempt++;
  106. }
  107.  
  108. System.out.print("--------You have exceeded the number of tries-------"); System.exit(0);
  109.  
  110.  
  111.  
  112. System.out.println("Your enteries are correct"); System.exit(0);
  113.  
  114. Default : System.out.println("Invalid input");System.exit(0);
  115. }
  116.  
  117. }
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement