Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hey I need help with these problems. I need detailed work if possible thanks Problem 2 -ArrayList In this problem, we implement an ArrayList to

Hey I need help with these problems. I need detailed work if possible image text in transcribed thanks

Problem 2 -ArrayList In this problem, we implement an ArrayList to store a phone directory with your friends names and phone numbers. Each entry in the phone directory consists of an object of type DirectoryEntry. The clas DirectoryEntry has two instance variables (name, number), getter and setter methods, and toString( method DirectoryEntry - name:String - number:string + DirectoryEntry) + DirectoryEntry(name:String, number:String) + toString() : String //getters and setters Implement the class DirectoryEntry and a Main class for testing. The Main class declares an ArrayList object to store the phone directory, namely theDirectory Write a loop of 4 iterations (e.g. counter-controlled for statement). In each iteration, ask for a friends name and number, and instantiate a new entry of type DirectoryEntry accordingly. Use the methoo boolean add(DirectoryEntry entry) to add the new entry to the ArrayList theDirectory Write an enhanced for loop that passes over the entries in theDirectory, and calls the method toString( at each iteration. Remove the entry at index 2 using the method DirectoryEntry remove(int index), and print out the removed entry using toString() method. Add an entry at index 1 using the method void ad(int index, DirectoryEntry entry), given the friend's name-"Jad Hassan" and the phone number-"03223322" Replace the entry at index 3 using the method DirectoryEntry set(int index, DirectoryEnty entry) with the friend's name "Liam McDonald" and the phone number-"03998877" Write a public method String addOrChangeEntry(DirectoryEntry theDirectory, String name, String newNumber), where this method first checks for the friend's name in theDirectory. If the friend's name is in theDirectory, the method changes the value of the phone number associated to the friend's name, then returns the old number. Else, the method instantiates a new entry of type DirectoryEntry, and ado the entry to end of theDirectory using the method boolean add(DirectoryEntry entry),then returns null. Call the method addorChangeEntry(theDirectory, "Sam Schouman", "81554488") Again, write an enhanced for loop that passes over the entries in theDirectory, and call the methoo toString() at each iteration. Problem 2 -ArrayList In this problem, we implement an ArrayList to store a phone directory with your friends names and phone numbers. Each entry in the phone directory consists of an object of type DirectoryEntry. The clas DirectoryEntry has two instance variables (name, number), getter and setter methods, and toString( method DirectoryEntry - name:String - number:string + DirectoryEntry) + DirectoryEntry(name:String, number:String) + toString() : String //getters and setters Implement the class DirectoryEntry and a Main class for testing. The Main class declares an ArrayList object to store the phone directory, namely theDirectory Write a loop of 4 iterations (e.g. counter-controlled for statement). In each iteration, ask for a friends name and number, and instantiate a new entry of type DirectoryEntry accordingly. Use the methoo boolean add(DirectoryEntry entry) to add the new entry to the ArrayList theDirectory Write an enhanced for loop that passes over the entries in theDirectory, and calls the method toString( at each iteration. Remove the entry at index 2 using the method DirectoryEntry remove(int index), and print out the removed entry using toString() method. Add an entry at index 1 using the method void ad(int index, DirectoryEntry entry), given the friend's name-"Jad Hassan" and the phone number-"03223322" Replace the entry at index 3 using the method DirectoryEntry set(int index, DirectoryEnty entry) with the friend's name "Liam McDonald" and the phone number-"03998877" Write a public method String addOrChangeEntry(DirectoryEntry theDirectory, String name, String newNumber), where this method first checks for the friend's name in theDirectory. If the friend's name is in theDirectory, the method changes the value of the phone number associated to the friend's name, then returns the old number. Else, the method instantiates a new entry of type DirectoryEntry, and ado the entry to end of theDirectory using the method boolean add(DirectoryEntry entry),then returns null. Call the method addorChangeEntry(theDirectory, "Sam Schouman", "81554488") Again, write an enhanced for loop that passes over the entries in theDirectory, and call the methoo toString() at each iteration

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

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions