Guest User

Untitled

a guest
Apr 23rd, 2018
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 20.51 KB | None | 0 0
  1. //Initializes the program and acts as the UI (Every member on Team 10)
  2. import java.util.Scanner;
  3.  
  4. public class Main {
  5.     public static void main(String args[]) throws Exception {
  6.         Scanner scan = new Scanner(System.in);
  7.         ContactList clist = new ContactList(); // new ContactList object clist
  8.         clist.init(); // initializes the program
  9.  
  10.         System.out.println("Welcome to Team 10's Contact List");
  11.         int programRunning = 1;
  12.         while (programRunning == 1) { // while the program is still running
  13.             System.out.println("");
  14.             System.out.println("");
  15.             System.out.println("What do you wish to do?");
  16.             System.out.println("1. Add a new Contact ");
  17.             System.out.println("2. Print the Contact List");
  18.             System.out
  19.                     .println("3. Search for a Contact by Last Name, Email, or Zipcode");
  20.             System.out.println("4. Delete a Contact");
  21.             System.out.println("5. Quit and Save the new Contact");
  22.             String choice = (String) scan.nextLine();
  23.             int number = 0;
  24.  
  25.             //
  26.             // parses the user input (string) into an int
  27.             //
  28.             try {
  29.                 number = Integer.parseInt(choice);
  30.             }
  31.  
  32.             //
  33.             // if the string cannot be parsed into an int, displays a message
  34.             // saying so
  35.             //
  36.             catch (NumberFormatException nfe) {
  37.                 System.out.println("I don't know how to " + choice);
  38.                 continue;
  39.             }
  40.             switch (number) {
  41.             case 1:
  42.                 clist.addContact();
  43.                 clist.writeLinesToFile("contacts.txt", false);
  44.                 clist.readContactsFromFile();
  45.                 break;
  46.             case 2:
  47.                 clist.sortLastName();
  48.                 clist.printContactList();
  49.                 break;
  50.             case 3:
  51.                 clist.search();
  52.                 break;
  53.             case 4:
  54.                 clist.delete();
  55.                 clist.writeLinesToFile("contacts.txt", false);
  56.                 clist.readContactsFromFile();
  57.                 break;
  58.             case 5:
  59.                 clist.writeLinesToFile("contacts.txt", false);
  60.                 System.out.println("See you soon. :)");
  61.                 programRunning = 0;
  62.                 break;
  63.             default:
  64.                 System.out.println("I don't know how to " + number);
  65.                 break;
  66.             }
  67.         }
  68.     }
  69.  
  70. }
  71.  
  72. // USE CASE 1: ENTER NEW CONTACT
  73.  
  74. // Reading in Contacts from File...
  75. // EOF: Finished reading in Contacts
  76. // Welcome to Team 10's Contact List
  77. //
  78. //
  79. // What do you wish to do?
  80. // 1. Add a new Contact
  81. // 2. Print the Contact List
  82. // 3. Search for a Contact by Last Name, Email, or Zipcode
  83. // 4. Delete a Contact
  84. // 5. Quit and Save the new Contact
  85. // 1
  86. // Please enter the Contact information.
  87. // What is your First name? Sarah
  88. // What is your Last name? (Required)
  89. // What is your Last name? (Required)Port
  90. // What is your Email? (xxxx@xxx.com)email
  91. // What is your Email? (xxxx@xxx.com)website.com
  92. // What is your Email? (xxxx@xxx.com)email@website
  93. // What is your Email? (xxxx@xxx.com)email@website.com
  94. // What is your Phone Number? (xxx-xxx-xxxx)1234567899
  95. // What is your Phone Number? (xxx-xxx-xxxx)123-456-7899
  96. // What is your street address?
  97. // What city do you live in?
  98. // What State do you live in?
  99. // What is your Zip Code? 94040
  100. // Any notes?
  101. // Are you sure you want to enter the following information?
  102. // Name: Sarah Port
  103. // Email: email@website.com
  104. // Phone: 123-456-7899
  105. // Address:
  106. // 94040
  107. // Notes:
  108. // Y/N: y
  109. // Entering new Contact:
  110. // Writing Contacts to file...
  111. // Reading in Contacts from File...
  112. // EOF: Finished reading in Contacts
  113.  
  114. // USE CASE 2: PRINT ENTIRE CONTACT LIST SORTED BY LAST NAME
  115.  
  116. // What do you wish to do?
  117. // 1. Add a new Contact
  118. // 2. Print the Contact List
  119. // 3. Search for a Contact by Last Name, Email, or Zipcode
  120. // 4. Delete a Contact
  121. // 5. Quit and Save the new Contact
  122. // 2
  123. // Printing Contact List
  124. // ===========================
  125. // Name: joe atom
  126. // Email:
  127. // Phone:
  128. // Address:
  129. // Notes: no notes
  130. // ===========================
  131. // Name: Wilson Ng
  132. // Email: hisemail@derp.com
  133. // Phone:
  134. // Address: 123 Sesame St.
  135. // Mountain View Ca 94040
  136. // Notes: nope
  137. // ===========================
  138. // Name: Sarah Port
  139. // Email: email@website.com
  140. // Phone: 123-456-7899
  141. // Address: 217 College St.
  142. // Mountain View Ca 94040
  143. // Notes: no notes
  144. // ===========================
  145. // Name: Sarah Port
  146. // Email: email@website.com
  147. // Phone: 123-456-7899
  148. // Address: 217 College St.
  149. // Mountain View CA 94040
  150. // Notes: Nothing to see here folks.
  151. // ===========================
  152. // Name: Sarah Port
  153. // Email: email@website.com
  154. // Phone: 123-456-7899
  155. // Address:
  156. // 94040
  157. // Notes:
  158.  
  159. // USE CASE 3: SEARCH BY LAST NAME
  160.  
  161. // What do you wish to do?
  162. // 1. Add a new Contact
  163. // 2. Print the Contact List
  164. // 3. Search for a Contact by Last Name, Email, or Zipcode
  165. // 4. Delete a Contact
  166. // 5. Quit and Save the new Contact
  167. // 3
  168. // Please type the last name, email, or zip code you are searching for: port
  169. //
  170. // 1: Name: Sarah Port
  171. // Email: email@website.com
  172. // Phone: 123-456-7899
  173. // Address: 217 College St.
  174. // Mountain View Ca 94040
  175. // Notes: no notes
  176. //
  177. // 2: Name: Sarah Port
  178. // Email: email@website.com
  179. // Phone: 123-456-7899
  180. // Address: 217 College St.
  181. // Mountain View CA 94040
  182. // Notes: Nothing to see here folks.
  183. //
  184. // 3: Name: Sarah Port
  185. // Email: email@website.com
  186. // Phone: 123-456-7899
  187. // Address:
  188. // 94040
  189. // Notes:
  190.  
  191. // USE CASE 4: SEARCH BY EMAIL
  192.  
  193. // What do you wish to do?
  194. // 1. Add a new Contact
  195. // 2. Print the Contact List
  196. // 3. Search for a Contact by Last Name, Email, or Zipcode
  197. // 4. Delete a Contact
  198. // 5. Quit and Save the new Contact
  199. // 3
  200. // Please type the last name, email, or zip code you are searching for:
  201. // email@website.com
  202. //
  203. // 1: Name: Sarah Port
  204. // Email: email@website.com
  205. // Phone: 123-456-7899
  206. // Address: 217 College St.
  207. // Mountain View Ca 94040
  208. // Notes: no notes
  209. //
  210. // 2: Name: Sarah Port
  211. // Email: email@website.com
  212. // Phone: 123-456-7899
  213. // Address: 217 College St.
  214. // Mountain View CA 94040
  215. // Notes: Nothing to see here folks.
  216. //
  217. // 3: Name: Sarah Port
  218. // Email: email@website.com
  219. // Phone: 123-456-7899
  220. // Address:
  221. // 94040
  222. // Notes:
  223.  
  224. // USE CASE 5: SEARCH BY ZIP CODE
  225.  
  226. // What do you wish to do?
  227. // 1. Add a new Contact
  228. // 2. Print the Contact List
  229. // 3. Search for a Contact by Last Name, Email, or Zipcode
  230. // 4. Delete a Contact
  231. // 5. Quit and Save the new Contact
  232. // 3
  233. // Please type the last name, email, or zip code you are searching for: 94040
  234. //
  235. // 1: Name: Wilson Ng
  236. // Email: hisemail@derp.com
  237. // Phone:
  238. // Address: 123 Sesame St.
  239. // Mountain View Ca 94040
  240. // Notes: nope
  241. //
  242. // 2: Name: Sarah Port
  243. // Email: email@website.com
  244. // Phone: 123-456-7899
  245. // Address: 217 College St.
  246. // Mountain View Ca 94040
  247. // Notes: no notes
  248. //
  249. // 3: Name: Sarah Port
  250. // Email: email@website.com
  251. // Phone: 123-456-7899
  252. // Address: 217 College St.
  253. // Mountain View CA 94040
  254. // Notes: Nothing to see here folks.
  255. //
  256. // 4: Name: Sarah Port
  257. // Email: email@website.com
  258. // Phone: 123-456-7899
  259. // Address:
  260. // 94040
  261. // Notes:
  262.  
  263. // CONDITION FOR USE CASES 3-5: SEARCH NOT FOUND
  264.  
  265. // What do you wish to do?
  266. // 1. Add a new Contact
  267. // 2. Print the Contact List
  268. // 3. Search for a Contact by Last Name, Email, or Zipcode
  269. // 4. Delete a Contact
  270. // 5. Quit and Save the new Contact
  271. // 3
  272. // Please type the last name, email, or zip code you are searching for:
  273. // nonexistant search term
  274. // No matches found for: nonexistant search term
  275.  
  276. // USE CASE 6: DELETE A CONTACT
  277.  
  278. // What do you wish to do?
  279. // 1. Add a new Contact
  280. // 2. Print the Contact List
  281. // 3. Search for a Contact by Last Name, Email, or Zipcode
  282. // 4. Delete a Contact
  283. // 5. Quit and Save the new Contact
  284. // 4
  285. // Please type the first and last name of the contact you would like to delete:
  286. // First Name: sarah
  287. // Last Name: port
  288. //
  289. // 1: Name: Sarah Port
  290. // Email: email@website.com
  291. // Phone: 123-456-7899
  292. // Address: 217 College St.
  293. // Mountain View Ca 94040
  294. // Notes: no notes
  295. // Are you sure you'd like to delete Sarah Port? Y/N
  296. // n
  297. // SarahPort was not deleted.
  298. //
  299. // 2: Name: Sarah Port
  300. // Email: email@website.com
  301. // Phone: 123-456-7899
  302. // Address: 217 College St.
  303. // Mountain View CA 94040
  304. // Notes: Nothing to see here folks.
  305. // Are you sure you'd like to delete Sarah Port? Y/N
  306. // y
  307. //
  308. // 3: Name: Sarah Port
  309. // Email: email@website.com
  310. // Phone: 123-456-7899
  311. // Address:
  312. // 94040
  313. // Notes:
  314. // Are you sure you'd like to delete Sarah Port? Y/N
  315. // y
  316. // Writing Contacts to file...
  317. // Reading in Contacts from File...
  318. // EOF: Finished reading in Contacts
  319. //
  320. //
  321. // What do you wish to do?
  322. // 1. Add a new Contact
  323. // 2. Print the Contact List
  324. // 3. Search for a Contact by Last Name, Email, or Zipcode
  325. // 4. Delete a Contact
  326. // 5. Quit and Save the new Contact
  327. // 5
  328. // Writing Contacts to file...
  329. // See you soon. :)
  330.  
  331.  
  332.  
  333.  
  334.  
  335. //CONTACTLIST
  336.  
  337. import java.io.EOFException;
  338. import java.io.FileInputStream;
  339. import java.io.FileOutputStream;
  340. import java.io.IOException;
  341. import java.io.ObjectInputStream;
  342. import java.io.ObjectOutputStream;
  343. import java.util.Scanner;
  344.  
  345. //
  346. //Controller class. Has all the verbs of the program, and defines the array of contacts. (everyone)
  347. //
  348. public class ContactList {
  349.  
  350.     private static final long serialVersionUID = 1L;
  351.     static final String STORE_FILE = "contacts.txt";
  352.     private static final int LIMIT = 100; // static because each instance doesn't have to have a different value.
  353.     Contact[] list; // array that gets and stores all the contact objects
  354.     private int listSpot = 0; // holds the next empty spot in the array
  355.  
  356.     //
  357.     // This method sets the limit of the list with LIMIT values of type integer.
  358.     //
  359.     public ContactList() {
  360.         list = new Contact[LIMIT];
  361.     }
  362.  
  363.     //
  364.     // This method adds a new contact object to the array list.
  365.     //
  366.     public void addContact() {
  367.         if (listSpot <= LIMIT) {
  368.  
  369.             Contact newContact = new Contact(); // defines the array
  370.  
  371.             Scanner scanner = new Scanner(System.in);
  372.  
  373.             System.out.println("Please enter the Contact information.");
  374.  
  375.             String input = "";
  376.  
  377.             System.out.print("What is your First name? ");
  378.             input = scanner.nextLine();
  379.             if (null != input)
  380.                 newContact.setFirstName(input);
  381.  
  382.             while (null == newContact.getLastName() || newContact.getLastName().isEmpty()) {
  383.                 System.out.print("What is your Last name? (Required)");
  384.                 input = scanner.nextLine();
  385.                 newContact.setLastName(input);
  386.             }
  387.  
  388.             boolean emailValid = false;
  389.             String tempEmail = "";
  390.             while (!emailValid) {
  391.                 System.out.print("What is your Email? (xxxx@xxx.com)");
  392.                 tempEmail = scanner.nextLine();
  393.                 emailValid = testEmail(tempEmail);
  394.             }
  395.             if (null != tempEmail)
  396.                 newContact.setEmail(tempEmail);
  397.  
  398.             boolean phoneValid = false;
  399.             String tempPhone = "";
  400.             while (!phoneValid) {
  401.                 System.out.print("What is your Phone Number? (xxx-xxx-xxxx)");
  402.                 tempPhone = scanner.nextLine();
  403.                 phoneValid = testPhone(tempPhone);
  404.             }
  405.             if (null != tempPhone)
  406.                 newContact.setPhone(tempPhone);
  407.  
  408.             System.out.print("What is your street address? ");
  409.             input = scanner.nextLine();
  410.             if (null != input)
  411.                 newContact.setStreet(input);
  412.  
  413.             System.out.print("What city do you live in? ");
  414.             input = scanner.nextLine();
  415.             if (null != input)
  416.                 newContact.setCity(input);
  417.  
  418.             System.out.print("What State do you live in? ");
  419.             input = scanner.nextLine();
  420.             if (null != input)
  421.                 newContact.setState(input);
  422.  
  423.             System.out.print("What is your Zip Code? ");
  424.             input = scanner.nextLine();
  425.             if (null != input)
  426.                 newContact.setZipCode(input);
  427.  
  428.             System.out.print("Any notes? ");
  429.             input = scanner.nextLine();
  430.             if (null != input)
  431.                 newContact.setNotes(input);
  432.  
  433.             System.out
  434.                     .println("Are you sure you want to enter the following information?");
  435.             newContact.printContact();
  436.             String choice;
  437.             System.out.print("Y/N: ");
  438.             choice = scanner.nextLine();
  439.  
  440.             if (choice.equalsIgnoreCase("Y")) {
  441.                 System.out.println("Entering new Contact: ");
  442.  
  443.                 // Enter Contact into ContactList only after fields have been validated (i.e. lastName is not Null, phone number format, email format)
  444.                 list[listSpot] = newContact;
  445.                 listSpot++;
  446.             }
  447.         }
  448.     }
  449.  
  450.     //
  451.     //tests the syntax of the tempEmail. If it is correct it returns true, if it is incorrect it returns false.
  452.     //
  453.     private boolean testEmail(String tempEmail) {
  454.         // Test if email is in the form name@domain. Also check there is only one @ in the String.
  455.  
  456.         int firstAt = tempEmail.indexOf("@");
  457.         int lastAt = tempEmail.lastIndexOf("@");
  458.         int com = tempEmail.indexOf(".com");
  459.  
  460.         if (null == tempEmail || tempEmail.isEmpty()) {
  461.             return true;
  462.         } else if (firstAt > 0 && lastAt < tempEmail.length() - 1
  463.                 && firstAt == lastAt && com > 0) {
  464.             return true;
  465.         }
  466.         return false;
  467.     }
  468.  
  469.     //
  470.     //tests the syntax of the tempPhone number. If it is correct it returns true, if it is incorrect it returns false.
  471.     //
  472.     private boolean testPhone(String tempPhone) {
  473.         int firstDash = tempPhone.indexOf("-");
  474.         int secondDash = tempPhone.lastIndexOf("-");
  475.         int phoneLength = tempPhone.length();
  476.  
  477.         if (null == tempPhone || tempPhone.isEmpty()) {
  478.             return true;
  479.         } else if (firstDash == 3 && secondDash == 7 && phoneLength == 12) {
  480.             return true;
  481.         }
  482.         return false;
  483.     }
  484.  
  485.     //
  486.     // This method prints ContactsList list.
  487.     //
  488.     public void printContactList() {
  489.  
  490.         System.out.println("Printing Contact List");
  491.         for (int i = 0; i < listSpot; i++) {
  492.             if (list[i] != null) { // print list[i] only if list[i] IS NOT(!=)
  493.                 // null
  494.                 System.out.println("===========================");
  495.                 list[i].printContact();
  496.             }
  497.         }
  498.     }
  499.  
  500.     //
  501.     // method deletes contacts
  502.     //
  503.     public void delete() {
  504.         String searchFirst;
  505.         String searchLast;
  506.         System.out.println("Please type the first and last name of the contact you would like to delete: ");
  507.         Scanner scan = new Scanner(System.in);
  508.         System.out.print("First Name: ");
  509.         searchFirst = scan.nextLine();
  510.         System.out.print("Last Name: ");
  511.         searchLast = scan.nextLine();
  512.  
  513.         int e = 0;
  514.  
  515.         int count = 0;
  516.  
  517.         while (e < listSpot) {
  518.             if (searchFirst.equalsIgnoreCase(list[e].getFirstName())
  519.                     && searchLast.equalsIgnoreCase(list[e].getLastName())) {
  520.  
  521.                 System.out.print("\n" + ++count + ": ");
  522.                 list[e].printContact();
  523.                 System.out.println("Are you sure you'd like to delete "
  524.                         + list[e].getFirstName() + " " + list[e].getLastName()
  525.                         + "? Y/N");
  526.                 String delete;
  527.                 delete = scan.nextLine();
  528.  
  529.                 if (delete.equalsIgnoreCase("y")) {
  530.                     list[e] = null;
  531.                 } else {
  532.                     System.out.println(list[e].getFirstName()
  533.                             + list[e].getLastName() + " was not deleted.");
  534.                 }
  535.             }
  536.             e++;
  537.         }
  538.         if (count < 1) {
  539.             System.out.println("No matches found for: " + searchFirst + searchLast);
  540.         }
  541.     }
  542.  
  543.     //
  544.     // This method searches by Last Name, Email, or Zip Code. if found it prints the contact's information searched or prints "not found". (WNG)
  545.     //
  546.     public void search() {
  547.         String search;
  548.         System.out
  549.                 .print("Please type the last name, email, or zip code you are searching for: ");
  550.         Scanner scan = new Scanner(System.in);
  551.         search = scan.nextLine();
  552.  
  553.         int e = 0;
  554.  
  555.         int count = 0;
  556.  
  557.         while (e < listSpot) {
  558.             if (search.equalsIgnoreCase(list[e].getLastName())
  559.                     || search.equalsIgnoreCase(list[e].getEmail())
  560.                     || search.equalsIgnoreCase(list[e].getZipCode())) {
  561.                 System.out.print("\n" + ++count + ": ");
  562.                 list[e].printContact();
  563.             }
  564.             e++;
  565.         }
  566.         if (count < 1) {
  567.             System.out.println("No matches found for: " + search);
  568.         }
  569.     }
  570.  
  571.     //
  572.     // This method sorts the array by Last names (WNG)
  573.     //
  574.     public void sortLastName() {
  575.         int in;
  576.         int out;
  577.         for (out = 1; out < listSpot; out++) {
  578.             Contact temp = list[out];
  579.             in = out;
  580.  
  581.             while (in > 0 && list[in - 1].getLastName().toLowerCase().compareTo(temp.getLastName().toLowerCase()) > 0) {
  582.                 list[in] = list[in - 1]; // shift item to the right
  583.                 --in; // go left one position
  584.             }
  585.             list[in] = temp;
  586.         }
  587.     }
  588.  
  589.     //
  590.     // This method writes and saves the information into a text file to disk.
  591.     //
  592.     public void writeLinesToFile(String filePath, boolean appendToFile) {
  593.         FileOutputStream outFileStream;
  594.         ObjectOutputStream outObjectStream;
  595.         try {
  596.             outFileStream = new FileOutputStream(filePath);
  597.             outObjectStream = new ObjectOutputStream(outFileStream);
  598.             for (int i = 0; i < listSpot; i++) {
  599.                 outObjectStream.writeObject(list[i]);
  600.             }
  601.             outObjectStream.flush();
  602.             outObjectStream.close();
  603.             outFileStream.close();
  604.             System.err.println("Writing Contacts to file...");
  605.         } catch (IOException ioe) {
  606.             System.out.println("Error writing objects to the file: "
  607.                     + ioe.getMessage());
  608.             ioe.printStackTrace();
  609.         }
  610.     }
  611.  
  612.     //
  613.     // This method reads the saved file into the array Contact[] list
  614.     //
  615.     public void readContactsFromFile() throws Exception {
  616.         FileInputStream inFileStream = null;
  617.         ObjectInputStream inObjectStream = null;
  618.  
  619.         System.err.println("Reading in Contacts from File...");
  620.  
  621.         try {
  622.             inFileStream = new FileInputStream("contacts.txt");
  623.             inObjectStream = new ObjectInputStream(inFileStream);
  624.  
  625.             // Reset listSpot to read in Contacts
  626.             listSpot = 0;
  627.  
  628.             // Read in each Contact from the store file and assign to list
  629.             // Contact[].
  630.             // Assign current read Contact position to listSpot.
  631.             boolean keepGoing = true;
  632.  
  633.             while (keepGoing) {
  634.  
  635.                 Contact readContact = (Contact) inObjectStream.readObject();
  636.                 if (null == readContact) {
  637.                    
  638.                 } else {
  639.  
  640.                     list[listSpot] = readContact;
  641.                     listSpot++;
  642.                 }
  643.             }
  644.  
  645.         } catch (EOFException eof) {
  646.             System.err.println("EOF: Finished reading in Contacts");
  647.  
  648.         } catch (IOException ioe) {
  649.             System.err.println("Error reading from the file: "
  650.                     + ioe.getMessage());
  651.         } catch (ClassNotFoundException cnfe) {
  652.             System.err.println("Error in casting to Object: " + cnfe);
  653.  
  654.         } finally {
  655.             if (inFileStream != null)
  656.                 inFileStream.close();
  657.             if (inObjectStream != null)
  658.                 inObjectStream.close();
  659.         }
  660.  
  661.     }
  662.  
  663.     //
  664.     //initiates the program.
  665.     //
  666.     public void init() {
  667.         try {
  668.             readContactsFromFile();
  669.         } catch (Exception e) {
  670.             // TODO Auto-generated catch block
  671.             e.printStackTrace();
  672.         }
  673.  
  674.     }
  675. }
  676.  
  677.  
  678.  
  679.  
  680.  
  681. //CONTACT
  682.  
  683. //Creates contacts's information with first name, last name, phone number, email, and home address. (everyone)
  684. import java.io.Serializable;
  685.  
  686. //
  687. //model class
  688. //
  689. public class Contact implements Serializable {
  690.  
  691.     private static final long serialVersionUID = 1L;
  692.     private String firstName;
  693.     private String lastName;
  694.     private String email;
  695.     private String phone;
  696.     private String street;
  697.     private String city;
  698.     private String state;
  699.     private String zipCode;
  700.     private String notes;
  701.  
  702.     //
  703.     //the following set methods sets the local variables for the current instance in the array.
  704.     //
  705.    
  706.     public void setFirstName(String firstName) {
  707.         this.firstName = firstName;
  708.     }
  709.  
  710.     public void setLastName(String lastName) {
  711.         this.lastName = lastName;
  712.     }
  713.  
  714.     public void setEmail(String email) {
  715.         this.email = email;
  716.     }
  717.  
  718.     public void setPhone(String phone) {
  719.         this.phone = phone;
  720.     }
  721.  
  722.     public void setStreet(String street) {
  723.         this.street = street;
  724.     }
  725.  
  726.     public void setCity(String city) {
  727.         this.city = city;
  728.     }
  729.  
  730.     public void setState(String state) {
  731.         this.state = state;
  732.     }
  733.  
  734.     public void setZipCode(String zipCode) {
  735.         this.zipCode = zipCode;
  736.     }
  737.  
  738.     public void setNotes(String notes) {
  739.         this.notes = notes;
  740.     }
  741.  
  742.     public String getFirstName() {
  743.         return firstName;
  744.     }
  745.  
  746.     //
  747.     //the following get methods return the local variables for use outside of this class.
  748.     //
  749.     public String getLastName() {
  750.         return lastName;
  751.     }
  752.  
  753.     // This method gets the values for email
  754.     public String getEmail() {
  755.         return email;
  756.     }
  757.  
  758.     // This method gets the values for phone
  759.     public String getPhone() {
  760.         return phone;
  761.     }
  762.  
  763.     // This method gets the values for street
  764.     public String getStreet() {
  765.         return street;
  766.     }
  767.  
  768.     // This method gets the values for city
  769.     public String getCity() {
  770.         return city;
  771.     }
  772.  
  773.     // This method gets the values for state
  774.     public String getState() {
  775.         return state;
  776.     }
  777.  
  778.     // This method gets the values for zipCode
  779.     public String getZipCode() {
  780.         return zipCode;
  781.     }
  782.  
  783.     // This method gets the values for notes
  784.     public String getNotes() {
  785.         return notes;
  786.     }
  787.  
  788.     // This method prints the all the Contact's information
  789.     public void printContact() {
  790.         System.out.println("Name: " + firstName + " " + lastName);
  791.         System.out.println("Email: " + email);
  792.         System.out.println("Phone: " + phone);
  793.         if (street.length() == 0 && city.length() == 0 && state.length() == 0
  794.                 && zipCode.length() == 0) { // If all address information is missing, the punctuation will not be printed.
  795.             System.out.println("Address:");
  796.         } else {
  797.             System.out.println("Address: " + street + "\n" + "        " + city
  798.                     + " " + state + " " + zipCode);
  799.         }
  800.         System.out.println("Notes: " + notes);
  801.     }
  802. }
Add Comment
Please, Sign In to add comment