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 Four</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 Four</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>3½ ✔</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-4)</th>
</tr>
<tr>
<td>code that is correct, clear and succint</td>
<td>4</td>
<td>4 ✔</td>
</tr>
<tr>
<td>code with small number of minor problems</td>
<td>3</td>
<td> </td>
</tr>
<tr>
<td>code that is clearly incorrect, too complex or hard to understand</td>
<td>1</td>
<td> </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 design (0-6)</th>
</tr>
<tr>
<td>design that is elegant and meets assignment design requirements</td>
<td>6</td>
<td> </td>
</tr>
<tr>
<td>design with minor flaws</td>
<td>4</td>
<td>5 ✔</td>
</tr>
<tr>
<td>design with minor flaws, but meets assignment design requirements</td>
<td>2</td>
<td> </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 ItemTracking.java (0-4)</th>
</tr>
<tr>
<td>no errors detected</td>
<td>4</td>
<td>4 ✔</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> </td>
</tr>
<tr>
<th scope="row">Total Possible Marks</th>
<td>15</td>
<td>16½/18</td>
</tr>
</tbody>
</table>
<h2>Submitted Code</h2>
<pre>
Inheritence Hierachy
LibraryItem
|
______________________|______________________
| |
| |
<a href="#stealable">Stealable</a> <a href="#borrowable">Borrowable</a>
| |
_________|_________ _____________|______________
| | | | |
| | | | |
<a href="#referenceitem">ReferenceItem</a> <a href="#visualmedium">VisualMedium</a> <a href="#librarybook">LibraryBook</a> <a href="#atdeskitem">AtDeskItem</a> <a href="#periodical">Periodical</a>
</pre>
<p> </p>
<p id="atdeskitem"> AtDeskItem.java<br />
View the <a href="JavaDoc/AtDeskItem" title="JavaDoc documentation for this code">JavaDoc</a><br />
<textarea name="textarea" cols="82" rows="44" readonly="readonly" title="Java Code - Copyright 2003 Ned Martin">/*
* Author: Ned Martin #40529927
*
* Creation Date: 17-AUG-2003
*
* Copyright: Ned Martin
*
* Description: Assignment 4 for COMP2500
*
* Tab Stops: Eight spaces
*/
/**
* Container for at-desk items. Implements isLost function.
* @author Ned Martin 40529927
* @version FINAL 17-OCT-2003
*/
public class AtDeskItem extends Borrowable
{
/**
* Construct a library item given its call number and cost
* Type is A - at-desk item
*/
public AtDeskItem
(
String id, // call number
int val // item cost
)
{
super(id, val);
}
/**
* Has the library item been lost
* @return true if the library item is lost
*/
public boolean isLost()
{
return (availability >= 3);
}
// end of file
}
</textarea>
</p>
<p id="availability">Availability.java<br />
View the <a href="JavaDoc/Availability" title="JavaDoc documentation for this code">JavaDoc</a><br />
<textarea name="textarea2" cols="82" rows="29" readonly="readonly" title="Java Code - Copyright 2003 Ned Martin">/*
* Author: Ned Martin #40529927
*
* Creation Date: 17-AUG-2003
*
* Copyright: Ned Martin
*
* Description: Assignment 4 for COMP2500
*
* Tab Stops: Eight spaces
*/
/**
* Interface providing library item availability function.
* @author Ned Martin 40529927
* @version FINAL 17-OCT-2003
*/
public interface Availability
{
/**
* Set availability of library item.
*/
public void setAvailability
(
String avail // if item is available or not (Y/N)
);
// end of file
}
</textarea>
</p>
<p id="borrowable">Borrowable.java<br />
View the <a href="JavaDoc/Borrowable" title="JavaDoc documentation for this code">JavaDoc</a><br />
<textarea name="textarea5" cols="82" rows="66" readonly="readonly" title="Java Code - Copyright 2003 Ned Martin">/*
* Author: Ned Martin #40529927
*
* Creation Date: 17-AUG-2003
*
* Copyright: Ned Martin
*
* Description: Assignment 4 for COMP2500
*
* Tab Stops: Eight spaces
*/
/**
* Abstract container for borrowable library items
*
* @author Ned Martin 40529927
* @version FINAL 17-OCT-2003
*/
abstract public class Borrowable extends LibraryItem implements Availability
{
/**
* Constant fine for late items.
*/
public int BOOK_FINE = 50;
/**
* days since item borrowed
*/
protected int availability;
/**
* Construct a borrowable library item given its call number and cost.
*
* Only called by subclasses.
*/
public Borrowable
(
String id, // call number
int val // item cost
)
{
super(id, val);
}
/**
* What is the replacement cost of the library item to the library
* @return the integer replacement cost of the library item
*/
public int getReplacementCost()
{
return getCost()-BOOK_FINE;
}
/**
* Set how many days since item was borrowed.
*/
public void setAvailability
(
String itemAvail // days since item borrowed
)
{
availability = Integer.parseInt(itemAvail);
}
// end of file
}
</textarea>
</p>
<p id="itemtracking">ItemTracking.java<br />
View the <a href="JavaDoc/ItemTracking" title="JavaDoc documentation for this code">JavaDoc</a><br />
<textarea name="textarea6" cols="82" rows="244" readonly="readonly" title="Java Code - Copyright 2003 Ned Martin">/*
* Author: Ned Martin #40529927
*
* Creation Date: 17-AUG-2003
*
* Copyright: Ned Martin
*
* Description: Assignment 4 for COMP2500
*
* Tab Stops: Eight spaces
*/
import java.io.*; // Provides standard IO
import java.util.*; // Provides StringTokenizer
/**
* This item tracking program reads in a number of library items where each item
* description contains a call number, item cost, usage value, item type, and an
* availability value. The usage value is how often the item is used. The
* availability value is dependent on the type of the library item. The output
* is two sorted lists: the first is a list of items currently in the library or
* on-loan, but not lost and the second is a sorted list of missing library
* items, the replacement cost of the item to the library; and the overall cost
* of the missing items.
*
* @author Ned Martin 40529927
* @version FINAL 17-OCT-2003
*/
public class ItemTracking
{
/**
* Linked list to hold library items.
*/
public static LibraryItemList libraryItems = new LibraryItemList();
/**
* Run read and print methods.
*/
public static void main(String[] args)
{
read(); // read input
print(); // print output
}
/**
* Read from standard input.
*/
private static void read()
{
String line; // holds input line
try
{
// Capture input from stdin
BufferedReader in = new BufferedReader(new
InputStreamReader(System.in));
// capture line
while ((line = in.readLine()) != null)
{
try
{
// send line to parser
parse(line);
}
catch (NumberFormatException e)
{
System.err.println("Invalid "+
"Input\n"+e);
System.exit(1);
}
}
}
catch (IOException e)
{
System.err.println("IO Exception: Check input\n"+e);
System.exit(1);
}
}
/**
* Parse input.
*
* Accept a line, parses it, determines type of book,
* create a new LibraryList object, insert data into it, add object to
* linked list in a sorted manner, and set usage and availability
* information
*/
private static void parse
(
String line // input line to parse
)
{
// create new string tokenizer
StringTokenizer st = new StringTokenizer(line);
int i = 0, // counter
itemCost = 0, // cost of item
itemUsage = 0; // item usage figure
String type = "", // type of item
token = "", // parsed token
callNo = "", // item call number
itemType = "", // type of item
itemAvail = "-0"; // item availability
// library item
LibraryItem libraryItem = null;
while (st.hasMoreTokens()) // more tokens exist
{
token = st.nextToken();
switch (i)
{
case 0: // Call No
callNo = token;
break;
case 1: // Cost
itemCost = Integer.parseInt(token);
break;
case 2: // Usage
itemUsage = Integer.parseInt(token);
break;
case 3: // Type
libraryItem = returnType(token, callNo,
itemCost, libraryItem);
break;
case 4: // Availability
itemAvail = token;
break;
}
i++;
}
try
{
// add library item to linked list
libraryItems.insert(libraryItem);
}
catch (DuplicateExc e)
{
System.err.println("Duplicate Exception\n"+e);
System.exit(1);
}
// set item usage
libraryItem.setUsage(itemUsage);
// cast library item to availability item and set availability
Availability avLib = null;
avLib = (Availability)libraryItem;
avLib.setAvailability(itemAvail);
}
/**
* Parse item type and create library items based on type
* @return object depending on type of library item
*/
private static LibraryItem returnType
(
String type, // R, B, A, P, V
String callNo, // call number
int itemCost, // item cost
LibraryItem libraryItem // null library item
)
{
if (type.equals("R")) //return "Reference Item";
{
return libraryItem =
new ReferenceItem(callNo,itemCost);
}
if (type.equals("B")) //return "Book";
{
return libraryItem =
new LibraryBook(callNo,itemCost);
}
if (type.equals("A")) //return "At desk item";
{
return libraryItem =
new AtDeskItem(callNo,itemCost);
}
if (type.equals("P")) //return "Periodical";
{
return libraryItem =
new Periodical(callNo,itemCost);
}
if (type.equals("V")) //return "Visual Medium";
{
return libraryItem =
new VisualMedium(callNo,itemCost);
}
// this never happens but makes compiler very happy
return libraryItem;
}
/**
* Print item information.
*/
private static void print ()
{
LibraryItem res = null; // library item
int totalReplacementCost = 0; // replacement cost
try
{
// located items
System.out.println("Located Items:");
libraryItems.resetIterator();
while (libraryItems.hasNext()) // more nodes exist
{
res = libraryItems.next();
if (!res.isLost()) // item is not lost
{
System.out.println(res.getCallNumber()+
" "+res.getUsage());
}
}
// missing items
System.out.println("Missing Items:");
libraryItems.resetIterator();
while (libraryItems.hasNext()) // more nodes exist
{
res = libraryItems.next();
if (res.isLost()) // item is lost
{
totalReplacementCost +=
res.getReplacementCost();
System.out.println(res.getCallNumber()+
" "+res.getReplacementCost());
}
}
// total replacement cost
System.out.println("Total replacement cost: "+
totalReplacementCost);
}
catch (NoSuchElementExc e)
{
System.err.println("Exception\n"+e);
e.printStackTrace();
System.exit(1);
}
}
// end of file
}
</textarea>
</p>
<p id="librarybook">LibraryBook.java<br />
View the <a href="JavaDoc/LibraryBook" title="JavaDoc documentation for this code">JavaDoc</a><br />
<textarea name="textarea7" cols="82" rows="52" readonly="readonly" title="Java Code - Copyright 2003 Ned Martin">/*
* Author: Ned Martin #40529927
*
* Creation Date: 17-AUG-2003
*
* Copyright: Ned Martin
*
* Description: Assignment 4 for COMP2500
*
* Tab Stops: Eight spaces
*/
/**
* Container for book items. Implements isLost and getReplacementCost functions.
* @author Ned Martin 40529927
* @version FINAL 17-OCT-2003
*/
public class LibraryBook extends Borrowable
{
/**
* Construct a library item given its call number and cost.
* Type is B - book
*/
public LibraryBook
(
String id, // call number
int val // item cost
)
{
super(id, val);
}
/**
* Has the library item been lost.
* @return true if the library item is lost
*/
public boolean isLost()
{
return (availability >= 28);
}
/**
* What is the replacement cost of the library item to the library.
* @return the integer replacement cost of the library item
*/
public int getReplacementCost()
{
return getCost() - (getCost()/2);
}
// end of file
}
</textarea>
</p>
<p id="periodical">Periodical.java<br />
View the <a href="JavaDoc/Periodical" title="JavaDoc documentation for this code">JavaDoc</a><br />
<textarea name="textarea8" cols="82" rows="51" readonly="readonly" title="Java Code - Copyright 2003 Ned Martin">/*
* Author: Ned Martin #40529927
*
* Creation Date: 17-AUG-2003
*
* Copyright: Ned Martin
*
* Description: Assignment 4 for COMP2500
*
* Tab Stops: Eight spaces
*/
/**
* Container for periodical items. Implements isLost function.
* @author Ned Martin 40529927
* @version FINAL 17-OCT-2003
*/
public class Periodical extends Borrowable
{
/**
A library item is an abstarct class that stores the call number of a
library item, the cost of that item and the usage of that item.
@author Anthony MacDonald
@version 1.0 26/09/2003
*/
/**
* Construct a library item given its call number and cost.
* Type is P - periodical item
*/
public Periodical
(
String id, // call number
int val // item cost
)
{
super(id, val);
}
/**
* Has the library item been lost.
* @return true if the library item is lost
*/
public boolean isLost()
{
return (availability >= 7);
}
// end of file
}
</textarea>
</p>
<p id="referenceitem">ReferenceItem.java<br />
View the <a href="JavaDoc/ReferenceItem" title="JavaDoc documentation for this code">JavaDoc</a><br />
<textarea name="textarea9" cols="82" rows="43" readonly="readonly" title="Java Code - Copyright 2003 Ned Martin">/*
* Author: Ned Martin #40529927
*
* Creation Date: 17-AUG-2003
*
* Copyright: Ned Martin
*
* Description: Assignment 4 for COMP2500
*
* Tab Stops: Eight spaces
*/
/**
* Container for reference items. Implements getReplacementCost function.
* @author Ned Martin 40529927
* @version FINAL 17-OCT-2003
*/
public class ReferenceItem extends Stealable
{
/**
* Construct a library item given its call number and cost.
* Type is R - reference item
*/
public ReferenceItem
(
String id, // call number
int val // item cost
)
{
super(id, val);
}
/**
* What is the replacement cost of the library item to the library.
* @return the integer replacement cost of the library item
*/
public int getReplacementCost()
{
return getCost();
}
// end of file
}
</textarea>
</p>
<p id="stealable">Stealable.java<br />
View the <a href="JavaDoc/Stealable" title="JavaDoc documentation for this code">JavaDoc</a><br />
<textarea name="textarea10" cols="82" rows="71" readonly="readonly" title="Java Code - Copyright 2003 Ned Martin">/*
* Author: Ned Martin #40529927
*
* Creation Date: 17-AUG-2003
*
* Copyright: Ned Martin
*
* Description: Assignment 4 for COMP2500
*
* Tab Stops: Eight spaces
*/
/**
* Abstract container for non-borrowable library items.
*
* @author Ned Martin 40529927
* @version FINAL 17-OCT-2003
*/
abstract public class Stealable extends LibraryItem implements Availability
{
private String availability; // if item is available or not
/**
* Construct a non-borrowable library item given its call number and
* cost.
*
* Only called by subclasses.
*/
public Stealable
(
String id, // call number
int val // item cost
)
{
super(id, val);
}
/**
* Has the library item been lost.
* @return true if the library item is lost
*/
public boolean isLost()
{
// Y or N for on-shelf or off-shelf (lost)
return (getAvailability().equals("N"));
}
/**
* Set whether item is on-shelf or off-shelf (lost).
*
* Either Y/N
*/
public void setAvailability
(
String avail // if item is available or not Y/N
)
{
availability = avail;
}
/**
* Return availability
* @return String Y if item available or N if item not available
*/
private String getAvailability()
{
return availability;
}
// end of file
}
</textarea>
</p>
<p id="visualmedium">VisualMedium.java<br />
View the <a href="JavaDoc/VisualMedium" title="JavaDoc documentation for this code">JavaDoc</a><br />
<textarea name="textarea11" cols="82" rows="43" readonly="readonly" title="Java Code - Copyright 2003 Ned Martin">/*
* Author: Ned Martin #40529927
*
* Creation Date: 17-AUG-2003
*
* Copyright: Ned Martin
*
* Description: Assignment 4 for COMP2500
*
* Tab Stops: Eight spaces
*/
/**
* Container for visual-medium items. Implements getReplacementCost function.
* @author Ned Martin 40529927
* @version FINAL 17-OCT-2003
*/
public class VisualMedium extends Stealable
{
/**
* Construct a library item given its call number and cost.
* Type is V - visual-medium item
*/
public VisualMedium
(
String id, // call number
int val // item cost
)
{
super(id, val);
}
/**
* What is the replacement cost of the library item to the library.
* @return the integer replacement cost of the library item
*/
public int getReplacementCost()
{
return 2*getCost();
}
// end of file
}
</textarea>
</p>
<p>Code © Copyright 2003 Ned Martin</p>
<p>12-Nov-2003</p>
</body>
</html>