toString( )methods in testing
Don't put off working on this lab! Although the implementation is straightforward once you understand the design, the lab is a little larger than either of the previous labs. Feel free to ask for help as needed!
All labs will include a main file named by the lab number,
Lab3.java. The labs will
also include a
Startup.java file, which
serves as a driver: a piece of code that calls the methods you
write, to exercise your code and demonstrate your work. In this lab,
the driver is incomplete; you must write some test procedures for some of the
classes you implement.
Toons 'R' Us
.com, the famous Internet clothing store for
two-dimensional characters, is a smash hit! Our toon friends are clamoring
for more. In order to meet their demands, though, Toons 'R' Us will have to
step back and re-analyze that ad-hoc method they're using to supply shirts to
these customers. Yes, that's right: it's time for some high-level business
some assembly line fun, and Java is just the language to help us out.
Your job is to help increase the profitability of Toons 'R' Us by articulating and implementing a system of objects that models real-life counterparts (recall that the API of such objects is the interface, which hides internal implementation). The Toons 'R' Us head honchos have already decided on the API, and it's set in stone. So, you'll have to honor their wishes in your implementation. Their design involves the following:
Before we start you in on the design, you need to understand how the system will function. The shirts that are made
a means for accessing the particular values of these shirt production
giving you a
file, which contains a means for storing and retrieving attributes such as
how long it takes to make a shirt which is made of fabric 3, or exactly how
large a "large" shirt is.
When you are done implementing the lab, its objects will form a (linear) optimization problem, in which many factors must be considered to try to make the maximum profit. Problems such as these occur everywhere in the real world, especially in manufacturing processes. Have fun trying to find the best solution you can (Hint: you're doing very well if, given the default parameters in Startup.java as described below, you can make $2000).
During demo, a prize will be given to the student who can maximize profit in running his or her implementation. The idea is to use your implementation as a tool to explore how best to make money.
In real life, you would probably implement more features into each of the classes because the problems of real manufacturing are deeper and more complex. So, here is an example of stepwise refinement -- our factory classes will be complete in and of themselves, but the design may need to support more features in different contexts.
Major caveat #1: One of the goals of this lab is to get you thinking of how to write internal representations (i.e. choose instance variables). So, you will find the instance variables missing in most of the files for this lab. Feel free to choose your own instance variables; part of your grade for the lab will be how well you choose them and how well they work. Having said that, the choice of instance variables should be fairly straightforward based on our design - if it seems like the right answer, it probably is!
Major caveat #2: Another goal of this lab is to get you testing your
classes thoroughly. We require of all of your classes (except ProcessControl)
to have a method
public String toString( ) that Java uses to
convert your object to a String. You are also required to test your
classes thoroughly in Startup.java by printing some tests to the Terminal,
some of which involve the use of your toString. The test procedures should
be located in the indicated spots in Startup.java.
Some examples are provided; if you have any questions, please ask.
Now, on to the design!
Shirt(int area, double productionTime, int price)
Shirt, we provide
toStringwhich would produce the following for the above example.
For this design, we will encode the kind of fabric as an
int: 1, 2,
3, or 4.
This suggests an internal representation which allows you to keep
track of how much of which fabric and time you have left,
and leads to the following API for
ShirtFactory(int supply1, int supply2, int supply3, int supply4, double prodHours, SimConstants sc)
SimConstants. You will need this object to learn how much time it takes to produce a particular shirt.
int getFabricLeft(int fabricType)
double getHoursLeft( )
void addFabric(int fabricType, int quantity)
Shirt makeShirt(int size, int fabricType)
In order to find out the sales price, fabric requirement, and time
requirement for this shirt, you must
call methods on the
SimConstants object. Those methods
take the size of the shirt as a parameter.
Stringthat shows the supply of your factory. We suggest this format: "ShirtFactory with supply [1, 2, 3, 4] and hours left 101".
Notice that the ShirtFactory should never make a shirt for which it doesn't have the resources; in other words, ShirtFactory has a representation invariant which says the resources should never dip below zero, or else the object is in an illegal state. It is your responsibility to be sure your implementation maintains this invariant.
ShirtWarehouseobject, for which we have the following API.
int getGoodsValue( )
void empty( )
void addToStock(Shirt s)
Stringthat shows the monetary value of the supply of your factory. We suggest this format: "ShirtWarehouse with total goods $101"
ShirtShopwith the following API.
ShirtShop(String owner, double startingCash)
boolean debit(double cash)
To indicate the error state in this case, we use a boolean value; a return of true means the transaction succeeded, and false means the transaction failed.
void credit(double cash)
Stringcontaining the cash flow of the shop and its owner. We suggest this format: "Shirt Shop owned by John Doe with $101".
FabricFactoryto keep track of the supplier's amount of fabric.
FabricFactory(int supply1, int supply2, int supply3, int supply4, SimConstants sc)
int getSupply(int fabricType)
boolean sellFabric(int fabricType, int qty, ShirtShop shop, ShirtFactory destFactory)
ShirtShop is providing the funds for this transcation, but
the fabric is sold to the
Thus, you must check against the cash on hand in the given ShirtShop and this
FabricFactory's supply to decide if the order can be filled. If the order
can be filled, fill it by adding fabric to the destination ShirtFactory
and making a negative valued transaction on the ShirtShop. Use the
SimConstants object you received in the constructor to determine the total
cost of the order based on qty and the unit price of the given fabric type.
Again, returns false if the order can't be filled, and true if the order could have been (and was) filled. Don't forget to actually subtract the order from your supply!
Stringcontaining the supply of your factory. We suggest this format: "FabricFactory with supply [1, 2, 3, 4]".
ProcessControl(FabricFactory ff, ShirtFactory sf, ShirtWarehouse sw, ShirtShop s, SimConstants sc)
GUIManager.javaif you want the gory details (but don't worry if you don't understand it now - you'll learn how to make GUIs in CS102).
updateGUI()on the GUIManager stored inside the ProcessControl object so that the user interface can refresh itself.
boolean manufactureShirt(int size, int fabricType)
indicateProblem(String errorMessage)method on the GUIManager.
void orderFabric(int fabricType, int quantity)
indicateProblem(String errorMessage)on the GUIManager.
void sellShirts( )
indicateMessage(String message)on the GUIManager that shows the amount you made on the sale.
You must implement the classes described in the design. For this lab, you are constrained to following this design. Specific implementation steps are given at the end of this document; the files you download repeat those suggestions.
transcript.txtin the same folder as your Lab 3 files.
Shirt.javaaccording to the instructions contained in that file. Use the textual test in
Startup.javato test it.
ShirtFactory.javaaccording to the instructions in that file. Use the textual test in Startup.java to test it.
ShirtWarehouse.java. Write tests in Startup.java to test ShirtWarehouse.
ShirtShop.javaand write tests in Startup.java to test ShirtShop.
FabricFactory.javaand write tests in Startup.java to test FabricFactory.
ProcessControl.java. Comment in the graphical test in Startup to test ProcessControl.