Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.util.Scanner;
- public class PhoneBookApplication {
- public static void main(String [] args){
- PhoneBookAdmin admin = new PhoneBookAdmin();
- NormalUser user = new NormalUser();
- //setuservariables method reads from a file and returns a string array
- //that has the values for each data field
- //Then set these values to the data field for normaluser
- String [] uservariables = new String [3];
- setuservariables(uservariables);
- user.setId(uservariables[0]);
- user.setUsername(uservariables[1]);
- user.setPassword(uservariables[2]);
- //Normal user has four data fields. The first three data fields are set
- //Now the data field for directory must be set
- //so make a new instance of object phonebookdirectory and set that to the data field in user
- PhoneBookDirectory dir = new PhoneBookDirectory();
- user.setDirectory(dir);
- //this runs the method that fills the directory with default instances of the object
- user.getuserDirectory().createdirectory();
- //same thing as above but for admin
- String [] adminuservariables = new String [3];
- setadminuservariables(adminuservariables);
- admin.setEmailaddress(uservariables[0]);
- admin.setUsername(uservariables[1]);
- admin.setPassword(uservariables[2]);
- Scanner input = new Scanner (System.in);
- System.out.println("Input Username");
- String inputusername = input.next();
- System.out.println("Input password");
- String inputpassword = input.next();
- input.close();
- if (inputusername.equals(user.getUsername())){
- if (inputpassword.equals(user.getPassword())){
- System.out.println("Correct username and password for normal user");
- System.out.println("Successful login");
- usermenu(user);
- }
- }
- }
- public static void setuservariables(String [] uservariables){
- try {
- Scanner sc = new Scanner(new File("NormalUser.txt"));
- // Separate by commas
- sc.useDelimiter(",");
- while (sc.hasNext()) {
- uservariables[0] = sc.next();
- uservariables[1] = sc.next();
- uservariables[2] = sc.next();
- }
- sc.close();
- }
- catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
- public static void setadminuservariables(String [] uservariables){
- try {
- Scanner sc = new Scanner(new File("AdminUser.txt"));
- // Separate by commas
- sc.useDelimiter(",");
- while (sc.hasNext()) {
- uservariables[0] = sc.next();
- uservariables[1] = sc.next();
- uservariables[2] = sc.next();
- }
- sc.close();
- }
- catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- }
- public static void usermenu(NormalUser user){
- int loop = 1;
- //print menu
- Scanner in = new Scanner (System.in);
- while (loop == 1){
- System.out.println("1. Add Entry");
- System.out.println("2. Edit Entry");
- System.out.println("3. Sort PhoneBook Directory");
- System.out.println("4. Linear Search");
- System.out.println("5. Print user info");
- System.out.println("6. Logout");
- System.out.println("Input selection");
- int selection = 0;
- selection = in.nextInt();
- if (selection == 1){
- System.out.println("Input new entry to add");
- System.out.println("Input id");
- int ID = in.nextInt();
- System.out.println("Input first name");
- String first_name = in.next();
- System.out.println("Input last name");
- String last_name = in.next();
- System.out.println("Input email");
- String email = in.next();
- System.out.println("Input zipcode");
- int zipcode = in.nextInt();
- System.out.println("Input number");
- int number = in.nextInt();
- PhoneBookEntry Entry = new PhoneBookEntry(ID, first_name, last_name, email, zipcode, number);
- System.out.println(user.AddPhoneEntry(Entry));
- }
- else if (selection == 2){
- System.out.println("Input first name of user you want to edit");
- String fname = in.next();
- System.out.println("Input last name of user you want to edit");
- String lname = in.next();
- System.out.println(user.EditPhoneEntryFnameLname(fname, lname));
- }
- else if (selection == 3){
- user.SortPhoneBookDirectory();
- }
- else if (selection == 4){
- System.out.println("Input phonenumber you want to serach");
- int Phonenumber = in.nextInt();
- System.out.println(user.LinearSearch(Phonenumber));
- }
- else if (selection == 5){
- user.PrintUserInfo();
- }
- else if (selection == 6){
- System.out.println("Logout Successful");
- break;
- }
- }
- in.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement