PLease help me add four Java OOP concepts iin the program. Add comment so I can identify what concept it is .Thank you! ______ public class Person {   private int id; private String name; private String contactNumber; private int age;   Was this answer helpful?   private String address; private String emailAddress; / constructor public Person(int id, String name, String contactNumber, int age, String address, String emailAddress) { this.id = id; this.name = name; this.contactNumber = contactNumber; this.age = age; this.address = address; this.emailAddress = emailAddress; }   / start of getter and setter public int getId() { return id; }   public String getName() { return name; }   public void setName(String name) { this.name = name; }   public String getContactNumber() { return contactNumber; }   public void setContactNumber(String contactNumber) { this.contactNumber = contactNumber; }   public int getAge() { return age; }   public void setAge(int age) { this.age = age; }   public String getAddress() { return address; }   public void setAddress(String address) { this.address = address; }   public String getEmailAddress() { return emailAddress; }   public void setEmailAddress(String emailAddress) { this.emailAddress = emailAddress; } / end of getter and setter   / toString @Override public String toString() { return "Id: " + id + "\n" + "Name: " + name + "\n" + "Contact Number: " + contactNumber + "\n" + "Age: " + age + "\n" + "Address: " + address + "\nEmail: " + emailAddress; } } import java.util.ArrayList; import java.util.Scanner; public class PhoneBook { public static void main(String[] args) { / creating scanner object Scanner scanner = new Scanner(System.in); char task; ArrayList phoneBook = new ArrayList<>();   do { / printing menu to the user System.out.println("Tasks: "); System.out.println("\t\tA - Add a contact"); System.out.println("\t\tV - View a contact"); System.out.println("\t\tU - Update a contact"); System.out.println("\t\tD - Delete a contact"); System.out.print("Chosen Task is: "); task = scanner.next().charAt(0);   switch (task) { case 'A': System.out.println(""); / taking id input System.out.print("Enter id : "); int id = scanner.nextInt(); / clearing buffer scanner.nextLine();   / taking name input System.out.print("Enter name: "); String name = scanner.nextLine();   / taking contact number input System.out.print("Enter contact number: "); String contactNumber = scanner.nextLine();   / taking age input System.out.print("Enter age: "); int age = scanner.nextInt(); / clearing buffer scanner.nextLine();   / taking address input System.out.print("Enter address: "); String address = scanner.nextLine();   / taking email input System.out.print("Enter email: "); String email = scanner.nextLine(); Person person = new Person(id, name, contactNumber, age, address, email); phoneBook.add(person); System.out.println(); break; case 'V': System.out.println(""); System.out.print("\nEnter id of the contact to be viewed: "); int idToView = scanner.nextInt(); / clearing buffer scanner.nextLine(); for (Person item : phoneBook) { if (item.getId() == idToView) { System.out.println(item); } } System.out.println(); break; case 'U': System.out.println(""); System.out.print("\nEnter id of the contact to be updated: "); int idToUpdate = scanner.nextInt(); System.out.println("\nWhat you want to update? 1. Name, 2. Phone Number, 3. Age, 4. Address or 5. Email"); int number = scanner.nextInt(); / clearing buffer scanner.nextLine(); switch (number) { case 1: System.out.print("Enter name to update: "); String nameToUpdate = scanner.nextLine(); for (Person item : phoneBook) { if (item.getId() == idToUpdate) { item.setName(nameToUpdate); } } break; case 2: System.out.print("Enter contact number to update: "); String contactNumberToUpdate = scanner.nextLine(); for (Person item : phoneBook) { if (item.getId() == idToUpdate) {   item.setContactNumber(contactNumberToUpdate); } } break; case 3: System.out.print("Enter age to update: "); int ageToUpdate = scanner.nextInt(); / clearing buffer scanner.nextLine(); for (Person item : phoneBook) { if (item.getId() == idToUpdate) { item.setAge(ageToUpdate); } } break; case 4: System.out.print("Enter address to update: "); String addressToUpdate = scanner.nextLine(); for (Person item : phoneBook) { if (item.getId() == idToUpdate) { item.setAddress(addressToUpdate); } } break; case 5: System.out.print("Enter email to update: "); String emailToUpdate = scanner.nextLine(); for (Person item : phoneBook) { if (item.getId() == idToUpdate) { item.setEmailAddress(emailToUpdate); } } } System.out.println(); break; case 'D': System.out.println(""); System.out.print("\nEnter id of the contact to be deleted: "); int idToDelete = scanner.nextInt(); / clearing buffer scanner.nextLine(); boolean b = phoneBook.removeIf(item -> item.getId() == idToDelete); if (b){ System.out.println("Item Deleted"); }else{ System.out.println("Item not exist in the Phone Book"); } System.out.println(); } } while (task == 'A' || task == 'V' || task == 'U' || task == 'D'); } }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
100%

PLease help me add four Java OOP concepts iin the program. Add comment so I can identify what concept it is .Thank you!

______

public class Person {

 

private int id; private String name;

private String contactNumber; private int age;

 

Was this answer helpful?

 

private String address; private String emailAddress;

/ constructor

public Person(int id, String name, String contactNumber, int age, String address, String emailAddress) { this.id = id;

this.name = name; this.contactNumber = contactNumber; this.age = age;

this.address = address; this.emailAddress = emailAddress;

}

 

/ start of getter and setter public int getId() {

return id;

}

 

public String getName() { return name;

}

 

public void setName(String name) { this.name = name;

}

 

public String getContactNumber() { return contactNumber;

}

 

public void setContactNumber(String contactNumber) { this.contactNumber = contactNumber;

}

 

public int getAge() { return age;

}

 

public void setAge(int age) { this.age = age;

}

 

public String getAddress() { return address;

}

 

public void setAddress(String address) { this.address = address;

}

 

public String getEmailAddress() { return emailAddress;

}

 

public void setEmailAddress(String emailAddress) { this.emailAddress = emailAddress;

}

/ end of getter and setter

 

/ toString @Override

public String toString() {

return "Id: " + id + "\n" + "Name: " + name + "\n" + "Contact Number: " + contactNumber + "\n"

+ "Age: " + age + "\n" + "Address: " + address + "\nEmail: " + emailAddress;

}

}

import java.util.ArrayList; import java.util.Scanner;

public class PhoneBook {

public static void main(String[] args) {

/ creating scanner object

Scanner scanner = new Scanner(System.in); char task;

ArrayList<Person> phoneBook = new ArrayList<>();

 

do {

/ printing menu to the user System.out.println("Tasks: "); System.out.println("\t\tA - Add a contact"); System.out.println("\t\tV - View a contact"); System.out.println("\t\tU - Update a contact"); System.out.println("\t\tD - Delete a contact"); System.out.print("Chosen Task is: ");

task = scanner.next().charAt(0);

 

switch (task) { case 'A':

System.out.println("<Add a contact>");

/ taking id input System.out.print("Enter id : "); int id = scanner.nextInt();

/ clearing buffer scanner.nextLine();

 

/ taking name input System.out.print("Enter name: "); String name = scanner.nextLine();

 

/ taking contact number input System.out.print("Enter contact number: "); String contactNumber = scanner.nextLine();

 

/ taking age input System.out.print("Enter age: "); int age = scanner.nextInt();

/ clearing buffer scanner.nextLine();

 

/ taking address input System.out.print("Enter address: "); String address = scanner.nextLine();

 

/ taking email input System.out.print("Enter email: "); String email = scanner.nextLine();

Person person = new Person(id, name, contactNumber, age, address, email); phoneBook.add(person);

System.out.println(); break;

case 'V':

System.out.println("<View a contact>"); System.out.print("\nEnter id of the contact to be viewed: "); int idToView = scanner.nextInt();

/ clearing buffer scanner.nextLine();

for (Person item : phoneBook) { if (item.getId() == idToView) { System.out.println(item);

}

}

System.out.println();

break; case 'U':

System.out.println("<Update a contact>"); System.out.print("\nEnter id of the contact to be updated: "); int idToUpdate = scanner.nextInt();

System.out.println("\nWhat you want to update? 1. Name, 2. Phone Number, 3. Age, 4. Address or 5. Email");

int number = scanner.nextInt();

/ clearing buffer scanner.nextLine(); switch (number) { case 1:

System.out.print("Enter name to update: "); String nameToUpdate = scanner.nextLine(); for (Person item : phoneBook) {

if (item.getId() == idToUpdate) { item.setName(nameToUpdate);

}

}

break;

case 2:

System.out.print("Enter contact number to update: "); String contactNumberToUpdate = scanner.nextLine(); for (Person item : phoneBook) {

if (item.getId() == idToUpdate) {

 

item.setContactNumber(contactNumberToUpdate);

}

}

break;

case 3:

System.out.print("Enter age to update: "); int ageToUpdate = scanner.nextInt();

/ clearing buffer scanner.nextLine();

for (Person item : phoneBook) {

if (item.getId() == idToUpdate) { item.setAge(ageToUpdate);

}

}

break;

case 4:

System.out.print("Enter address to update: "); String addressToUpdate = scanner.nextLine(); for (Person item : phoneBook) {

if (item.getId() == idToUpdate) { item.setAddress(addressToUpdate);

}

}

break;

case 5:

System.out.print("Enter email to update: "); String emailToUpdate = scanner.nextLine(); for (Person item : phoneBook) {

if (item.getId() == idToUpdate) { item.setEmailAddress(emailToUpdate);

}

}

}

System.out.println(); break;

case 'D':

System.out.println("<Delete a contact>"); System.out.print("\nEnter id of the contact to be deleted: "); int idToDelete = scanner.nextInt();

/ clearing buffer scanner.nextLine();

boolean b = phoneBook.removeIf(item -> item.getId() == idToDelete); if (b){

System.out.println("Item Deleted");

}else{

System.out.println("Item not exist in the Phone Book");

}

System.out.println();

}

} while (task == 'A' || task == 'V' || task == 'U' || task == 'D');

}

}

Expert Solution
steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY