Created
March 21, 2016 15:44
-
-
Save sfpprxy/0c41332b1f17989010a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package andy; | |
import java.lang.reflect.Array; | |
import java.util.Date; | |
/** | |
* This class is used to test Operations methods | |
* @author (enter your name here) | |
* @version (date) | |
*/ | |
public class EventOperationsMain | |
{ | |
public static void main(String[] args) | |
{ | |
// Print start-of-testing timestamp | |
System.out.println("\n*** Begin testing on " + new Date()); | |
// Create new concrete class implementing EventList interface for testing | |
// populate it with at least 25 layout objects... | |
// Test implemented EventList methods add(), remove() and get() | |
System.out.println("\n** Begin testing event list methods"); | |
EventSchedule myEvent = new EventSchedule(); | |
myEvent.add("Conference", "A", "a", new Date(), 1); | |
myEvent.add("Conference", "B", "b", new Date() , 2); | |
myEvent.add("Trade Fair", "C", "c", new Date() , 3); | |
myEvent.add("Trade Fair", "D", "d", new Date() , 4); | |
myEvent.add("Concert", "E", "e", new Date() , 5); | |
myEvent.add("Concert", "F", "f", new Date() , 6); | |
myEvent.add("Conference", "G", "g", new Date() , 7); | |
myEvent.add("Conference", "H", "h", new Date() , 8); | |
myEvent.add("Trade Fair", "I", "i", new Date() , 9); | |
myEvent.add("Trade Fair", "J", "j", new Date() , 10); | |
myEvent.add("Concert", "K", "k", new Date() , 11); | |
myEvent.add("Concert", "L", "l", new Date() , 12); | |
System.out.println(myEvent); | |
System.out.println("\n** Finish testing event list methods"); | |
EventHelper help = new EventHelper(); | |
help.generateEventID(); | |
// Test implemented EventList method sort() | |
System.out.println("\n** Begin testing sort method"); | |
System.out.println("\n*** Finish testing sort method"); | |
System.out.println("\n*** Finish testing on " + new Date()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package andy; | |
import java.awt.*; | |
import java.util.ArrayList; | |
import java.util.Collection; | |
import java.util.Collections; | |
import java.util.Date; | |
/** | |
* Created by Andy on 2016/3/20. | |
*/ | |
public class EventSchedule implements EventList { | |
private ArrayList<NEC_Event> mylist = new ArrayList<NEC_Event>(); | |
/** | |
* Adds an event to the List, if its not already there | |
* @param name string the name of the event | |
* @param layout string layout configuration of the event | |
* @param ID | |
* @param date Date date object (must be > the current date) | |
* @param hall int hall number (must be <0 <= 20) @return true if successful, else false | |
* @throws NullPointerException if name, type, ID, date are null | |
*/ | |
@Override | |
public boolean add(String name, String layout, String ID, Date date, int hall) throws NullPointerException | |
{ // need to check for null and throw NPE | |
if (name == null) | |
throw new NullPointerException("add: name is null"); | |
if (layout == null) | |
throw new NullPointerException("add: layout is null"); | |
if (ID == null) | |
throw new NullPointerException("add: ID is null"); | |
// if (date.before(new Date()) ) | |
// throw new NullPointerException("add: date is null"); | |
if (hall > 20) | |
throw new NullPointerException("add: date is null"); | |
mylist.add(new NEC_Event(name, layout, ID, date, hall)); | |
return true; | |
} | |
/** | |
* Remove an event from the list | |
* @param id string the id of the event to remove | |
* @return true if successful, else false | |
* @throws NullPointerException if id is null | |
*/ | |
@Override | |
public boolean remove(String id) | |
{// need to check for null and explicitly throw NPE | |
if ( id == null) throw new NullPointerException("EventSchedule.remove"); | |
return mylist.remove(id); //returns false if id not found | |
} | |
/** | |
* Get an event given the event's id | |
* @param id string the event's id string | |
* @return the event if found, else null | |
*/ | |
@Override | |
public NEC_Event get(String id) throws NullPointerException | |
{ | |
return null; | |
} | |
/** | |
* Get the size of the list (number of events) | |
* @return the list size | |
*/ | |
@Override | |
public int size() | |
{ | |
return mylist.size(); | |
} | |
/** | |
* Convert the list to a single string "nS0\nS1\nS2\n..." | |
* @return a printable string formatted as above | |
*/ | |
@Override | |
public String toString() | |
{ | |
return mylist.toString(); | |
} | |
/** | |
* Sort the list of event into ascending order by ID | |
* @return true if successful, else false | |
*/ | |
@Override | |
public boolean sort() | |
{//sort the arrayList | |
Collections.sort(mylist); | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment