Difference between revisions of "Assessment 2011 2"

From Progzoo
Jump to: navigation, search
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
{{Assessment 2011 2}}
 
<shell><![CDATA[
 
<shell><![CDATA[
 
import java.io.BufferedReader;
 
import java.io.BufferedReader;
Line 51: Line 52:
 
*[[Assessment 2011 2 Medium]]
 
*[[Assessment 2011 2 Medium]]
 
*[[Assessment 2011 2 Hard]]
 
*[[Assessment 2011 2 Hard]]
 +
The data file http://progzoo.net/timetable.txt contains the raw data.
 +
 
The Event class contains the following public attributes:
 
The Event class contains the following public attributes:
 
   public String id;
 
   public String id;
Line 82: Line 85:
 
<prog><![CDATA[
 
<prog><![CDATA[
 
static void doStuff(HashMap<String,Event> events){
 
static void doStuff(HashMap<String,Event> events){
   Event e = event.get("SET07102.L2");
+
   Event e = events.get("SET07102.L2");
   System.out.println(e.room);
+
   System.out.println(e.module);
 +
}
 +
]]></prog>
 +
</question>
 +
==Looping over all events in the event map==
 +
<question copyFile='timetable.txt'>
 +
To find events that match some criteria you can loop over the '''values()''' of '''events'''
 +
 
 +
<prog><![CDATA[
 +
static void doStuff(HashMap<String,Event> events){
 +
  for(Event e:events.values()){
 +
    if (e.module.equals("SET07102"))
 +
      System.out.println(e.day+" "+e.start);
 +
  }
 
}
 
}
 
]]></prog>
 
]]></prog>
 
</question>
 
</question>

Latest revision as of 19:03, 1 November 2011

Assessment 2 2011
Easy
Medium
Hard

The data file http://progzoo.net/timetable.txt contains the raw data.

The Event class contains the following public attributes:

 public String id;
 public String module;
 public String etype;
 public String day;
 public String start;
 public int duration;
 public String weeks;
 public String room;
 public String staff;
 public ArrayList<String> students;

An example event is given in the table:

 id       SET07102.P2a
 module   SET07102
 etype    Practical
 day      Wednesday
 start    14:00
 duration 2
 weeks    2-13
 room     M.Kilby.C09
 staff    Co.Set.Chisholm, Ken
 students Co.Cc1f-A       Co.Cc1f-B

The structure events is supplied for most questions. This is a HashMap that relates the event id to the event object.

Looking up events in the event map

If you know the event id you can use get to retrieve the Event object associated.

You access the public members of the object using dot notation.


[Font] [Default] [Show] [Resize] [History] [Profile]

Looping over all events in the event map

To find events that match some criteria you can loop over the values() of events


[Font] [Default] [Show] [Resize] [History] [Profile]