UQ Students should read the Disclaimer & Warning
Note: This page dates from 2005, and is kept for historical purposes.
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>COMP2500 - Assignment Three</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<style type="text/css">
<!--
.wrong {
background: #FF9999;
}
body {
background: url(_img/DSC04989.jpg) fixed center;
font-family: "Arial Unicode MS", Arial, Helvetica, sans-serif;
}
th, td, textarea {
border: 1px solid #000000;
padding: 0 1ex;
background: transparent;
overflow: hidden;
}
table {
border: none;
}
-->
</style>
</head>
<body>
<h1>COMP2500 – Programming in the Large – Assignment Three</h1>
<table border="1" summary="Criteria and results achieved for COMP2500 assignment one">
<thead>
<tr>
<th colspan="3">Criteria and Results</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="2">Average class result</td>
<td>—</td>
</tr>
</tfoot>
<tbody>
<tr>
<th colspan="3" scope="col">Adherence to code format rules (0-4)<br />
(including quantity and quality of comments)</th>
</tr>
<tr>
<td>no violation of code format rules/comments</td>
<td>4</td>
<td> </td>
</tr>
<tr>
<td>a number of problems with code format rules/comments</td>
<td>2</td>
<td>2 ✔</td>
</tr>
<tr>
<td>work with little or no academic merit</td>
<td>0</td>
<td> </td>
</tr>
<tr>
<th colspan="3" scope="col">Quality of code (0-6)</th>
</tr>
<tr>
<td>code that is correct, clear and succint</td>
<td>6</td>
<td> </td>
</tr>
<tr>
<td>code with small number of minor problems</td>
<td>4</td>
<td> </td>
</tr>
<tr>
<td>code that is clearly incorrect, too complex or hard to understand</td>
<td>2</td>
<td>2½ ✔</td>
</tr>
<tr>
<td>work with little or no academic merit</td>
<td>0</td>
<td> </td>
</tr>
<tr>
<th colspan="3" scope="col">Our testing of ClassRanking.java (0-4)</th>
</tr>
<tr>
<td>no errors detected</td>
<td>4</td>
<td> </td>
</tr>
<tr>
<td>one or two minor problems detected</td>
<td>3</td>
<td> </td>
</tr>
<tr>
<td>substantial number or problems detected</td>
<td>1</td>
<td> </td>
</tr>
<tr>
<td>work with little or no academic merit</td>
<td>0</td>
<td>0 ✗</td>
</tr>
<tr>
<th colspan="3" scope="col">Our testing of DoubleOrderedLinkedList.java
(0-4)</th>
</tr>
<tr>
<td>no errors detected</td>
<td>4</td>
<td> </td>
</tr>
<tr>
<td>one or two minor problems detected</td>
<td>3</td>
<td> </td>
</tr>
<tr>
<td>substantial number of problems detected</td>
<td>1</td>
<td> </td>
</tr>
<tr>
<td>work with little or no academic merit</td>
<td>0</td>
<td>0 ✗</td>
</tr>
<tr>
<th scope="row">Total Possible Marks</th>
<td>15</td>
<td>4½/18</td>
</tr>
</tbody>
</table>
<h2>Submitted Code</h2>
<p> ClassRanking.java<br />
View the <a href="JavaDoc/ClassRanking" title="JavaDoc documentation for this code">ClassRanking
JavaDoc</a><br />
<textarea name="textarea" cols="82" rows="148" readonly="readonly" title="Java Code - Copyright 2003 Ned Martin">import java.io.*; // Provides standard IO
import java.util.*; // Provides StringTokenizer
/**
* Ranks a class via their marks and prints output
* @author Ned Martin 40529927
* @version BETA 26-SEP-2003
*
* Note: This class is unfinished BETA version.
* Caveats: Requires exact input. Requires more than three input students.
* Does not sort well. Does not use String sorting. I had difficulties in the
* design and ran out of time. My apologies.
*/
class ClassRanking
{
/**
* Creates a new linked list
*/
public static DoubleOrderedLinkedList studentList =
new DoubleOrderedLinkedList();
/**
* Reads input, stores in linked list and writes output
* @param -r number Not Implemented
* number Not Implemented
*/
public static void main
(
String[] args
)
{
// read input
read();
// if ranking
boolean reverse; // sort reverse order
int cutOffRank; // rank to sort from
if (args.length >= 1)
{
// if reverse ranking
if (args[0].equals("-r"))
{
reverse = true;
cutOffRank = Integer.parseInt(args[1]);
}
// if normal ranking
else
{
cutOffRank = Integer.parseInt(args[1]);
}
}
// print output
print();
}
/**
* Read input
*/
private static void read ()
{
String studentMarks; // holds input line
try
{
// Capture input from stdIn
BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));
// capture line
while ((studentMarks = in.readLine()) != null)
{
// send line to parser
parse(studentMarks);
}
}
catch (IOException e)
{
System.err.println("IO Exception: Check input\n"+e);
System.exit(1);
}
}
/**
* parser
*/
private static void parse
(
String studentMarks // input line to parse
)
{
//String name; // student name
StringTokenizer st = new StringTokenizer(studentMarks);
// assume exact string format "name exam mark mark ..."
// make new Comparable Object with student name
ComparableResult student = new ComparableResult(st.nextToken());
//students[(int) numStudents-1] = st.nextToken();
// set exam marks and course marks
student.setExamMark(Integer.parseInt(st.nextToken()));
while (st.hasMoreTokens())
{
student.addToCourseWorkMark(
Integer.parseInt(st.nextToken()));
}
studentList.insert(student);
}
/**
* Print output
*/
private static void print ()
{
// create new iterator over list
BidirectionalIterator iter = studentList.iterator();
// iterate through nodes in list printing them
do
{
//((Integer)obj).toString()
ComparableResult cp = (ComparableResult) iter.next();
// format string as:
// name, final mark, exam mark, coursework mark
String toPrint = cp.getName()+"\t"+
cp.getFinalMark()+"\t"+
cp.getExamMark()+"\t"+
cp.getCourseWorkMark();
// print string
System.out.println(toPrint);
}
// while more nodes exist
while (iter.hasNext());
}
}
</textarea>
</p>
<p>DoubleOrderedLinkedList.java<br />
View the <a href="JavaDoc/DoubleOrderedLinkedList" title="JavaDoc documentation for this code">DoubleOrderedLinkedList
JavaDoc</a><br />
<textarea name="textarea3" cols="82" rows="245" readonly="readonly" title="Java Code - Copyright 2003 Ned Martin">import java.util.*; // Provides NoSuchElementException
/**
* Creates Double Linked List and an Iterator for this list.
* @author Ned Martin 40529927
* @version BETA 26-SEP-2003
*
* This class is unfinished and BETA.
*/
class DoubleOrderedLinkedList implements OrderedLinkedList
{
private int size; // number of elements in list
private Node first; // first Node of list
/**
* Creates an empty linked list
*/
protected DoubleOrderedLinkedList ()
{
size = 0; // number of elements in list
first = null; // pointer to first Node in list
//header = new Header();
//header.next = header;
//header.previous = header;
}
/**
* Stores number of Nodes in linked list
* @return integer number of Nodes in linked list
*/
public int size ()
{
return size;
}
/**
* Make node
*/
private class Node
{
public Object element; // element to add to Node
public Node next, previous; // next node
/**
* Creates a Node
* @param Object to insert in node
*/
public Node
(
Object element // element to add to node
)
{
this.element = element;
this.next = null;
this.previous = null;
}
}
/**
* Returns an element for specified Node
* @param Node to return element for
* @return Element of Node
*/
public Object getElement (Node n)
{
// get element
return n.element;
}
/**
* Insert an element into a Node in order.
* Note: Order not fully implemented.
* @param Comparable to insert
*
* Note: Sorting not fully implemented.
*/
public void insert
(
Comparable c // object to insert
)
{
ComparableResult cp = (ComparableResult) c;
Node current, previous;
current = first;
previous = null;
Node newNode = new Node(cp); // insert new node
// if first
//while (current != null && SORTING_CONDITION)
while (current != null && cp.compareTo(current.element) < 1)
//while (current != null)
{
// include many more sorting conditions here
previous = current;
current = current.next;
}
// if empty list
if (previous == null)
{
first = newNode;
}
else
{
previous.next = newNode;
newNode.previous = previous;
newNode.next = current;
//current.previous = newNode;
}
size++;
}
/**
* Returns a BidirectionalIterator over the list
* @return BidirectionalIterator over list
*/
public BidirectionalIterator iterator ()
{
DoubleLinkedListIterator it =
new DoubleLinkedListIterator(this);
return it;
}
/**
* List iterator implementing BidirectionalIterator
*/
private class DoubleLinkedListIterator
implements BidirectionalIterator
{
/**
* Creates a DoubleLinkedListIterator
* @param list to iterate
*/
public DoubleLinkedListIterator
(
DoubleOrderedLinkedList s // list
)
{
//DoubleOrderedLinkedList theLinkedList = s;
//current = theLinkedList.first;
//current = s.first;
reset(s);
}
Node current;
/**
* Resets iterator to first positions
* @param list to iterate
*/
public void reset
(
DoubleOrderedLinkedList s // list to iterate
)
{
current = s.first;
}
/**
* Tests for next Node in list
* @return true if next Node exists
*/
public boolean hasNext ()
{
// has next
//System.out.println("next it "+current.next != null);
//current = current.next;
return current.next != null;
}
/**
* Gets Object from Node in list
* @return Object from next Node in list
* @throws NoSuchElementException if element does not exist
*
* Note: This method does not currently work well with hasNext()
* not all elements will be returned.
*/
public Object next ()
throws NoSuchElementException
{
Node temp;
// move pointer right
// output element
// if first
if (current.previous == null)
{
temp = current;
current = current.next;
return temp.element;
}
// if last
//if (current.next == null)
//{
// return current.element;
//}
temp = current;
current = current.next;
return temp.element;
}
/**
* Tests if previous Node exists in list
* @return true if previous Node exists
*/
public boolean hasPrevious ()
{
// has previous
return current.previous != null;
}
/**
* Returns previous Object from Node in list
* @return Object from previous Node in list
* @throws NoSuchElementException if element does not exist
*/
public Object previous()
throws NoSuchElementException
{
// output element
//return current.element;
// move pointer left
current = current.previous;
return current.next.element;
}
/**
* Removes Node from list. This function is not implemented.
* @throws UnsupportedOperationException because this
function is not implemented, and
IllegalStateException
*/
public void remove()
throws IllegalStateException,
UnsupportedOperationException
{
throw new UnsupportedOperationException();
}
}
}
</textarea>
</p>
<p>ComparableResult.java<br />
View the <a href="JavaDoc/ComparableResult" title="JavaDoc documentation for this code">ComparableResult
JavaDoc</a><br />
<textarea name="textarea4" cols="82" rows="186" readonly="readonly" title="Java Code - Copyright 2003 Ned Martin">/**
* Creates a Comparable Object and implements StudentResults and Comparable
* @author Ned Martin 4052992
* @version BETA 26-SEP-2003
*
* Note: This class is incomplete BETA version.
*/
class ComparableResult implements Comparable, StudentResults
{
int[] marks = new int [8]; // holds marks
String name; // holds name
/**
* Constructor
* @param String containing Student Name
*/
public ComparableResult
(
String studentname // student name
)
{
name = studentname;
// initialise course marks to 0
for (int i = 1; i < marks.length; i++)
{
marks[i] = 0;
}
}
/**
* The name of the student for whoon results are stored.
* @return the name of the student
*/
public String getName()
{
return name;
}
/**
* The exam mark for a student can be stored or updated
* @param mark the student's exam result
*/
public void setExamMark
(
int mark // exam mark to set -1 to 60
)
{
marks[0] = mark;
}
/**
* The exam mark for the student
* @return the student's exam mark
*/
public int getExamMark ()
{
return marks[0];
}
/**
* A student's course work mark may be composed of a collection of
* marks and this method allows a new mark to be added to that
* collection.
* @param extraMark the next mark to be added
*/
public void addToCourseWorkMark
(
int extraMark // mark to add, int 1 to 10, up to 7
// times
)
{
// add to course work mark - does not handle incorrect input
int i = 1;
while (i < marks.length && marks[i] != 0)
{
i++;
}
marks[i] = extraMark;
}
/**
* The course work mark is calculated from the course work marks added
* to the collection of course work marks for the student.
* @return the final coursework mark for the student
*/
public int getCourseWorkMark ()
{
int sum = 0;
// get course work mark
for (int i = 1; i < marks.length ; i++)
{
sum = sum + marks[i];
}
return sum;
}
/**
* The final mark for a student is calculated from the exam and
* coursework marks.
* @return the student's final mark
*/
public int getFinalMark ()
{
int sum = 0;
for (int i = 0; i < marks.length ; i++)
{
sum = sum + marks[i];
}
return sum;
}
/**
* Compares two Objects
* @param Object s to compare, representing student marks
* @return -1 if this student's final mark is less than s's final
* mark or the final marks are the same but this student’s
* exam mark is less than s’s exam mark or both the final
* and exam marks are the same but this student's name is
* less than s's name.
* 0 if all of the final mark, exam mark and name are the
* same.
* +1 if this student's final mark is greater than s's
* final mark or the final marks are the same but this
* student’s exam mark is greater than s’s exam mark or
* both the final and exam marks are the same but this
* student's name is greater than s's name.
* @throws ClassCastException if Object is not a ComparableResult
Object.
*
* Note: This method is incomplete.
*/
public int compareTo(Object s)
throws ClassCastException
{
ComparableResult cp = (ComparableResult) s;
// final mark is greater
if (this.getFinalMark() > cp.getFinalMark())
{
return 1;
}
// final mark is less
if (this.getFinalMark() < cp.getFinalMark())
{
return -1;
}
// exam mark is greater
if (this.getExamMark() > cp.getExamMark())
{
return 1;
}
// exam mark is less
if (this.getExamMark() < cp.getExamMark())
{
return -1;
}
// String sorting is not implemented in this version
// if String name is greater
//if (this.getName().compareToIgnoreCase(cp.getName()) > 1)
//{
// return 1;
//}
// if String name is less
//if (this.getName().compareToIgnoreCase(cp.getName()) < 1)
//{
// return -1;
//}
// if Objects are the same
else
{
return 0;
}
}
}</textarea>
<br />
Code © Copyright 2003 Ned Martin</p>
<p>01-Nov-2003</p>
</body>
</html>