Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.00 KB | None | 0 0
  1. package as2_view;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.Date;
  5. import java.util.Scanner;
  6. import Members.*;
  7.  
  8. public class View {
  9.  
  10.  
  11. static void register(HealthAppController control)
  12. { Scanner sc=new Scanner(System.in);
  13. String username,password,email1,email2,firstname,lastname,aboutme,photourl1,photourl2,photourl3,streetname,streetnumber,
  14. majormunicipality,governingdistrict,postalarea;
  15. int usertypeid,status,karma=0;
  16. long phone;
  17. ArrayList<String>qualification=new ArrayList<String>();
  18. String q;
  19.  
  20.  
  21. User u;
  22.  
  23. System.out.println("Enter the type of member");
  24. System.out.println("1.user");
  25. System.out.println("2.moderator");
  26. System.out.println("3.admin");
  27.  
  28. while(true)
  29. {
  30. System.out.println("Eneter the Username");
  31. username=sc.next();
  32. if(control.checkUsername(username))
  33. System.out.println("Username alraedy exists.Try a different username");
  34. else
  35. break;
  36. }
  37.  
  38. while(true)
  39. {
  40. System.out.println("Eneter the Password");
  41. password=sc.next();
  42. if(password.length()<6)
  43. System.out.println("Password should be atleast 6 characters long.Try a different password");
  44. else
  45. break;
  46. }
  47.  
  48. while(true)
  49. {
  50. System.out.println("Eneter the primary email id");
  51. email1=sc.next();
  52. if(control.checkEmail())
  53. System.out.println("Email already exists.Try again");
  54. else
  55. break;
  56. }
  57.  
  58. while(true)
  59. {
  60. System.out.println("Eneter the secondary email id");
  61. email1=sc.next();
  62. if(control.checkEmail())
  63. System.out.println("Email already exists.Try again");
  64. else
  65. break;
  66. }
  67.  
  68. System.out.println("Enter the firstname");
  69. firstname=sc.next();
  70.  
  71. System.out.println("Enter the lastname");
  72. lastname=sc.next();
  73.  
  74. System.out.println("Enter the aboutme");
  75. aboutme=sc.next();
  76.  
  77. System.out.println("Enter the photourl1");
  78. photourl1=sc.next();
  79.  
  80. System.out.println("Enter the photourl2");
  81. photourl2=sc.next();
  82.  
  83. System.out.println("Enter the photourl3");
  84. photourl3=sc.next();
  85.  
  86. System.out.println("Enter the streetname");
  87. streetname=sc.next();
  88.  
  89. System.out.println("Enter the streetnumber");
  90. streetnumber=sc.next();
  91.  
  92. System.out.println("Enter the majormunicipality");
  93. majormunicipality=sc.next();
  94.  
  95. System.out.println("Enter the governingdistrict");
  96. governingdistrict=sc.next();
  97.  
  98. System.out.println("Enter the postalarea");
  99. postalarea=sc.next();
  100.  
  101. System.out.println("Enter the usertypeID");
  102. System.out.println("1.Enduser 2.Administrator 3.Moderator");
  103. usertypeid=sc.nextInt();
  104. if(usertypeid==2 || usertypeid==3)
  105. {
  106. System.out.println("Enter your contact number");
  107. phone=sc.nextLong();
  108. }
  109.  
  110. if(usertypeid==3)
  111. {
  112. System.out.println("Enter your qualification details.Press b to break");
  113. while(true)
  114. {
  115. q=sc.next();
  116. if(q=="b")
  117. {
  118. break;
  119. }
  120. qualification.add(q);
  121. }
  122. }
  123.  
  124. if(usertypeid==1)
  125. {
  126. Date date=new Date();
  127. java.sql.Date datecreated=new java.sql.Date(date.getTime());
  128. u=new EndUser(username, password, email1, email2, firstname, lastname, aboutme, photourl1, photourl2, photourl3, streetname, streetnumber, majormunicipality, governingdistrict, postalarea, usertypeid, status, karma, datecreated);
  129. }
  130. else
  131. if(usertypeid==2)
  132. {
  133. u=new Administrator(username, password, email1, email2, firstname, lastname, aboutme, photourl1, photourl2, photourl3, streetname, streetnumber, majormunicipality, governingdistrict, postalarea, usertypeid, status, phone);
  134. }
  135. else
  136. u=new Moderator(username, password, email1, email2, firstname, lastname, aboutme, photourl1, photourl2, photourl3, streetname, streetnumber, majormunicipality, governingdistrict, postalarea, usertypeid, status, qualification, phone);
  137.  
  138. control.register(u);
  139.  
  140. }
  141.  
  142. static void login(control)
  143. {
  144. Scanner sc=new Scanner(System.in);
  145. String username,password;
  146. User u;
  147. while(true)
  148. {
  149. System.out.println("Eneter the Username and password");
  150. username=sc.next();
  151. password=sc.next();
  152. u=control.login(username,password);
  153. if(u==null)
  154. {System.out.println("wrong username or password");
  155. continue;
  156. }
  157. else
  158. break;
  159. }
  160.  
  161. System.out.println("1.View profile");
  162. System.out.println("2.Update profile");
  163. System.out.println("3.Delete profile");
  164. System.out.println("4.Send request");
  165. System.out.println("5.Reject request");
  166. System.out.println("6.Withdraw request");
  167. System.out.println("7.Confirm request");
  168. System.out.println("8.Unfriend");
  169. System.out.println("9.Logout");
  170. int ch;
  171. ch=sc.nextInt();
  172.  
  173. switch(ch)
  174. {
  175. case 1:View.viewProfile(u);
  176. break;
  177. case 2:View.updateProfile(u);
  178. break;
  179. case 3:View.deleteprofile(u);
  180. break;
  181. case 4:View.sendrequest(u);
  182. break;
  183. case 5:View.rejectrequest(u);
  184. break;
  185. case 6:View.withdrawrequest(u);
  186. break;
  187. case 7:View.confirmrequest(u);
  188. break;
  189. case 8:View.unfriend(u);
  190. break;
  191. case 9:View.logout(u);
  192. break;
  193. }
  194.  
  195. }
  196.  
  197. public static void viewProfile(User u)
  198. {
  199. if(u instanceof EndUser)
  200. ((EndUser)u).toString();
  201. else if(u instanceof Administrator)
  202. ((Administrator)u).toString();
  203. else
  204. ((Moderator)u).toString();
  205. }
  206.  
  207. public static void updateProfile(User u)
  208. {
  209.  
  210. String username,password,email1,email2,firstname,lastname,aboutme,photourl1,photourl2,photourl3,streetname,streetnumber,
  211. majormunicipality,governingdistrict,postalarea;
  212. int usertypeid,status,karma=0;
  213. long phone;
  214.  
  215.  
  216. System.out.println("What do you want to update?");
  217. System.out.println("1.Password");
  218. System.out.println("2.Firstname");
  219. System.out.println("3.Lastname");
  220. System.out.println("4.AboutMe");
  221. System.out.println("5.PhotoUrl1");
  222. System.out.println("6.PhotoUrl2");
  223. System.out.println("7.PhotoUrl3");
  224. System.out.println("8.Street Name");
  225. System.out.println("9.Street Number");
  226. if(u instanceof Administrator || u instanceof Moderator)
  227. System.out.println("10.phone number");
  228. if( u instanceof Moderator)
  229. System.out.println("11.Qualification");
  230.  
  231. Scanner sc=new Scanner(System.in);
  232. int ch;
  233. ch=sc.nextInt();
  234. switch(ch)
  235. {
  236. case 1:System.out.println("Enter the new password");
  237. password=sc.next();
  238. u.setPassword(password);
  239. break;
  240. case 2:System.out.println("Enter the new firstname");
  241. firstname=sc.next();
  242. u.setUsername(username);
  243. break;
  244.  
  245. case 3:System.out.println("Enter the new lastname");
  246. lastname=sc.next();
  247. u.setLastname(lastname);
  248. break;
  249.  
  250. case 4:System.out.println("Enter About Yourself");
  251. aboutme=sc.next();
  252. u.setAboutme(aboutme);
  253. break;
  254.  
  255. case 5:System.out.println("Enter photourl1");
  256. photourl1=sc.next();
  257. u.setPhotourl1(photourl1);
  258. break;
  259. case 6:System.out.println("Enter photourl2");
  260. photourl2=sc.next();
  261. u.setPhotourl2(photourl2);
  262. break;
  263.  
  264. case 7:System.out.println("Enterphotourl3");
  265. photourl3=sc.next();
  266. u.setPhotourl1(photourl3);
  267. break;
  268.  
  269. case 8:System.out.println("Enter Street name");
  270. streetname=sc.next();
  271. u.setStreetname(streetname);
  272. break;
  273.  
  274. case 9:System.out.println("Enter Street number");
  275. streetnumber=sc.next();
  276. u.setStreetnumber(streetnumber);
  277. break;
  278.  
  279. case 10:System.out.println("Enter Phone number");
  280. phone=sc.nextLong();
  281. if(u instanceof Administrator)
  282. {
  283. ((Administrator)u).setPhone(phone);
  284. }
  285. else
  286. ((Moderator)u).setPhone(phone);
  287. break;
  288.  
  289. // case 11:System.out.println("Enter Phone number");
  290. // System.out.println("Enter your qualification details.Press b to break");
  291. // while(true)
  292. // {
  293. // q=sc.next();
  294. // if(q=="b")
  295. // {
  296. // break;
  297. // }
  298. // qualification.add(q);
  299. // }
  300. //
  301. }
  302.  
  303. }
  304.  
  305.  
  306. public static void main(String[] args) {
  307. Scanner sc = new Scanner(System.in);
  308. Controller control=new Controller;
  309.  
  310. System.out.println("1.Register");
  311. System.out.println("2.Login");
  312. System.out.println("3.Quit");
  313. int ch=sc.nextInt();
  314. if(ch==3)
  315. {
  316. return;
  317. }
  318.  
  319.  
  320. switch(ch)
  321. {
  322. case 1: View.register(control);
  323. break;
  324. case 2: View.login(control);
  325. break;
  326. }
  327.  
  328.  
  329. }
  330.  
  331. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement