Question: ListInterface Class import java.util.*; public interface ListInterface extends CollectionInterface , Iterable { void add(int index, T element); // Throws IndexOutOfBoundsException if passed an index argument

ListInterface Class
import java.util.*;
public interface ListInterface
CollectionInterface
public interface CollectionInterface
T get(T target); // Returns an element e from this collection such that e.equals(target). // If no such e exists, returns null.
boolean contains(T target); // Returns true if this collection contains an element e such that // e.equals(target); otherwise returns false.
boolean remove (T target); // Removes an element e from this collection such that e.equals(target) // and returns true. If no such e exists, returns false.
boolean isFull(); // Returns true if this collection is full; otherwise, returns false.
boolean isEmpty(); // Returns true if this collection is empty; otherwise, returns false. int size(); // Returns the number of elements in this collection. }
ArrayCollection Class
public class ArrayCollection
// set by find method protected boolean found; // true if target found, otherwise false protected int location; // indicates location of target if found
public ArrayCollection() { elements = (T[]) new Object[DEFCAP]; }
public ArrayCollection(int capacity) { elements = (T[]) new Object[capacity]; }
protected void find(T target) // Searches elements for an occurrence of an element e such that // e.equals(target). If successful, sets instance variables // found to true and location to the array index of e. If // not successful, sets found to false. { location = 0; found = false;
while (location
public boolean add(T element) // Attempts to add element to this collection. // Returns true if successful, false otherwise. { if (isFull()) return false; else { elements[numElements] = element; numElements++; return true; } }
public boolean remove (T target) // Removes an element e from this collection such that e.equals(target) // and returns true; if no such element exists, returns false. { find(target); if (found) { elements[location] = elements[numElements - 1]; elements[numElements - 1] = null; numElements--; } return found; } public boolean contains (T target) // Returns true if this collection contains an element e such that // e.equals(target); otherwise, returns false. { find(target); return found; }
public T get(T target) // Returns an element e from this collection such that e.equals(target); // if no such element exists, returns null. { find(target); if (found) return elements[location]; else return null; } public boolean isFull() // Returns true if this collection is full; otherwise, returns false. { return (numElements == elements.length); }
public boolean isEmpty() // Returns true if this collection is empty; otherwise, returns false. { return (numElements == 0); }
public int size() // Returns the number of elements in this collection. { return numElements; } }
Cities
Philadelphia pivot city
Boston
New York
Washington DC
Atlanta
Description: In this lab, you will be practicing the use of the built in List libraries in java.util including ArrayList, List, and Collections. I provide you with template classes which you will modify to find the distance between Philadelphia and a list of other cities. Your goal is to compute travel plans from Philadelphia to each provided city, sort the plans by distance, then print the results The following imports should already be included in your java file: import java.util.ArrayList; import java.util.List; import java.util.Collections; First, implement the City constructor. The constructor should simply set the fields (name, longitude and latitude), of the city class with the values of the constructor argument Next, implement the constructor for the TravelPlan class. The origin, destination, and dis- tance should be set in this constructor. To find the distance between two points, use the Euclidean distance formula. The Euclidean distance between two points P = (x,y)and Q = (a, b) in space is defined as d(P, )- V(x use the Math library located in java.lang. (does not need to be imported). Relevant functions would be Math.pow and Math.sqrt x - a)2 + (y - b)2. If you would like to use built in commands, you may Next, override the toString method to print out the origin, destination, and distance, and the compareTo method to compare the objects of the class based upon distance Finally, finish the file lab11.java by storing the distance between Philadelphia and each of the other provided cities in an generic ArrayList of TravelPlan objects. Sort the list of TravelPlan objects using the Collections.sort static method. Finally, print the list to see the Travel Plans in order of shortest trip to longest. To submit the lab, create a zip folder containing the files City.java, TravelPlan.java, and lab11.java and subt t on Blackboard Kubric: Compiles without errors City class correctly implemented TravelPlan class correctly implemented driver program correctly implemented
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
