Question
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.java as the generic Comparable E.
At least one of the solutions here (you pick it) must use anIterator
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
I will test your class with code like this (plus 10x more):
List
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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started