Changeset 206 for liacs/TOOS/assignment1


Ignore:
Timestamp:
Oct 25, 2010, 8:42:20 PM (14 years ago)
Author:
Rick van der Zwet
Message:

Some more clever java writing and hacking on checking syntax slightly properly.

Location:
liacs/TOOS/assignment1
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • liacs/TOOS/assignment1/build.xml

    r205 r206  
    1 <project>
     1<project name="Census" >
     2
     3  <property name="src.dir" value="src"/>
    24  <property name="lib.dir" value="lib" />
     5  <property name="build.dir" value="build"/>
     6  <property name="classes.dir" value="${build.dir}/classes"/>
     7  <property name="jar.dir" value="${build.dir}/jar"/>
    38  <property name="javac.includeAntRuntime" value="false" />
     9  <property name="main-class" value="nl.rickvanderzwet.toos.assignment1.Census" />
    410
    511  <path id="classpath">
     
    915
    1016  <target name="clean">
    11       <delete dir="build"/>
     17      <delete dir="${build.dir}"/>
    1218  </target>
    1319
    1420  <target name="compile">
    15       <mkdir dir="build/classes"/>
    16       <javac srcdir="src" destdir="build/classes"
     21      <mkdir dir="${classes.dir}"/>
     22      <javac srcdir="${src.dir}" destdir="${classes.dir}"
    1723        includeAntRuntime="${javac.includeAntRuntime}" classpathref="classpath">
    1824
    1925        <compilerarg value="-Xlint:unchecked" />
    2026      </javac>
     27      <copy todir="${classes.dir}">
     28          <fileset dir="${src.dir}" excludes="**/*.java"/>
     29      </copy>
    2130  </target>
    2231
    2332  <target name="jar" depends="compile">
    24       <mkdir dir="build/jar"/>
    25       <jar destfile="build/jar/Census.jar" basedir="build/classes">
     33      <mkdir dir="${jar.dir}"/>
     34      <jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
    2635          <manifest>
    27               <attribute name="Main-Class" value="Census"/>
     36              <attribute name="Main-Class" value="${main-class}" />
    2837          </manifest>
    2938      </jar>
    3039  </target>
    3140
    32   <target name="run" depends="jar">
    33       <java jar="build/jar/Census.jar" fork="true">
     41  <target name="run" depends="clean, jar">
     42      <java fork="true" classname="${main-class}">
    3443        <classpath>
    3544          <path refid="classpath" />
     45          <path location="${jar.dir}/${ant.project.name}.jar" />
    3646        </classpath>
    3747      </java>
  • liacs/TOOS/assignment1/src/Census.java

    r205 r206  
    11package nl.rickvanderzwet.toos.assignment1;
    22
     3import java.util.Calendar;
    34import java.util.HashSet;
     5import java.util.Enumeration;
     6
    47import nl.rickvanderzwet.toos.assignment1.Voter;
     8
    59import org.apache.log4j.BasicConfigurator;
    610import org.apache.log4j.Logger;
     
    1014  public static void main(String[] args) {
    1115    BasicConfigurator.configure();
     16   
     17    Census census = new Census();
     18
    1219    HashSet<Voter> voters = new HashSet<Voter>();
    1320    voters.add(new Voter(true));
    14    
    15     logger.info("Hello, world!");
     21    voters.add(new Voter(true));
     22    Voter duplicate  = new Voter(true);
     23    voters.add(duplicate);
     24    voters.add(duplicate);
     25    //voters.add(new Voter());
     26   
     27    logger.info(census.census(voters));
    1628  }
    17   public boolean census(HashSet<Voter> Voters) {
    18     return false;
     29  /**
     30   * Calculates the end-vote for a list of voters, given a certain set of creteria's:
     31   *   - No voter is allowed more than one time on the list.
     32   *   - All voters present needed to have a vote set.
     33   *   - Voter.getVote() : Boolean
     34   *
     35   * @return boolean with conjuction of voters or null on error.
     36   */
     37  public Boolean census(HashSet<Voter> voters) {
     38    /* Nobody likes voting on Tuesday don't they? */
     39    Calendar rightNow = Calendar.getInstance();
     40    if (rightNow.get(Calendar.DAY_OF_WEEK) == Calendar.TUESDAY) {
     41      return false;
     42    }
     43
     44    /* Check all votes to make it a fair voting system */
     45    for (Voter v: voters) {
     46      logger.debug(v.getVote());
     47      /* Some vote is not set correctly or of wrong return value */
     48      if (v.getVote() == null || (!(v.getVote() instanceof Boolean))) {
     49        return false;
     50      }
     51
     52      /* All has to be in agreement */
     53      if (v.getVote() == false) {
     54        return false;
     55      }
     56    }
     57
     58    return true;
    1959  }
    2060}
  • liacs/TOOS/assignment1/src/Voter.java

    r205 r206  
    99  }
    1010
    11   public Boolean voted() {
     11  public Boolean getVote() {
    1212    return fvote;
    1313  }
Note: See TracChangeset for help on using the changeset viewer.