Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package as2_view;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.Scanner;
- import Members.*;
- public class View {
- static void register(HealthAppController control)
- { Scanner sc=new Scanner(System.in);
- String username,password,email1,email2,firstname,lastname,aboutme,photourl1,photourl2,photourl3,streetname,streetnumber,
- majormunicipality,governingdistrict,postalarea;
- int usertypeid,status,karma=0;
- long phone;
- ArrayList<String>qualification=new ArrayList<String>();
- String q;
- User u;
- System.out.println("Enter the type of member");
- System.out.println("1.user");
- System.out.println("2.moderator");
- System.out.println("3.admin");
- while(true)
- {
- System.out.println("Eneter the Username");
- username=sc.next();
- if(control.checkUsername(username))
- System.out.println("Username alraedy exists.Try a different username");
- else
- break;
- }
- while(true)
- {
- System.out.println("Eneter the Password");
- password=sc.next();
- if(password.length()<6)
- System.out.println("Password should be atleast 6 characters long.Try a different password");
- else
- break;
- }
- while(true)
- {
- System.out.println("Eneter the primary email id");
- email1=sc.next();
- if(control.checkEmail())
- System.out.println("Email already exists.Try again");
- else
- break;
- }
- while(true)
- {
- System.out.println("Eneter the secondary email id");
- email1=sc.next();
- if(control.checkEmail())
- System.out.println("Email already exists.Try again");
- else
- break;
- }
- System.out.println("Enter the firstname");
- firstname=sc.next();
- System.out.println("Enter the lastname");
- lastname=sc.next();
- System.out.println("Enter the aboutme");
- aboutme=sc.next();
- System.out.println("Enter the photourl1");
- photourl1=sc.next();
- System.out.println("Enter the photourl2");
- photourl2=sc.next();
- System.out.println("Enter the photourl3");
- photourl3=sc.next();
- System.out.println("Enter the streetname");
- streetname=sc.next();
- System.out.println("Enter the streetnumber");
- streetnumber=sc.next();
- System.out.println("Enter the majormunicipality");
- majormunicipality=sc.next();
- System.out.println("Enter the governingdistrict");
- governingdistrict=sc.next();
- System.out.println("Enter the postalarea");
- postalarea=sc.next();
- System.out.println("Enter the usertypeID");
- System.out.println("1.Enduser 2.Administrator 3.Moderator");
- usertypeid=sc.nextInt();
- if(usertypeid==2 || usertypeid==3)
- {
- System.out.println("Enter your contact number");
- phone=sc.nextLong();
- }
- if(usertypeid==3)
- {
- System.out.println("Enter your qualification details.Press b to break");
- while(true)
- {
- q=sc.next();
- if(q=="b")
- {
- break;
- }
- qualification.add(q);
- }
- }
- if(usertypeid==1)
- {
- Date date=new Date();
- java.sql.Date datecreated=new java.sql.Date(date.getTime());
- u=new EndUser(username, password, email1, email2, firstname, lastname, aboutme, photourl1, photourl2, photourl3, streetname, streetnumber, majormunicipality, governingdistrict, postalarea, usertypeid, status, karma, datecreated);
- }
- else
- if(usertypeid==2)
- {
- u=new Administrator(username, password, email1, email2, firstname, lastname, aboutme, photourl1, photourl2, photourl3, streetname, streetnumber, majormunicipality, governingdistrict, postalarea, usertypeid, status, phone);
- }
- else
- u=new Moderator(username, password, email1, email2, firstname, lastname, aboutme, photourl1, photourl2, photourl3, streetname, streetnumber, majormunicipality, governingdistrict, postalarea, usertypeid, status, qualification, phone);
- control.register(u);
- }
- static void login(control)
- {
- Scanner sc=new Scanner(System.in);
- String username,password;
- User u;
- while(true)
- {
- System.out.println("Eneter the Username and password");
- username=sc.next();
- password=sc.next();
- u=control.login(username,password);
- if(u==null)
- {System.out.println("wrong username or password");
- continue;
- }
- else
- break;
- }
- System.out.println("1.View profile");
- System.out.println("2.Update profile");
- System.out.println("3.Delete profile");
- System.out.println("4.Send request");
- System.out.println("5.Reject request");
- System.out.println("6.Withdraw request");
- System.out.println("7.Confirm request");
- System.out.println("8.Unfriend");
- System.out.println("9.Logout");
- int ch;
- ch=sc.nextInt();
- switch(ch)
- {
- case 1:View.viewProfile(u);
- break;
- case 2:View.updateProfile(u);
- break;
- case 3:View.deleteprofile(u);
- break;
- case 4:View.sendrequest(u);
- break;
- case 5:View.rejectrequest(u);
- break;
- case 6:View.withdrawrequest(u);
- break;
- case 7:View.confirmrequest(u);
- break;
- case 8:View.unfriend(u);
- break;
- case 9:View.logout(u);
- break;
- }
- }
- public static void viewProfile(User u)
- {
- if(u instanceof EndUser)
- ((EndUser)u).toString();
- else if(u instanceof Administrator)
- ((Administrator)u).toString();
- else
- ((Moderator)u).toString();
- }
- public static void updateProfile(User u)
- {
- String username,password,email1,email2,firstname,lastname,aboutme,photourl1,photourl2,photourl3,streetname,streetnumber,
- majormunicipality,governingdistrict,postalarea;
- int usertypeid,status,karma=0;
- long phone;
- System.out.println("What do you want to update?");
- System.out.println("1.Password");
- System.out.println("2.Firstname");
- System.out.println("3.Lastname");
- System.out.println("4.AboutMe");
- System.out.println("5.PhotoUrl1");
- System.out.println("6.PhotoUrl2");
- System.out.println("7.PhotoUrl3");
- System.out.println("8.Street Name");
- System.out.println("9.Street Number");
- if(u instanceof Administrator || u instanceof Moderator)
- System.out.println("10.phone number");
- if( u instanceof Moderator)
- System.out.println("11.Qualification");
- Scanner sc=new Scanner(System.in);
- int ch;
- ch=sc.nextInt();
- switch(ch)
- {
- case 1:System.out.println("Enter the new password");
- password=sc.next();
- u.setPassword(password);
- break;
- case 2:System.out.println("Enter the new firstname");
- firstname=sc.next();
- u.setUsername(username);
- break;
- case 3:System.out.println("Enter the new lastname");
- lastname=sc.next();
- u.setLastname(lastname);
- break;
- case 4:System.out.println("Enter About Yourself");
- aboutme=sc.next();
- u.setAboutme(aboutme);
- break;
- case 5:System.out.println("Enter photourl1");
- photourl1=sc.next();
- u.setPhotourl1(photourl1);
- break;
- case 6:System.out.println("Enter photourl2");
- photourl2=sc.next();
- u.setPhotourl2(photourl2);
- break;
- case 7:System.out.println("Enterphotourl3");
- photourl3=sc.next();
- u.setPhotourl1(photourl3);
- break;
- case 8:System.out.println("Enter Street name");
- streetname=sc.next();
- u.setStreetname(streetname);
- break;
- case 9:System.out.println("Enter Street number");
- streetnumber=sc.next();
- u.setStreetnumber(streetnumber);
- break;
- case 10:System.out.println("Enter Phone number");
- phone=sc.nextLong();
- if(u instanceof Administrator)
- {
- ((Administrator)u).setPhone(phone);
- }
- else
- ((Moderator)u).setPhone(phone);
- break;
- // case 11:System.out.println("Enter Phone number");
- // System.out.println("Enter your qualification details.Press b to break");
- // while(true)
- // {
- // q=sc.next();
- // if(q=="b")
- // {
- // break;
- // }
- // qualification.add(q);
- // }
- //
- }
- }
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- Controller control=new Controller;
- System.out.println("1.Register");
- System.out.println("2.Login");
- System.out.println("3.Quit");
- int ch=sc.nextInt();
- if(ch==3)
- {
- return;
- }
- switch(ch)
- {
- case 1: View.register(control);
- break;
- case 2: View.login(control);
- break;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement