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

Public Methods the Program Must Provide All eight methods must be implemented as

ID: 3707820 • Letter: P

Question

Public Methods the Program Must Provide All eight methods must be implemented as named and as described in order for Web-CAT to be able to test and score them correctly. You may not make any assumptions regarding the number of entries of the 2-D book arrays passed to these methods. That is, it may have any number of rows, but will always have three columns. (This allows for future expansion of your code.) 1. public static void initBook (String111 book) to an empty string initializing the This method will set every element of the array parameter book phone book array to a default state that has no entries in it. 2. public static boolean bookEmpty (String book) This method will return true if the phone book is empty, false otherwise. Must handle null s 3. public static void displayBook (StringlI book) This method will display each entry in the format #. LAST, FIRST (PHONE) , where # is the row in the phonebook array, LAST is the person's last name, FIRST is the person's first name and PHONE is the person's phone number. If there are no entries in the book, display No entries. instead. 4. public static int findEmpty (String book) This method will return an int value corresponding to the first "empty position located in the array starting from row 0.If the array is full (i.e., all rows have an entry), return Must handle nul1 s 5. public static void addEntry (String1 book, Scanner g) If there is an empty/available row, this method will add a new entry to the phone book, asking for first name, then last name, then phone number. Otherwise, the display Phonebook is full! 6. public static void deleteEntry (String book, Scanner g) If there are no entries in the phonebook, the message No entries. should be displayed. Otherwise, the phonebook should be displayed and then the user can select a number from 0 through 9 to delete that entry in the phonebook, any other number to cancel. No data validation is necessary. Deleting an entry means that the first name, last name, and phonebook are all set to an empty stringt will display Record deleted. or No record deleted. as appropriate. 7. public static void sortBook (String book) This method will sort the phonebook entries by last name. You can either implement a bubble sort or a selection sort for this. See "Points to Think About" for information about duplicate last names. The prompt Phonebook sorted ill always display to the screen. 8. public static void menu (String1 book, Scanner g) This method displays a menu and calls the appropriate methods. This method has been provided for you.

Explanation / Answer

import java.util.Scanner;

public class PassBook {

static String[][] book = new String[10][3];

static Scanner scanner = null;

public static void main(String... args)

{

scanner = new Scanner(System.in);

System.out.println("1.Display phonebook");

System.out.println("2.Add entry");

System.out.println("3.Delete entry");

System.out.println("4.quit");

int choice = scanner.nextInt();

switch (choice) {

case 1:

displayBook(book);

break;

case 2:

addEntry(book);

break;

case 3:

deleteEntry(book);

break;

case 4:

System.exit(0);

}

}

private static void displayBook(String[][] book2) {

int size = book2.length;

if (size == 0) {

System.out.println("no records in the book");

} else {

for (int i = 0; i < 10; i++) {

for (int j = 0; j < 3; j++) {

System.out.println(book2[i][j]);

}

}

}

}

public static boolean bookEmpty(String[] book) {

if (book.length == 0)

return true;

else

return false;

}

public static void init(String[][] book) {

int size = book.length;

if (size == 0) {

System.out.println("no records in the book");

} else {

for (int i = 0; i < 10; i++) {

for (int j = 0; j < 3; j++) {

String str = "";

String str1 = book[i][j];

// replacing values into empty

String newString = str1.replace(str1, str);

book[i][j] = newString;

}

}

}

System.out.println("no entries");

}

public static int findEmpty(String[][] book) {

int size = book.length;

if (size == 0) {

System.out.println("no records in the book");

return -1;

} else

return 0;

}

public static void deleteEntry(String[][] book) {

System.out.println("enter the record no from 0 to 9 only to delete");

int recordno = scanner.nextInt();

if (recordno > 9) {

System.out.println("u entered wrong no");

} else {

for (int i = 0; i < 10; i++) {

for (int j = 0; j < 3; j++) {

book[i][j] = "";

}

}

}

}

public static void addEntry(String[][] book) {

System.out.println("please enter the record");

for (int i = 0; i < 1; i++) {

for (int j = 0; j < 3; j++) {

System.out

.println("enter the first name and lastname and phoneno sequentially ");

String word = scanner.next();

book[i][j] = word;

}

}

System.out.println("record inserted sucessfully");

}

}

output

1.Display phonebook
2.Add entry
3.Delete entry
4.quit
2
please enter the record
enter the first name and lastname and phoneno sequentially
koti
enter the first name and lastname and phoneno sequentially
ramu
enter the first name and lastname and phoneno sequentially
3695
record inserted sucessfully

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