Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is Java program . Any hints or help would be great. Thank you This is Java

ID: 3704078 • Letter: T

Question

This is Java program . Any hints or help would be great. Thank you This is Java program . Any hints or help would be great. Thank you Overview of Assignment This program will implement a rudimentary phone book, storing the first name, last name, and phone number for each person in the phone book. The "phonebook" will be stored in a 10x3 array of String s, with the first column storing first names, the second column storing last names, and the third column storing the phone number Here is an example of how the array might look for a 4x3 phonebook Column 0 Column1 Column2 Row 0 Wanda" "Maximoff "513-222-3333" Row 1 Row 2 Row 3Professor" Row "Jean" Grey "111-2222" "4021110000" x612" "none Peter Quill" 4"Black" "Widow The first and last names will always be a single "word", and the phone number in column 2 can be in any format.

Explanation / Answer

Please find the below implemented Phonebook class which contains all the methods.

Please check and revert in case anything needs to change then will change acordingly

****** Phonebook *****


import java.util.Scanner;
public class Phonebook {
public static void main(String[] args) {
String phoneBooks [][] = new String[10][3];
Scanner userInput = new Scanner(System.in);
initBook(phoneBooks);
menu(phoneBooks, userInput);
}
public static void initBook(String[][] book) {
for (int i=0;i<book.length;i++) {
for (int j=0;j<book[i].length;j++) {
book[i][j] = "";
}
}
}
public static boolean bookEmpty(String[][] book) {
for (int i=0;i<book.length;i++) {
for (int j=0;j<book[i].length;j++) {
if (book[i][j] != null && !book[i][j].equalsIgnoreCase("")) {
return false;
}
}
}
return true;
}
public static void displayBook(String[][] book) {
if (!bookEmpty(book)) {
System.out.println();
for (int i=0;i<book.length;i++) {
if (book[i][0] != null && !book[i][0].equalsIgnoreCase("") &&
book[i][1] != null && !book[i][1].equalsIgnoreCase("") &&
book[i][2] != null && !book[i][2].equalsIgnoreCase("")) {
String line = i+ ". " + book[i][1] + ", " + book[i][0] + " ("+ book[i][2]+")";
System.out.println(line);
}
}
System.out.println();
} else {
System.out.println(" No entries. ");
}
}
public static int findEmpty(String[][] book) {
for (int i=0;i<book.length;i++) {
boolean emptyFlag = false;
for (int j=0;j<book[i].length;j++) {
if (book[i][j] == null || book[i][j].equalsIgnoreCase("")) {
emptyFlag = true;
} else {
emptyFlag = false;
}
}
if (emptyFlag){
return i;
}
}
return -1;
}
public static void addEntry(String[][] book, Scanner g) {
System.out.println();
int entryRow = findEmpty(book);
if (entryRow != -1) {
while (true) {
System.out.print("Enter first name: ");
String firstName = g.nextLine();
if (firstName != null && !firstName.equalsIgnoreCase("")) {
book[entryRow][0] = firstName;
break;
}
}
while (true) {
System.out.print("Enter last name: ");
String lastName = g.nextLine();
if (lastName != null && !lastName.equalsIgnoreCase("")) {
book[entryRow][1] = lastName;
break;
}
}
while (true) {
System.out.print("Enter phone number: ");
String phoneNumber = g.nextLine();
if (phoneNumber != null && !phoneNumber.equalsIgnoreCase("")) {
book[entryRow][2] = phoneNumber;
break;
}
}
System.out.println();
} else {
System.out.println(" Phonebook is full. ");
}
}
public static void deleteEntry(String[][] book, Scanner g) {
if (!bookEmpty(book)) {
System.out.println();
displayBook(book);
System.out.println();
System.out.print("Enter number of entry to delete, any other integer value to cancel: ");
int entry = g.nextInt();
if (entry >=0 && entry <=9) {
if (book[entry][0] != null && !book[entry][0].equalsIgnoreCase("") &&
book[entry][1] != null && !book[entry][1].equalsIgnoreCase("") &&
book[entry][2] != null && !book[entry][2].equalsIgnoreCase("")) {
System.out.println(" Record "+entry+" deleted: "+book[entry][1]+", "+book[entry][0]+" ("+book[entry][2] +") ");
for (int j=0;j<3;j++) {
book[entry][j] = "";
}
} else {
System.out.println(" No record deleted. ");
}
} else {
System.out.println(" No record deleted. ");
}
} else {
System.out.println(" No entries. ");
}
}
public static void sortBook(String[][] book) {
for (int j = 0; j < book.length; j++) {
for (int i = 0; i < book.length - j - 1; i++) {
if (book[i + 1][1].compareTo(book[i][1]) < 0) {
String tempFirstName = book[i][0];
book[i][0] = book[i + 1][0];
book[i+1][0] = tempFirstName;
String tempLastName = book[i][1];
book[i][1] = book[i + 1][1];
book[i+1][1] = tempLastName;
String tempPhoneNumber = book[i][2];
book[i][2] = book[i + 1][2];
book[i+1][2] = tempPhoneNumber;
}
}
}
System.out.println(" Phonebook sorted. ");
}
public static void menu(String[][] book, Scanner g) {
int choice = 0;
System.out.println("Phonebook Main Menu");
do {
System.out.println();
System.out.println("1. Display Phonebook");
System.out.println("2. Add Entry");
System.out.println("3. Delete Entry");
System.out.println("4. Sort Book");
System.out.println("9. Quite");
System.out.print(" Enter choice: ");
choice = g.nextInt();
g.nextLine();
switch(choice) {
case 1:
displayBook(book);
break;
case 2:
addEntry(book, g);
break;
case 3:
deleteEntry(book, g);
break;
case 4:
sortBook(book);
break;
}
} while (choice != 9);
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote