Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Page 1 of 2 /* APCSA Ch85pg28: Phone Book Array List 4a 20240206 STU Burkham, 20230209 Write the missing lines of code in the static

Page 1 of 2 /* APCSA Ch85pg28: Phone Book Array List 4a 20240206 STU Burkham, 20230209 Write the missing lines of code in the static matchName() method. Modify the program so that it searches for a name entered by the user String name="Zoe"; // input the search name PLN(matchName(name,phone)); // look up name in phonebook, print returned answer static public String matchName(String n, ArrayList p) // find name in phonebook list { String a=""; // the "answer" string to return // ######------ insert code here ------###### return a; } Test, change, play with code. Know all the concepts, be able to clearly explain each part and each line! */ import java.util.* ; public class Ch85pg28_PhoneBook_STU4a { public static void main ( String[] args) { ArrayList phone = new ArrayList(); phone.add( new Entry( "Amy", "123-4567") ); phone.add( new Entry( "Bob", "123-6780") ); phone.add( new Entry( "Hal", "789-1234") ); phone.add( new Entry( "Deb", "789-4457") ); phone.add( new Entry( "Zoe", "446-0210") ); String name="Zoe"; // input the search name PLN(matchName(name,phone)); // look up name in phonebook, print returned answer }//---------------- END MAIN --------------- // ------------- Static Print methods (shortens code, eases readability) ------------------- public static void P(Object arg) {System.out.print(arg);} public static void PLN(Object arg) {System.out.println(arg);} //------------------- INSERT CODE ------------------- static public String matchName(String n, ArrayList p) // find name in phonebook list { String a=""; // the default "answer" string to return // ######------ insert code here ------###### return a; } } class Entry // Makes objects for the ArrayList { private String name; // PIVs private String number; public Entry(String n, String num) { name=n; number=num; } // constructor public String getName() { return name; } // getter method public String getNumber() { return number; } // getter public boolean equals(Object other) // define equals method { //System.out.print (" Compare " + other + " To " + this ); // Debugging //System.out.println(" Result: " + name.equals( ((Entry)other).name ) ); return getName().equals( ((Entry)other).getName() ); } public String toString() { return "Name: "+getName()+"; Number: "+getNumber(); } }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mobile Communications

Authors: Jochen Schiller

2nd edition

978-0321123817, 321123816, 978-8131724262

More Books

Students also viewed these Programming questions