Write a program that will maintain a personal phonebook. The program should be menu driven.
Create a Person class. (name, age, id number, phone number, zip code)
Include 2 constructors, get and set methods, compareTo, and toString methods.
Also please add comments!
thanks for the question, here are the 3 classes, Due to time constraint, i could not finish of the modify function, rest all methods are implemented.
Here are the code for the 3 classes
========================================================
public class Person implements Comparable<Person> {
private String name;
private int age;
private int id;
private String phoneNumber;
private int zipCode;
public Person(String name, int age, int id, String phoneNumber, int zipCode) {
this.name = name;
this.age = age;
this.id = id;
this.phoneNumber = phoneNumber;
this.zipCode = zipCode;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
public int getZipCode() {
return zipCode;
}
public void setZipCode(int zipCode) {
this.zipCode = zipCode;
}
@Override
public int compareTo(Person person) {
return this.name.compareTo(person.getName());
}
@Override
public String toString() {
return name +
", Age: " + age +
", ID: " + id +
", Phone Number: " + phoneNumber + '\'' +
", ZipCode: " + zipCode;
}
@Override
public boolean equals(Object o) {
if (o != null && o instanceof Person) {
Person p = (Person) o;
return this.getName().equals(p.getName()) && this.getId() == p.getId() &&
this.getPhoneNumber().equals(p.getPhoneNumber());
}
return false;
}
}
========================================================
import java.util.ArrayList;
import java.util.Collections;
public class PhoneBook {
private ArrayList<Person> persons;
public PhoneBook() {
persons = new ArrayList<>();
}
public void addPerson(Person person) {
persons.add(person);
System.out.println("Person added successfully");
}
public void removePerson(String name) {
Person personToDelete = null;
for (Person person : persons) {
if (person.getName().equalsIgnoreCase(name)) {
personToDelete = person;
break;
}
}
if (personToDelete != null) {
persons.remove(personToDelete);
System.out.println("Person deleted successfully");
} else {
System.out.println("No person with name: " + name + " found in the directory");
}
}
public void sortPhoneBook() {
Collections.sort(persons);
}
public Person searchPerson(String name) {
for (Person person : persons) {
if (person.getName().equals(name)) {
return person;
}
}
System.out.println("No person with name: " + name + " found in the directory");
return null;
}
public void modifyPerson(Person person) {
for (Person p : persons) {
if (p.getName().equals(person.getName())) {
p = person;
return;
}
}
}
public void saveData() {
System.out.println("ERROR: IN DEVELOPEMENT");
}
public void readData() {
System.out.println("ERROR: IN DEVELOPEMENT");
}
public void printPersons() {
for (Person person : persons) {
System.out.println(person);
}
}
}
========================================================
import java.util.Scanner;
public class PhoneBookApplication {
private static Scanner scanner = new Scanner(System.in);
public static void main(String[] args) {
System.out.println("WELCOME TO PHONE BOOK APPLICATION");
PhoneBook phoneBook = new PhoneBook();
while (true) {
System.out.println("[1] - Add Person");
System.out.println("[2] - Print Phone Book");
System.out.println("[3] - Remove Person");
System.out.println("[4] - Sort Phone Book");
System.out.println("[5] - Modify Person");
System.out.println("[6] - Save to file");
System.out.println("[7] - Load file");
System.out.println("[8] - Quit");
int choice = scanner.nextInt();
switch (choice) {
case 1:
addPerson(phoneBook);
break;
case 2:
phoneBook.printPersons();
break;
case 3:
removePerson(phoneBook);
break;
case 4:
phoneBook.sortPhoneBook();
break;
case 5:
break;
case 6:
phoneBook.saveData();
break;
case 7:
phoneBook.readData();
break;
case 8:
System.out.println("Thanks for using the application");
return;
}
}
}
public static void addPerson(PhoneBook phoneBook) {
System.out.print("Enter person name: ");
String name = scanner.nextLine();
System.out.print("Enter age: ");
int age = scanner.nextInt();
scanner.nextLine();
System.out.print("Enter person ID: ");
int id = scanner.nextInt();
scanner.nextLine();
System.out.print("Enter phone number: ");
String phone = scanner.nextLine();
System.out.print("Enter zip code: ");
int zipCode = scanner.nextInt();
scanner.nextLine();
Person person = new Person(name, age, id, phone, zipCode);
phoneBook.addPerson(person);
}
public static void removePerson(PhoneBook phoneBook) {
System.out.print("Enter person name whom you want to delete: ");
String name = scanner.nextLine();
phoneBook.removePerson(name);
}
}
========================================================
thanks !!!
Write a program that will maintain a personal phonebook. The program should be menu driven. Create...
Create a menu-driven program (using the switch) that finds and displays areas of 3 different objects. The menu should have the following 4 choices: 1 -- rectangle 2 -- circle 3 -- triangle 4 -- quit If the user selects choice 1, the program should find the area of a rectangle. rectangle area = length * width If the user selects choice 2, the program should find the area of a circle. circle area = PI * radius * radius...
Write a contacts database program that presents the user with a menu that allows the user to select between the following options: (In Java) Save a contact. Search for a contact. Print all contacts out to the screen. Quit If the user selects the first option, the user is prompted to enter a person's name and phone number which will get saved at the end of a file named contacts.txt. If the user selects the second option, the program prompts...
Design program so that it correctly meets the program specifications given below. Specifications: Create a menu-driven program that finds and displays areas of 3 different objects. The menu should have the following 4 choices: 1 -- square 2 -- circle 3 -- right triangle 4 -- quit If the user selects choice 1, the program should find the area of a square. If the user selects choice 2, the program should find the area of a circle. If the user...
Phonebook This program is used to create a phonebook for storing contact information into a text file. The program begins by asking the user to provide a name for the file that will contain their phone book information. It will then ask the user to provide the names and numbers of their contacts. It should keep asking the user for contact information until they type in Done (case-sensitive). After the user types Done, store all contact information into the file...
In C++ write a simple menu program that displays a menu for the user in an object-oriented technique. The menu should keep showing up until the user chooses to quit. Also, there is a sub-menu inside a menu. The user should get at least a line displayed after he or she chooses that particular option meaning if the user presses 1 for the read actors from the file. The output can look like "reading actors from a file" and then...
This program is used to create a phonebook for storing contact information into a text file. The program begins by asking the user to provide a name for the file that will contain their phone book information. It will then ask the user to provide the names and numbers of their contacts. It should keep asking the user for contact information until they type in Done (case-sensitive). After the user types Done, store all contact information into the file name...
Using python 3.7.3 Challenge: Rock, Paper, Scissors GamePDF Description: Create a menu-driven rock, paper, scissors game in Python 3 that a user plays against the computer with the ability to save and load a game and its associated play statistics. Purpose: The purpose of this challenge is to assess the developer’s ability to create an interactive application with data persistence in Python 3. Requirements: Create a Rock, Paper, Scissors game in Python named rps.py according to the requirements specified in...
Create a java program that reads an input file named Friends.txt containing a list 4 names (create this file using Notepad) and builds an ArrayList with them. Use sout<tab> to display a menu asking the user what they want to do: 1. Add a new name 2. Change a name 3. Delete a name 4. Print the list or 5. Quit When the user selects Quit your app creates a new friends.txt output file. Use methods: main( ) shouldn’t do...
Write a menu driven program to demonstrate the use of array and switch. It must be written in C language . Here is the menu - Press 1 to add a number to the array. Press 2 to display the numbers entered in the array so far Press 3 to find the average of the numbers entered. Press 4 to exit. Option 1 - The user should be able to enter 20 numbers only. If all twenty numbers are entered...
Requesting help with the following C Program: DESIGN and IMPLEMENT a menu driven program that uses the following menu and can perform all menu items: Enter a payroll record for one person Display all paycheck stubs Display total gross payroll from all pay records. Quit program The program will reuse the DATE struct from the previous assignment. You should also copy in the functions relating to a DATE. The program will create a PAYRECORD struct with the following fields: typedef struct...