Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a Class called Chapter11.java with public static methods that provide solutions to the following: In all cases, your methods also must handle empty (but

Create a Class called Chapter11.java with public static methods that provide solutions to the following:

In all cases, your methods also must handle empty (but not null) Collections.

When two Collections are passed in as parameters, consider they could be the same Collection (e.g. method(set1, set1)).

And in all of these I will use CalendarDate.javaimage text in transcribedimage text in transcribed as the generic Comparable E.

At least one of the solutions here (you pick it) must use anIterator for your solution.

A. Write a method named partition that accepts a List of CalendarDates and a CalendarDate value E as its two parameters, and rearranges (partitions) the list so that all its elements less than E occur before all elements greater than E. The exact order of the elements is unimportant so long as all elements less than E appear before all elements greater than or equal to E. For example, for the list [1/6, 1/2, 3/9, 4/1], one acceptable ordering of the list after the call of partition(list, 1/5) would be [1/2, 3/9, 4/1, 1/6].

B. Write a method named sortAndRemoveDuplicates that accepts a List of CalendarDates as its parameter and rearranges the list's elements into sorted ascending order, as well as removing all duplicate values from the list. For example, the list [1/7, 1/4, 1/4] would become [1/4, 1/7] after a call to your method.

C. Write a method called symmetricSetDifference that accepts two Sets as parameters and returns a new Set containing their symmetric set difference (that is, the set of elements contained in either of the two sets but not in both). For example, the symmetric difference between the set1 [1/1, 2/2, 3/3, 4/4] and set2 [1/2, 2/2, 2/3] will be found from symmetricSetDifference(set1,set2); which returns [1/1, 1/2, 3/3, 2/3, 4/4]. Order of elements will not matter.

D. Write a method called reverse that accepts a Map and returns a new Map that is the reverse of the original, meaning the new Map uses values from the original as the new keys, and the keys from the original as its values. In other words, for the original Map, the new map must reverse these around and map keys of type String to values that are Sets containing elements of type CalendarDate. For example, the Map {4/2=April, 8/1=August, 1/7=January, 4/22=April, 8/5=August} has a reverse of {April=[4/2, 4/22], August=[8/1, 8/5], Januray=[1/7]}. The order of the data does not matter.

I will test your class with code like this (plus 10x more):

List test = new Vector(); Chapter11.sortAndRemoveDuplicates(test);

So public static methods must be created.

Submit one Java Class, named Chapter11.java

CalendarDate.java

public class CalendarDate implements Comparable { private int month; private int day;

public CalendarDate(int month, int day) { this.month = month; this.day = day; }

// Compares this calendar date to another date. // Dates are compared by month and then by day. public int compareTo(CalendarDate other) { if (this.month != other.month) { return this.month - other.month; } else { return this.day - other.day; } }

public int getMonth() { return this.month; }

public int getDay() { return this.day; }

public String toString() { return this.month + "/" + this.day; } }

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

Beginning Databases With PostgreSQL From Novice To Professional

Authors: Richard Stones, Neil Matthew

2nd Edition

1590594789, 978-1590594780

More Books

Students also viewed these Databases questions

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago