data structure /java code

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

data structure /java code

Post by answerhappygod »

data structure /java code
Data Structure Java Code 1
Data Structure Java Code 1 (104.33 KiB) Viewed 78 times
A Company would like to implement its catalogue of mobile phones given to its employees as a doubly linked list, called MobileList. 1. Write a class, called MobileNode, to hold the following information about a mobile phone: • mid (as a int) //mobile phone id. This id is unique. No two nodes have the same id. • brand (as a String) //apple, Samsung, Sony, Nokia, etc. • employee (as String) // the employee to whome the mobile phone was given • department (as String) // the department of the employee (e.g. Finance, Marketing, Sales, etc.) MobileNode should have constructors and methods (getters, setters, and toString() to manage the above information as well as the link to next and prev (previous) nodes in the list. 2. Write the MobileList class to hold objects of the class MobileNode. This class should define: • Two instance variables first and last to keep the reference (address) of the first and last nodes of the list. • An instance variable size that stores the size of the list. It should be updated whenever a new node is added to the list or an existing node is removed. (These are the only variables of this class). • It should implement the following interface: public interface MobileIF { public boolean isEmpty(); // returns true if the list is empty, false otherwise
public MobileNode getNodeAt (int index); 7/returns the MobileNode object at the specified index public int indexOf(int id); 1/returns the index of the MobileNode object in the list that //has the id given as a parameter(-1 if the object is //not in the list) public void setNodeAt (int index, MobileNode item); 1/modifies only the information of the node at the given index (if // it a valid index) in the list with information //from the MobileNode object given as parameter if it //is a valid object. public void addFirst (MobileNode mobile); // adds a Mobile node at the front of the list public void addLast (MobileNode mobile); 7/ adds a Mobile node at the end of the list public void addAt(int index, MobileNode mobile); 1/ adds a Mobile node to the list at the given index public String removeAt (int index); 1/ removes the mobile node at the given index from the list // and returns information of the removed node. Public ArrayList<MobileNode> departMobiles (String department); //searches and returns an arraylist of the set of MobileNode //objects used by the employees working in the department 1/given as a parameter of the method public MobileNode[] brandMobiles (String brand); 1/ returns an array of the Mobile nodes for which the //brand is equal to the brand given as a parameter of //the method. public String toString(); // implement a toString() method that prints the list in the // format: 1/[ size: the_size_of_the_list // Mobile nodel details, Tin same line) // Mobile node2 details, //....]
3. Write a TestMobileList class to test the class MobileList. This class should have a main method in which you perform the following actions: Create a MobileList object • Insert 3 Mobile Node objects at the end of the created list. • Insert 2 MobileNode objects at the front of the list, • Insert 3 Mobile Node objects at the following positions of the list respectively: 0, 2, 4 • Print the content of your list • Find out in the list the Mobiles that have the same brand as the last node of the list. Print them out. • Remove the first element of the list • Remove the item at index 3 • Print again the content of your list, • Print out the Mobiles that are used by employees of the Marketing department For each operation above, print a small message that describes the operation you are doing. For example: System.out.println("Insertion of 3 Mobile nodes at the end of the list");
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!

This question has been solved and has 1 reply.

You must be registered to view answers and replies in this topic. Registration is free.


Register Login
 
Post Reply