University of Toronto
Department of Computer Science

CSC 108 - INTRODUCTION TO COMPUTER PROGRAMMING

Assignment 4 page



Assignment 4 advice page.

April 10
Question: how do u want us to calculate wait times? I prefer wait time = deliver time - order time however this obviously doesnt cover if the pizza joint NEVER delivers it at end of run so in that context, the person who ordered the earliest who didnt get their pizza delivered is the one who waited the longest..
Answer: Yes the way to calculate the wait time is deliver time - order time.
Check the description of the assignment again it states that you can assume that every ordered pizza will have a corresponding Deliver command before the program ends.

April 10
Announcement: A4 has been extended until Friday, April 11, at midnight. This announcement applies to both the StGeo and Erindale offerings of the course.

April 10
Question: The Close command prints the 'total receipts' for this run of the program... is the that number of pizzas * their price?
Also, for number of pizzas, do we need to break it down in small/med/large or just one grand total?
Answer: Not exactly. Take a closer look at the Pizza Prices paragraph in the assignment description. Don't forget to include any extra charge for additional toppings.
No, you don't have to breakdown and print the number of pizzas by size, one grand total is enough.

April 10
Question: How do I compare two phone numbers or two Customer objects to see which one comes first for sorting purposes? Answer: If you've got a class with a compareTo method:
public int compareTo(Object o) {... } // must take an Object paremeter
and your class declaration looks like this:
public class Foo implements Comparable {....}
then you can make the declaration of binSearch look like this:
public static int binSearch(Comparable s, Vector list) {...}
and it will work for any class that implements Comparable. For example you could make your Customer class implement Comparable and add a compareTo(Customer c) method.
The String class already implements compareTo.

April 10
Correction: The April 7 answer needs to be:
v.insertElementAt(element, Finder.binSearch(pizza, v)
insertElementAt needs two parameters. This is only one suggestion. There are other solutions using the Vector add method.

April 10
Question: I am not sure that I will complete the assignment. What can I do?
Answer: Leave implementation of "Save" and "Load" until last. It is better to have a working program that solves part of the problem rather than a non working program tha attempts to solve all of the problem. You will receive credit for the parts of the program that you implement, even if you don't finish these two.

April 10
Question: Do we need to submit the stylesheet file composed by javadoc?
Answer: No, just the .html files that correspond to each of your .java files.

April 9
Question: How can I not make a date object and still use the Date class methods as it is described in the Clarification from April 5?
Answer: Please reread the clarification. It encourages you use the Date class, but says that you can't use the Date() constructor. The Date() constructor gives you the current date and time. You don't want the current date and time you want the date and time that are read in. So you have to use one of the other constructors that allows you to specify a date and time other than right now.

April 9
Question: do we assume that the text file we load is already sorted (by phone numbers)?
Answer: Yes. Assume that the load file is in the same format as the save file, sorted by phone number.

April 8
Question: I have a question about the close method. What excatly do we have to display. Also, do we only show the customer that waited the longest or we list all customer order to waiting time?
Answer: The Close command causes a summary of collected statistics with headings to be displayed. The three statistics are:
the phone number of the customer who waited the longest for their pizza,
the number of pizzas sold for this run of the program and
the total receipts for this run of the program.

April 8
Question: If someone ordered a pizza 1 year and 4 months ago, and I have to deliver it today, the Listorders will put it in the very top. In other word, should I consider that far back time?
Answer: (Unless there was one that was ordered even before that.) Let's assume that pizzas are ordered and delivered within a 24 hour period. (That period could span two days.)

April 8
Question: Can I create other methods in the class PizzaJoint? Answer: Yes.

April 8
Question: Can I use static variable as well as static method(for examle creat main as a static method) in PizzaJoint?
Answer: Yes, but is would probably make more sense to make it a local variable in the main method.

April 8
Question: I have a question about the cumulation of pizza number. Shoud I count one more after "order" or "deliver"?
Answer: It is up to you.

April 8
Question: Are you guys marking on style?
Answer: Yes. Paragraphing, good identifiers, commenting, etc.

April 8
Question: Does it matter how many classes we use? For example: Would it be better for a "Customer" to have a "Pizza" object, as Breathers had a Chamber in A2?
Answer: Yes the number of classes is important. But we are not looking for a specific number of classes. Your solution should be divided into logically organized objects. When you read the assignment description you should be able to see several different things, these should be objects in your program. The structure of A2 would be a good example to follow.

April 8
Question: Does it matter where we put TOPPINGS_LIST, etc.?
Answer: Yes. It should be placed in a logical location not necessarily near where it is used but with other related information.

April 8
Question: Does it matter if little helper methods to sort, parse, etc. are in PizzaJoint or should they be in a separate class?
Answer: Again they should be placed in a logical place. General methods that are used by many parts of the program could be in PizzaJoint or in a separate class. More specific methods should be placed with the code they are helping.

April 8
Student suggestion:For those people having problems running java from the command line, check out "5. Update the PATH variable" at
http://java.sun.com/j2se/1.4.1/install-windows.html
It solved all my problems.

April 7
Question: I am having trouble running from the command line.
Answer: Try
java -cp . PizzaJoint
or
java -cp . TestIO
With some versions of Windows the current directory must explicitly be added to the classpath.

April 7
Question: Any hints about keeping a list in order?
Answer: A linear or binary search that returns the index of the first element greater-than-or-equal to the one being searched for can be used maintain a sorted list with something to this effect:
v.insertElementAt(Finder.binSearch(pizza, v))

April 6
Question: Should I prompt the user for everything and make it as a txt file or I can load it from your sample directly and use it?
Answer: There is no need to prompt the user for the data in the load file. You will have to prompt the user for the name of the load file and for other commands and related input. Use the InputOutputOperations class to input the commands and the related information. It provides some prompts and each method has a parameter that is used for a data specific prompt.
For testing purposes you can create a file of commands and related information and redirect the contents of the file as standard input when running the program from the Command Prompt.

April 6
Question: Is Listorder like a delivery list? it contains the customers that are stilling wating for delivery? and also if we made a delivery do we remove that customer from the Listorder?
Answer: Listorders is a command that is read, keyed in by the user. Your program's response to this command should be the printing of a list of the pizza orders that are waiting to be delivered. The information for each waiting pizza is: the customer's phone number and the date and time of the order. If a pizza is delivered it is no longer waiting so should not be printed if the Listorders command is read.

April 6
Question: I wanted to ask if there was a specific file name that the tester would be using or would it change each time?
Answer: The name could be different for each run. This is the reason why the file name is read in for each run of the program. (In an actual application yesterday's save file would be today's load file.)

April 6
Question: I was wondering if we were suppose to use public static void main(String[] args) or if it doesnt matter.
Answer: Yes you must have a main method. When you execute a program from the command prompt Java is looking for a main method.

April 5
Question: Can we use classes from the API?
Answer: Yes. For example the Date class allows you store dates including times, to compare dates before and after. Other methods may be useful.
(Clarification: In an earlier message I said that you could not use Date(). This doesn't mean that you can't use the Date class but rather you can not use the Date() constructor.)

April 4
Question: I'm worried about the size of A4. Is there any logical place to trim it?
Answer: There are many ways. Here are a couple of ideas. For example: focus on the management of customers, reading in the load data, sorting and presenting the customer data in order by number of pizzas bought, saving the customer data. Or focus on the management of pizzas, executing order commands and delivery commands and presenting the list of waiting pizzas. (This is good programming practice, focusing on a part of the program, writing the code for that part, testing it and then building on that part.) No matter how much of the program you get completed, don't forget to document your reasons for using the logic and java structures that you choose.

April 4
Question: I can't run TestIO from the DrJava interactions pane.
Answer: That's right it doesn't do standard input. You can run TestIO from the DOS command prompt.
If you run into problems, class path errors. Copy all your files (including your class files) to the root level (ie not in any directories) on the a: drive. (You can use Windows to copy your files.) Change to the Command Prompt. (This will probably show a prompt of c:> or c: followed by a list of directories.) (The Command Prompt is should be in one of your menues. Probably Start/Programs/Accessories. If you don't find it there choose Run from the Start menu and key in cmd in the dialog box that appears.) Change to the a: drive by keying in a: Then key in:
a:> java TestIO

April 2
Question:When is this assignment due? is it due this thrusday or the next week?
Answer: (What is this? A bad April fools joke?) Thursday April 10 at 6 pm.

April 2
Question: Are we allowed to use the "Sort" method in the "Collections" class in API to sort our customer list?
Answer: If you can make a good case for using sort and you use it appropriately.

April 2
Question: In the A4 assignment description, is it supposed to be private static final as opposed to public static final?
Answer: No. It should be public. These arrays of options are declared in some appropriate place in your program structure but you may need them elsewhere in the program. The normal reason for declaring something private is to restrict access. In this case we don't want to restrict access. Also in this case restricting access to control changing the value(s) is not an issue because it has been declared final so it can not be changed.

April 2
Question: Are we allowed to make a JFrame with a bunch of buttons which carry out operations? rather than having to type it all in into the interactions pane?
Answer You are allowed to write a different InputOutputOperations class but it must have the same interface as the InputOutputOperations class that we have provided. (We will test your program with the InputOutputOperations class that we provided. Don't worry about buttons and JFrames until you get the rest of the program complete and working flawlessly!)

April 1
Question: I'm a bit unsure about the "Load" command in assignment 4. Firstly, does the user manually input the directory and filename or does it allow the user to choose the file (through FileDialog or JFileChooser)?
Answer: Just key in the file name. If you make sure that your .class files and the Load file are all in the same directory and you run the program from that directory you should not need the path. Refer to lessons 5-7 and 5-8 in ProgramLive for details for reading and writing to a file.

April 1
Question: Also, are there any specific restrictions to A4? I was thinking of using commands we have never covered in the lecture so far, such as 'try' and 'catch(Exception e)'.
Answer: Yes you can use parts of the API or the language that we have not taught in the course if you can make a case for it being a good way of solving the problem described in the assignment. You shouldn't need the try and catch structure because we will test your program on correct input.

April 1
Question:I have problems running the TestIO.java file Can you tell me how to run it? I get a message saying that I dont have the "PROGR~16.EXE needed to run java files". Can I run it from DrJava?
Answer: You should be able to run TestIO.java from DrJava. Make sure that your InputOutputOperations.class file is in the same directory as your TestIO.class file.

March 30:
Question: Is the customer allowed to order more than 1 pizza of the same kind?
Answer: No, only one pizza can be ordered by a single customer at a time.

March 30:
Question: Is the date format of mm/dd/yyyy an assignment requirement or can we use yyyy/mm/dd in our implementation?
Answer: Please use the same format that we use. Two reasons: It will make the testing of you program easier. Also the mm/dd/yyyy format is the same format that is used in the load file so whatever code you use to store the date/time information when storing the load data can also be used to store the date/time input that is read for an order ot a delivery.

March 30:
Question: For determining waiting times, may we assume all orders are delivered on the same date, between 00:01 and 24:00 hours?
Answer: No. Check the sample run. It is possible that a pizza could be ordered late one day and not delivered until after midnight.

March 30:
Question: I'm considering updating the customer data base when orders are delivered and NOT when the order is received. (Cancelations?) Is this appropriate?
Answer In my solution I updated the customer data when the pizza is ordered. Our application is restricted so does not have the ability to cancel an order.

March 30
Question: I dont know what to do with the InputOutputClass.class file, if it cant be displayed properly on my computer. or any computer for that matter. should it be a .java file for the students to download or something?
Answer: You use the InputOutputOperations.class, you don't display it. Save the file in the directory with your other .class files. Refer to the class API above to see now to use it.

March 30:
Questions: I have a question about the "Save" command. I don't understand it's purpose or where it fits in. Does the user of the program have to hit save every time they enter in a pizza order? or whenever a pizza is delivered? or is it just at the end of the "day" and all orders and have been delivered and the pizza place wants to save their customer data for the next day?
Answer: The save command is to save the current information at the end of the run (end of the day).

March 30
Question: For the order command, it says "The order instruction includes the customer's phone number, date and time of the order, pizza size and a list of toppings." Does it mean that we have to prompt user for ALL these information?
Answer: In my solution I request related information together, for example date and time.

March 30
Question: Should we use new Date() in the Order method to get the order date and time instead of having the user input it?
Answer No you can't use the Date class because it gives you current date and time. As I say in the assignment description, the program is not really realistic. So key in a date and time for both the order and delivery times.

March 30
Question: When I run TestIO.java with the InputOutputOperations.class provided, for the last part (testing the pickChoices method) there is an error message when I pick a choice, say "Lily", that is not in the list (Fred Bob Alice), there is an error message IMMEDIATELY. But when I write my own InputOutputOperations class and test it with TestIO.java, when I pick a choice that is not on the list, it lets me keep typing until i key in "done". Then it displays only the choices that are both in the list and i have made that choice. Does it matter if it doesn't produce any error message when the user input a choice that is not on the list?
Answer: First DON'T write you own InputOutputOperations class. Use the class that we have provided. Yes the class should give an error message and stop if you do not pick one of the choices listed. The only possible choices are those that are listed.

March 30
Question: For the data file of past customer records, can we not assume that data for each customer is in a seperate line?
Answer:Yes, you can assume that the format of the data file is as illustrated in the sample.