Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

06. Sixth Assignment Creating Lists Currently in our Facebook application, the first option in the driver program lists the users in some arbitrary order. In

06. Sixth Assignment Creating Lists

Currently in our Facebook application, the first option in the driver program lists the users in some arbitrary order. In this assignment you will split that into two options one to list users alphabetically by username and the other to list them based on the number of friends they have (from most to least). When you list users alphabetically, list them from smallest to largest and ignore capitalization. For example, Alice should come before Bob who should come before Charlie. In addition, the Recommend friends options currently lists the recommendations in an arbitrary order. Change this so that the recommendations are listed according to the number of friends each person already has, from most to least.

The menu displayed to the user will now look like the one below, and you will be implementing options 1 and 2 and tweaking the implementation of option 9. (The code for the rest of the options will stay the same as it was for previous assignments.)

Menu

  1. List users alphabetically
  2. List users by number of friends
  3. Add a user
  4. Delete a user
  5. Get password hint
  6. Add a friend
  7. Remove a friend
  8. List friends
  9. Recommend friends
  10. Quit

There are several ways to accomplish the assignment, and you are free to use whichever approach you feel most comfortable with. If youre at a loss for ideas, consider that the Collections class has a sort method that will take any List and a Comparator and sort the objects accordingly. This is described in chapter 22 of your textbook. Comparators are also discussed in the video for this topic.

You will be graded according to the following rubric (each item is worth one point):

  • The driver menu contains the two new options
  • The program will list users based on their username
  • The username listing is lexicographic order, from smallest to largest
  • The username listing is case insensitive
  • The program will list users based on the number of friends they have
  • The listing based on number of friends is ordered from most to least
  • Friend recommendations are listed in order of the number of friends each person already has, from most to least
  • The program compiles
  • The program runs
  • The program is clearly written and uses standard coding conventions
  • Note: If your program does not compile, you will receive a score of 0 on the entire assignment
  • Note: If you program compiles but does not run, you will receive a score of 0 on the entire assignment
  • Note: If your Eclipse project is not exported and uploaded to the eLearn drop box correctly, you will receive a score of 0 on the entire assignment
  • Note: If you do not submit code that solves the problem for this particular assignment, you will not receive any points for the programs compiling, the programs running, or following standard coding conventions.

Here is what i have so far

Here is the Utilities.java class, I have tested the program and its working fine. Read the comments and refer the screenshot below

------------------------------------------------------------------------------------------------------------------------------------

import java.util.ArrayList; //You can write your two methods in a new class called Utilities. // it enforces only classes which implements Comparable interface public class Utilities> { //Problem 19.3 asks you to write a generic method that removes duplicate // items from an ArrayList. This should be fairly straightforward. // takes in generic ArrayList and returns list of unique values public ArrayList removeDuplicates(ArrayList list) { ArrayList uniqueList = new ArrayList(); for (T element : list) { if (uniqueList.contains(element)) { continue; } else { uniqueList.add(element); } } return uniqueList; } //Problem 19.4 asks you to implement a generic method for linear search. // method takes in a generic ArrayList of elements which implement the Comparable class // and also the element to be searched // method returns the index of the matching element // if there is no such element method will return -1 public int linearSearch(ArrayList list, T element) { for (int index = 0; index < list.size(); index++) { if (list.get(index).equals(element)) { return index; } } return -1; } public static void main(String[] args) { ArrayList names = new ArrayList<>(); names.add("Peter"); names.add("Peter"); names.add("Peter"); names.add("Peter"); names.add("John"); names.add("Jason"); names.add("John"); names.add("Jason"); Utilities utilities = new Utilities<>(); ArrayList uniqueNames = utilities.removeDuplicates(names); System.out.println("Unique names - "); for (String name : uniqueNames) { System.out.println(name); } int jasonIndex = utilities.linearSearch(names, "Jason"); int markIndex = utilities.linearSearch(names, "Mark"); System.out.println("Jason found at index: "+jasonIndex); System.out.println("Mark found at index: "+markIndex); } }

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

Climate And Environmental Database Systems

Authors: Michael Lautenschlager ,Manfred Reinke

1st Edition

ISBN: 1461368332, 978-1461368335

More Books

Students also viewed these Databases questions

Question

> - what does the tail towards the left of the north arrow suggest?

Answered: 1 week ago

Question

Solve for x: 2(3x 1)2(x + 5) = 12

Answered: 1 week ago

Question

6. Describe why communication is vital to everyone

Answered: 1 week ago