Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA Using the class Person defined below create a class Friends that manages a list of Person. This class should have the following methods: add(Person

JAVA

Using the class Person defined below create a class Friends that manages a list of Person. This class should have the following methods:

add(Person p) add new person to set;

search(Person p) returns true if p is a member of the set of friends, false otherwise;

size() returns number of friends

getSurname(String s) returns a set of just those persons whose surname is s;

getFirstname(String f) - returns a set of just those persons whose surname is f;

getFreq(String f) returns number of persons whose first name is f;

del(Person p) remove person p if present;

sort() returns a sorted list of Person.

You may use a ArrayList or a LinkedList for your collection of Person. Please full working implementation with the main method that prints results of all methods.

final class Person implements Comparable{

private final String sName;

private final String fName;

Person(String fn, String sn){fName = fn; sName = sn;}

public String sName(){return sName;}

public String fName(){return fName;}

public String toString(){return fName+" "+sName;}

public boolean equals(Object ob){

if(!(ob instanceof Person)) return false;

Person p = (Person)ob;

return sName.equals(p.sName) && fName.equals(p.fName);

}

public int compareTo(Person p){

if(p == null) return -1;

if(this.equals(p)) return 0;

return sName.compareTo(p.sName);

}

public int hashCode(){

return 41 * sName.hashCode() * fName.hashCode();

}

}

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

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago