CSBP 319 Data structures

A company would like to implement its inventory of smartphones as a doubly-linked list, called MobileList. 

 

1. Write a Mobile node class, called MobileNode, to hold the following information about a smartphone: 

• code (as a String) 

• brand (as a String) 

• model (as a String) 

• price (as int) 

 

MobileNode should have constructors and methods (getters, setters, and toString()) to manage the above information as well as the link to next and 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.  

• The MobileList class should implement the following interface: 

 

public interface MList { 

 public boolean isEmpty(); 

// returns true if the list is empty, false otherwise 

 

public int size(); 

// returns the number of items in the list 

     

public MobileNode getNodeAt(int index); 

//returns the MobileNode object at the specified index  

 

public void addFirst(MobileNode item); 

// adds a Mobile node at the front of the list 

 

public void addLast(MobileNode item); // adds a Mobile node at the end of the list 

 

public void addAt(int index, MobileNode item); // adds a Mobile node to the list at the given index 

 

public String removeAt(int index); 

// removes the Mobile node from the list that has the given // index  

public String remove(MobileNode item); 

// removes the first item in the list whose data equals  // the given item data 

 

public MobileNode[] searchPriceGreaterThan(int p); 

//search and return an array of the set of MobileNode items  

//having a price greater than p 

 

public double averagePrice(); 

// return the average price of the mobile nodes in the list 

 

public double averageBrandPrice(String brand); 

// return the average price of the mobile nodes in the list 

// from the brand given as a parameter (e.g., “Samsung” or // “samsung”) 

 

 

@Override 

public String toString(); 

// implement a toString() method that prints the list in the // format: 

//[ size: the_size_of_the_list 

// Mobile node1,  

// Mobile node2,  

//.... ] 

 

 

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 10 MobileNode objects into the created list (from some brands like “Apple”, “Samsung”, “Huwaei”, “Sony”),  

• Print the content of your list,  

• Find out in the list the items that have a price greater than 3000. Print them out.  

• Remove the first element of the list 

• Remove the item at index 3 

• Print again the content of your ist,  

• Print out the average price of all mobiles in the list 

• Print out the average price of all mobiles in the list from “Apple”. 

 

For each operation above, print a small message that describes the operation you are doing. 

For example: 

System.out.println(“Insertion of 10 Mobile nodes in the list”); 

 

 

 

Submission Guidelines 

• Make sure your MobileList class implements the interface as specified, i.e. your class should 

begin with public class MobileList implements MList. 

• Submit your netbeans project file (with .zip extension) that contains the 3 java classes: MobileNode.java, MobileList.java, and TestMobileList.java.  The 3  classes should be in a package called: 

csbp319.assignment1 

   Your submitted file should be: 

YourID_csbp319_51_assignment1.zip 

• Put your ID and name at the top of each of the above 3 files. I will be testing your code, so make sure your code runs correctly.

Need a custom answer at your budget?

This assignment has been answered 4 times in private sessions.

© 2020 Codify Tutor. All rights reserved