Develop a menu driven application that shall allow user to choose different option numbers to add, search, update and delete users in an ArrayList object. Make a UserService class and implement different methods to perform each operation. These methods shall be called from main metod of UserServiceTest class. The ArrayList shall be defined as private instance variable in UserService, of type ArrayList named users.   The User class shall be composed of id, name and city fields. Define a constructor in User class that shall take and initialize id and name fields. Initialize the city field using setCity method. When user choose an option number for search, you shall take a string from user and list all those users id, name ad city where given string appears in user name or city (use some method of String class or StringUtils class from Apache Commons library to match sub-string for search). Search operation shall be performed by a method in UserService class, ArrayList search(String searchString), the method shall be called from UserServiceTest class where menu logic shall be implemented.   When user choose to add a new user, get name and city from user input (id shall be auto-incremented for each object, starting from 1). After getting the data, ask user at what index the object shall be added. You shall call void add(User user, int index) method defined in UserService class to add new user object at given index. If user enters an invalid index (i.e. => ArrayList size), show an error message and retake the index from user. After adding the user in ArrayList, show generated id for the added user. e.g. "User added with id 3". If users enters negative value for index, then add the user object as last element in the ArrayList.   When user choose to update user, get user id as input. Define User getUser(int userID) method in UserService class that shall return the user with given user ID. You shall display the current name and city of the user and let him/her update by getting updated name and city from input. Update both fields of that object in ArrayList. Do not change the user ID. To update, you shall call void updateUser(int userID, String newName, String newCityName).   When user choose to delete an object from the ArrayList, get user ID as input. Pass that id to UserService deleteUser method (boolean deleteUser(int userID), the method shall first search the ArrayList where that user is stored. Once you searched its index, remove that user from the ArrayList object. If no user exist with the specified ID, the method shall return false to indicate that no user was found inside the ArrayList with specified ID.   After adding and deleting, print how many users are there in the list. The count shall be retrieved by calling int getUsersCount() defined in UserService class.   Create a method User[] getUsers(int... ids) in UserService that shall retrieve all users from the users ArrayList and return them by making an Array of those objects. Take ids from user. Definiltey, you shall give an option for this and get required number of inputs. In main method, you shall print the names and IDs of the returned users.   Add another menu option in menu, "Press to search by city name". Get city name from user input and show all users who belong to that city. It shall be done calling a method a ArrayList searchByCityName(String city) defined in UserService class. In body of this method, you shall iterate all users stored in users ArrayList and filter those where the city name matches with parameter value. You shall add all matching users in an ArrayList and return. The main method shall print IDs and names of those users.   Create a method void printUserCountByCityName() in UserService class that shall print unique city name and numbers of users that belong to each city: e.g. Lahore - 4 users Karachi - 6 users and so Add approppriate option to invoke this operation in menu.

Question
Develop a menu driven application that shall allow user to choose different option numbers to add, search, update and delete users in an ArrayList object. Make a UserService class and implement different methods to perform each operation. These methods shall be called from main metod of UserServiceTest class. The ArrayList shall be defined as private instance variable in UserService, of type ArrayList<User> named users.
 
The User class shall be composed of id, name and city fields. Define a constructor in User class that shall take and initialize id and name fields. Initialize the city field using setCity method. When user choose an option number for search, you shall take a string from user and list all those users id, name ad city where given string appears in user name or city (use some method of String class or StringUtils class from Apache Commons library to match sub-string for search). Search operation shall be performed by a method in UserService class, ArrayList<User> search(String searchString), the method shall be called from UserServiceTest class where menu logic shall be implemented.
 
When user choose to add a new user, get name and city from user input (id shall be auto-incremented for each object, starting from 1). After getting the data, ask user at what index the object shall be added. You shall call void add(User user, int index) method defined in UserService class to add new user object at given index. If user enters an invalid index (i.e. => ArrayList size), show an error message and retake the index from user. After adding the user in ArrayList, show generated id for the added user. e.g. "User added with id 3". If users enters negative value for index, then add the user object as last element in the ArrayList.
 
When user choose to update user, get user id as input. Define User getUser(int userID) method in UserService class that shall return the user with given user ID. You shall display the current name and city of the user and let him/her update by getting updated name and city from input. Update both fields of that object in ArrayList. Do not change the user ID. To update, you shall call void updateUser(int userID, String newName, String newCityName).
 
When user choose to delete an object from the ArrayList, get user ID as input. Pass that id to UserService deleteUser method (boolean deleteUser(int userID), the method shall first search the ArrayList where that user is stored. Once you searched its index, remove that user from the ArrayList object. If no user exist with the specified ID, the method shall return false to indicate that no user was found inside the ArrayList with specified ID.
 
After adding and deleting, print how many users are there in the list. The count shall be retrieved by calling int getUsersCount() defined in UserService class.
 
Create a method User[] getUsers(int... ids) in UserService that shall retrieve all users from the users ArrayList and return them by making an Array of those objects. Take ids from user. Definiltey, you shall give an option for this and get required number of inputs. In main method, you shall print the names and IDs of the returned users.
 
Add another menu option in menu, "Press <n> to search by city name". Get city name from user input and show all users who belong to that city. It shall be done calling a method a ArrayList<User> searchByCityName(String city) defined in UserService class. In body of this method, you shall iterate all users stored in users ArrayList and filter those where the city name matches with parameter value. You shall add all matching users in an ArrayList and return. The main method shall print IDs and names of those users.
 
Create a method void printUserCountByCityName() in UserService class that shall print unique city name and numbers of users that belong to each city: e.g.
Lahore - 4 users
Karachi - 6 users
and so
Add approppriate option to invoke this operation in menu.

Expert Answer

1 Rating

Want to see the step-by-step answer?

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.
Tagged in
Engineering
Computer Science

Programing Language

Java

Related Computer Science Q&A

Find answers to questions asked by students like you.

Q: Computer Science Question

A: A function is a group of statements that together perform a task. Every C program has at least one f...

Q: 1 Insert the following customer into the CUST_MYSQL table, allowing the AUTO_INCREMENT attribute set...

A: insert into CUSTOMER(CUST_LNAME, CUST_FNAME, CUST_BALANCE)values('Powers', 'Ruth', 500);

Q: Problem 63 Write a query to display the checkout number, book number, patron ID, checkout date, and ...

A: a query to display the checkout number, book number, patron ID, checkout date, and the due date for ...

Q: Suppose G is a connected undirected graph. An edge e whose removal disconnects the graph is called a...

A: Bridge is an edge whose end vertex removal disconnects the graph so removal of that edge will also d...

Q: Write a C++ program that can ask the user to enter a four-digit number. You need to create a functio...

A: Introduction of the Program: The C++ Program takes a 4 digit number as input from the user and then ...

Q: Cache memory is an important component

A: Cache memory is a computer part based on a chip that allows retrieving data in an effective and easy...

Q: NOTES : In C Language Use basic code, dont use return, void, ect. Dont Use Stdlib.h library, use bas...

A: without stdlib we can use printf function in  the following format //Declare the printf() function i...

Q: Using Java Create a text file using the following books: And Then It's Spring  Baby Bear Sees Blue  ...

A: EXPLANATION: - The classes present in the io package named BufferedWriter, File, FileWriter, and IO...

Q: Your roommate Chris uses your computer at night while you sleep. Your roommate Robin takes your car ...

A: Similarities between two events:  Both Chris and Robin are using your things without taking any perm...

Q: Write pseudocode and Python code  Design a program that computes pay for employees. Allow a user to ...

A: This can be done using different lists for each of the attribute tax percent, tax amount, gross pay,...

Q: Data Structure and algorithms   ( in Java ) Please solve it urgent basis: Make a programe in Java an...

A: Answer in step2

Q: Problem 22 Insert the following customer into the CUST_MYSQL table, allowing the AUTO_INCREMENT attr...

A: Insert the following customer into the CUST_MYSQL table, allowing the AUTO_INCREMENT attribute set u...

Q: Write a C code that does the following: It asks the user to enter the number of hours they have work...

A: //Python code def computepay(h,r): if h&lt;=40: Pay=hr else: Pay=40r+(h-40)1.5r return Pay hrs=input...

Q: 1 The performance of hash table O A Related to the method of handling conflicts, not the length of t...

A: Based on our rules, we should answer only the first question when multiple questions are posted. Ple...

Q: In Python When analyzing data sets, such as data for human heights or for human weights, a common st...

A: Actually, python is a easiest programming language. It is a dynamically typed programming language. ...

Q: Given the following business scenario, create a Crow's Foot ERD using a specialization hierarchy if ...

A: Given: An organization requires arranging employees and their insurance dependents' details in prope...

Q: Write an Algorithm using a queue to compress a string by deleting all the space characters in the st...

A: Algorithm provided in step2

Q: Write a C/C++ program to count the total number of alphabet-, numeric- or special characters in a st...

A: #include &lt;iostream&gt; #include &lt;string&gt; using namespace std; void countDetails(string s){ ...

Q: in python  Code the circuit below.  Write the code as blocks in functions that will perform each gat...

A: Answer ins step2

Q: the classic recursion examples are the factorial program and fibonacci numbers discuss other uses we...

A: Step 1:-   Recursion Function:-   Recursion Function is defined as a function that calls itself agai...

Q: Subject: Online Social Network Analysis Textbook: Social Media Mining - Zafrani Topic: Information D...

A: Click to see the answer

Q: Write a code in python. Write down only the methods that are required; testers are not required. Co...

A: Answer in step2

Q: This is an algorithmic graph problem. Consider a set of movies M1, M2, ... , Mk. There is a set of c...

A: In this We can model this problem with the help of a graph. As you can see that Each node represents...

Q: C + +   Project Description   The Lo Shu Magic Square The Lo Shu Magic Square is a grid with 3 rows ...

A: #include&lt;iostream&gt;#include &lt;algorithm&gt;using namespace std;// Global constantsconst int R...

Q: Create student object class (Student.java) Student objects should have the following attributes: s...

A: First Make a directory named Package and place files Student.java and Course.java inside it. I have ...

Q: Write a C++ program that displays product of all odd numbers from 31 to 75 using while loop.

A: Odd numbers are generally of form 2n-1 All odd numbers differ by 2 So, step value is 2 Initial value...

Q: Write a program that takes the input of the number of rows and then prints the diamond for the given...

A: Program Approach: Define method diamond and pass row as an argument in it. Variable a is declared t...

Q: Discuss the potential risks of data at rest and data in transit, giving examples of what you think c...

A: Solution : (1st part ) Data is at rest: So when we are talking about the data at rest so the data is...

Q: 3. What is the hash table based on to determine the storage address of an element? O A The ordinal n...

A: Please find the answer below :

Q: Write a program whose input is two integers. Output the first integer and subsequent increments of 5...

A: Please Indent the code as shown in the picture below :

Q: Tasks Review the peronal traner fact-finding summary and draw an ERD with cardinality notation. Assu...

A: Personal Trainer Entity Relationship Diagram (ERD) the basic purpose involved in the personal train...

Q: 1. Use the RAND function and the Copy command to generate 100 random numbers. a. What fraction of th...

A: import random print("Printing random number using random.random()") print(random.random()) list = [2...

Q: Complete this program to read in each of the four scores as float values, multiply each score by its...

A: As per our policy, we are supposed to answer one question per question and kindly resubmit the remai...

Q: Question#3.Write a Python program to reverse a stack using recursion. Problem Solution Hints: 1. Cre...

A: Step 1:- Program Approach:-   1.Declare the Class stack 2.Declare user-defined function/method 3.Use...

Q: Calculate GCD (414,662) using Euler'sTheorem

A: The GCD of two numbers is obtained by calculating the remainder obtained when divided both numbers a...

Q: 7 In BST, the keyword of each node is larger than that of left child and smaller than that of right ...

A: In BST, for each node, the values of its left child nodes are less than that of the current node, wh...

Q: Assignment: Carefully read the instructions and write a program that reads the following information...

A: Click to see the answer

Q: In C, Is there a way to evaluate an array for a value &gt; 8?  Something like: If any value in the a...

A: C program to, Create an array of integer type. Enter some data in the array. When the data in the ar...