Could someone explain where the inputs would come from in this skeleton code.
The skeleton code is as follows:
Data.java
import java.util.Date;
import java.util.List;
public interface Data {
// Return a list of all appointments at the given location (at any time)
// If there are no such appointments, return an empty list
// Throws IllegalArgumentException if the argument is null
public List<Schedule> getSchedule(String location);
// Return the next appointment at or after the given time (in any location)
// If there is no such appointment, return null
// Throws IllegalArgumentException if the argument is null
public Schedule getNextSchedule(Date when);
// Return the next appointment at or after the given time, at that location
// If there is no such appointment, return null
// Throws IllegalArgumentException if any argument is null
public Schedule getNextSchedule(Date when, String location);
// Create a new appointment in the calendar
// Throws IllegalArgumentException if any argument is null
public void add(String description, Date when, String location);
// Remove an appointment from the calendar
// Throws IllegalArgumentException if the argument is null
public void remove(Schedule schedule);
}
Calendar.java
import java.util.Date;
import java.util.List;
public class Calendar implements Data {
// We will use this when we test
public Calendar() {
}
@Override
public List<Schedule> getSchedule(String location) {
// TODO
return null;
}
@Override
public Schedule getNextSchedule(Date when) {
if(when == null) {
throw new IllegalArgumentException("time was null");
}
// TODO
return null;
}
@Override
public Schedule getNextSchedule(Date when, String location) {
// TODO
return null;
}
@Override
public void add(String description, Date when, String location) {
// TODO
}
@Override
public void remove(Schedule schedule) {
// TODO
}
}
Schedule.java
import java.util.Date;
public interface Schedule {
public String getDescription();
public String getLocation();
public Date getStartTime();
}
I would also like to know:
- where to start, I attempted to start but I am unsure what to return in the first todo section labeled getSchedule. I know I can't return location because the method calls for a List type(?) to be returned.
The <> are used in Classes like Collections and Maps. means, that there is a Collection (for example an ArrayList) which can contain elements of the type Schedule. If you have a Map like a HashMap then you need to put 2 Types in these <>: The Key (for example Integer) and the Object (for example String)
Now you can get an Element from the Map using
This method returns a instance of the Type Schedule whith the key 7, stored in an Integer. You have to use Integer instead of int because a Map or List can't contain the simple Types like int, double, boolean.
Now to your problem: before you can return something in the method getSchedule(String location) you need to have a List to store your Schedules like this:
then you can iterate the list in the method getSchedule(String location) and write all entries with the right loation in another list and return it:
You wrote you wanted to use HashTrees. I think it's better and faster if you just use an ArrayList. Yes, you can put HashTrees in a specific order, but it's much more complicated and it works with Lists too.
Antilog