Guest User

Untitled

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