Question: =======================Java================================== completing the implementation of a program. public class Cache { // TODO: Put representation here /** * Creates a Cache from a string that
=======================Java==================================
completing the implementation of a program.
public class Cache { // TODO: Put representation here
/** * Creates a Cache from a string that consists of these seven cache attributes: the GC code, the title, the owner, * the difficulty rating, the terrain rating, the latitude, and the longitude, in that order, separated by single * TAB ('\t') characters. * * If any of the following problems are present, throws an IllegalArgumentException: *
- *
- Fewer than seven attributes *
- More than seven attributes *
- A GC code that is anything other than "GC" followed by one or more upper-case letters and/or digits *
- A difficulty or terrain rating that parses to anything other than the doubles 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, * or 5. *
- A title, owner, latitude, or longitude that consists only of white space */ public Cache (String attributes) { // TODO: Implement }
/** * Converts this cache to a string */ public String toString () { return getTitle() + " by " + getOwner(); }
/** * Returns the owner of this cache */ public String getOwner () { // TODO: Implement return ""; }
/** * Returns the title of this cache */ public String getTitle () { // TODO: Implement return ""; }
/** * Returns the difficulty rating of this cache */ public double getDifficulty () { // TODO: Implement return 1.0; }
/** * Returns the terrain rating of this cache */ public double getTerrain () { // TODO: Implement return 1.0; }
/** * Returns the GC code of this cache */ public String getGcCode () { // TODO: Implement return ""; }
/** * Returns the latitude of this cache */ public String getLatitude () { // TODO: Implement return ""; }
/** * Returns the longitude of this cache */ public String getLongitude () { // TODO: Implement return ""; } }
public class CacheList { // The caches being managed by this CacheList. They are arranged in // ascending order according to cache title. private ArrayList allCaches;
// TODO: Put remainder of representation here
/** * Creates a CacheList from the specified Scanner. Each line of the Scanner should contain the description of a * cache in a format suitable for consumption by the Cache constructor. The resulting CacheList should contain one * Cache object corresponding to each line of the Scanner. * * Sets the initial value of the title and owner constraints to the empty string, sets the minimum difficulty and * terrain constraints to 1.0, and sets the maximum difficulty and terrain constraints to 5.0. * * Throws an IOException if the Scanner throws an IOException, or an IllegalArgumentException if any of the * individual lines are not appropriate for the Cache constructor. * * When an IllegalArgumentException e is thrown, e.getMessage() is the number of the line that was being read when * the error that triggered the exception was encountered. Lines are numbered beginning with 1. */ public CacheList (Scanner caches) throws IOException { // TODO: Complete this implementation allCaches = new ArrayList();
// Sort the list of caches Collections.sort(allCaches, (c1, c2) -> c1.getTitle().compareToIgnoreCase(c2.getTitle())); }
/** * Sets the title constraint to the specified value. */ public void setTitleConstraint (String title) { // TODO: Implement }
/** * Sets the owner constraint to the specified value. */ public void setOwnerConstraint (String owner) { // TODO: Implement }
/** * Sets the minimum and maximum difficulty constraints to the specified values. */ public void setDifficultyConstraints (double min, double max) { // TODO: Implement }
/** * Sets the minimum and maximum terrain constraints to the specified values. */ public void setTerrainConstraints (double min, double max) { // TODO: Implement }
/** * Returns a list that contains each cache c from the CacheList so long as c's title contains the title constraint * as a substring, c's owner equals the owner constraint (unless the owner constraint is empty), c's difficulty * rating is between the minimum and maximum difficulties (inclusive), and c's terrain rating is between the minimum * and maximum terrains (inclusive). Both the title constraint and the owner constraint are case insensitive. * * The returned list is arranged in ascending order by cache title. */ public ArrayList select () { // TODO: Complete this implementation ArrayList caches = new ArrayList(); return caches; }
/** * Returns a list containing all the owners of all of the Cache objects in this CacheList. There are no duplicates. * The list is arranged in ascending order. */ public ArrayList getOwners () { // TODO: Complete this implementation ArrayList owners = new ArrayList();
// Sort the list of owners Collections.sort(owners, (s1, s2) -> s1.compareToIgnoreCase(s2)); return owners; } }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
