Assessment 2011 Tornado

From Progzoo
Revision as of 14:48, 7 March 2011 by Andr3w (Talk | contribs) (Introduction)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

SET08112 Algorithms and Data Structures Coursework 2011

Introduction

The coursework is based on a cluster of storage towers as used in a warehouse http://www.tornadostorage.com/en/storage/Tornado.html. Products are stored on trays, controlled by computer. The computer system keeps track of products. The state of the machine is stored in two files – cluster.txt and products.txt. Java programmes to read these files and create data structures are provided.

  • A cluster includes several towers each identified by a number.
  • A tower contains a number of movable trays – trays are numbered.
  • Each tray contains ten locations labelled 1A, 1B, 2A, 2B, … 5A, 5B.
  • Each location may contain several of a single product. The maximum number of products per location is typically 10 but may be some other value depending on the size of the product.
  • A product has an 8 digit code, a short description, weight and number per location (ppl).

Provided Data Structures

You may choose to use these data structures or change them as required.

Cluster.java

This represents a cluster of towers. Essentially list of locations (each on a tray on a tower) and a list of products.

import java.util.HashMap;
import java.util.ArrayList;
import java.io.*;
 
public class Cluster {
 	public ArrayList<Location> towers;
 	public HashMap<String,Product> products;
 	public Cluster(String productFile, String clusterFile){
 		try
 		{
 		products = new HashMap<String,Product>();
 		BufferedReader fh =
 			new BufferedReader(new FileReader(productFile));
 		String s;
 		while ((s=fh.readLine())!=null)
 		{
 			String [] f = s.split("\t");
 			products.put(f[0], new Product(f[0],f[1],Integer.parseInt(f[2])));
 		}
 		fh.close();
 
 		fh = new BufferedReader(new FileReader(clusterFile));
 		towers = new ArrayList<Location>();
 		while ((s=fh.readLine())!=null)
 		{
 			String [] f = s.split("\t");
 			Address addr = new Address(Integer.parseInt(f[0]),Integer.parseInt(f[1]),f[2]);
 			if (f.length==5 && f[3]!="")
 				towers.add(new Location(addr,f[3],Integer.parseInt(f[4])));
 			else
 				towers.add(new Location(addr,null,0));
 		}
 		fh.close();
 		}
 		catch (Exception e)
 		{
 			System.out.print("Exception: "+e);
 		}
 	}
 }


Location.java

This represnts a single location. A location has an address (including tower, tray and location). If a location is empty then product will be null, otherwise it holds quantity of the specified product.

public class Location {
	public Address addr;
	public String product;
	public int quantity;
 
	public Location(Address addr, String product, int quantity)
	{
		this.addr = addr;
		this.product = product;
		this.quantity = quantity;
	}
}

Product

Every product has id: a unique identifier, description: a user freindly name, weight: the mass in kg, ppl: products per location - the maximum number of this product that will fit into one slot.

public class Product {
	public String id;
	public String description;
	public int weight;
 
	public Product(String id, String description, int weight){
		this.id=id;
		this.description = description;
		this.weight = weight;
	}
}

Address

The address simply encapsulates the components of a location's physical position. The posn is string such as 1A, 1B ... 5B - these are laid out on the tray as shown below. Each tray has number in a tower, each tower has a number.

public class Address{
	public int tower;
	public int tray;
	public String posn;
	public Address(int tower, int tray, String posn){
		this.tower=tower;
		this.tray = tray;
		this.posn = posn;
	}
}

Trays and Addresses

Each tray has ten locations. Each location can contain a number of one particular product. The address of a location is written 1-02-3B – tower 1, tray 2, location 3B

1B 2B 3B 4B 5B
1A 2A 3A 4A 5A

Sample Question 00

How many of product 20034301 are there in tower 2?


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