CS 5004, Spring 2023
Refer to Canvas for assignment due dates for your section. Objectives: ● Implement and test a mutable ADT. ● Implement and test an immutable ADT.
Create a new Gradle project for this assignment in your course GitHub repo. Make sure to follow the instructions provided in “Using Gradle with IntelliJ” on Canvas.
Create a separate package for each problem in the assignment. Create all your files in the appropriate package.
To submit your work, push it to GitHub and create a release. Refer to the instructions on Canvas. Your repository should contain: ● One .java file per Java class. ● One .java file per Java test class. ● One pdf or image file for each UML Class Diagram that you create. UML diagrams can be generated using IntelliJ or hand-drawn. ● All non-test classes and non-test methods must have valid Javadoc.
Your repository should not contain: ● Any .class files. ● Any .html files. ● Any IntelliJ specific files.
Implement an ADT called NationalParkDirectory—an ordered, mutable collection, which will be used by the Department of Interior, to keep track of information about of the country’s national parks. This information will include resources about destinations and amenities, lodging, camping, permits and lotteries, as well as relevant information about the current conditions in each park.
A NationalPark class has already been written to store information about each national park (download it from the Canvas page for this assignment). The ADT will need to support the following functionality.
- Boolean isEmpty(): checks whether or not the NationalParkDirectory is empty.
- Integer count():gets the number of NationalParks in the NationalParkDirectory.
- Boolean contains(NationalPark): checks if the provided NationalPark exists in the NationalParkDirectory.
- void addNationalPark(NationalPark park): adds a new NationalPark to the NationalParkDirectory. Please note that NationalParkDirectory does not allow duplicate NationalParks, but it allows information about some NationalPark to change. So, if a NationalPark already exists in the NationalParkDirectory, method add() will replace the existing values of the NationalPark’s fields with the newly provided information.
- void removeNationalPark(NationalPark park): removes a specified NationalPark from the NationalParkDirectory. If the NationalPark does not exist in the NationalParkDirectory, the system should throw NationalParkNotFoundException, which you will have to implement yourself.
- NationalParks findParksWithinTheState(String state): finds and returns all NationalParks from the NationalParkDirectory that are located within the state provided as an input argument. NationalPark getParkByID(String nationalParkID): gets a NationalPark from the NationalParkDirectory based upon the NationalPark’s unique identifier, nationalParkID. The system throws an InvalidNationalParkIDException if the given unique ID doesn’t exist. You are expected to implement InvalidNationalParkIDException for yourselves.
Specify this ADT in an interface and implement it as well as any other classes needed to satisfy the specification. You should also implement toString, equals, and hashCode for this ADT. You may not use any built-in Java collections, other than arrays, as the underlying data structure. Please do not modify the provided NationalPark class.
Provide the design and implementation of a Set, as in the mathematical notion of a set. Here is the specification:
Set emptySet(): Creates and returns an empty Set.
Boolean isEmpty(): Checks if the Set is empty. Returns true if the Set contains no items, false otherwise.
Set add(Integer n): Adds the given Integer to the Set if and only if that Integer is not already in the Set.
Boolean contains(Integer n): Returns true if the given Integer is in the Set, false otherwise.
Set remove(Integer n): Returns a copy of the Set with the given Integer removed. If the given Integer is not in the Set, returns the Set as is.
Integer size(): Gets the number of items in the Set.
Your implementation of equals(Object o) should return true if and only if the two sets have the same number of elements and, for every element in this, the same element exists in o and vice versa. Ensure that your implementations of hashCode() and equals() satisfy the contracts for both methods.
You may not use any built-in Java collections, other than arrays, as the underlying data structure. As the specification suggests, your implementation should be immutable. Make sure your implementations for both problems are thoroughly tested. Please also provide UML diagrams.