![]() |
| CS Home » My Home Page » Teaching Archive 2005/6 » COMP1008 » Exercises 2 |
COMP1008 Object-Oriented Programming 2006Programming Notes and Exercises 2Recommend finishing date: Friday 3rd February 2006Purpose: To work with and modify a small object-oriented Java program. Goal: Complete as many of the exercise questions as you can. If you are keeping up, you need to do at least the core questions. The additional questions are more challenging and are designed to stretch the more confident programmers. Don't worry if you can't do them now, but be prepared to come back and try them later on. Feedback: It is important that you get feedback on your exercise answers so that you know they are correct, that you are not making common mistakes, that the program code is properly presented and that you are confident you have solved the problem properly. To do this, get your answers reviewed by a lab demonstrator during lab sessions. NOTE: You must keep all exercise answers as they form a record of your progress. After the exams you may be required to hand-in all exercises and coursework answers, as part of the course assessment process.
Getting StartedThese exercise questions require you to work with the SimpleOrderSystem program introduced in the lectures. To get the source code do the following: Either:
Or for use with BlueJ:
Exercise QuestionsEach of these questions involves working with, modifying and/or extending the SimpleOrderSystem application. Q1. Spend some time looking through the code, so that you understand how it works. Use BlueJ to run the code, and experiment with creating and using objects. Q2. Add a command to display the total value of all orders for all customers. You will need to add a menu item, and add a method called overallTotal that will be called from the doOption method. OverallTotal will need to iterate through each customer adding up their total for all their orders. Q3. You need to test your code to make sure it works. We haven't looked at testing yet, or loading/saving data to a file, and it is tedious having to type in customer and order information every time you run the program. Add an initialise method to class SimpleOrderSystem that creates a collection of example objects that you can then use to see if your code works. For example: public void initialise() {
Product p1 = new Product(1,"Widget",100);
products.add(p1);
... // Repeat for more Products
LineItem i1 = new LineItem(2,p1);
... // Repeat for more LineItems
Order o1 = new Order();
o1.addI(i1);
... // Repeat for more orders
Customer c1 = new Customer("Arthur","Dent","Earth","1233556","arthur@earth.com");
customers.add(c1);
c1.addOrder(o1);
}
Q4. Add a command to edit a customers details (name, address, phone or email). Do this by creating a new Customer object and transferring the orders from the old customer to the new customer (use the getOrders method and add each order to the new Customer). Q5. Customers have mobile phones! Add a mobile phone instance variable to class Customer and modify the class and the rest of the program to work with mobile phone numbers as well as ordinary phone numbers. Q6. Add the ability to display the list of all orders for a Customer, showing each item in the order. Q7. Add the ability to display a list of each order that includes a selected product. For each order, the customer name should be displayed.
|
Last updated:
September 2, 2006 |
Computer Science Department - University College London - Gower Street - London - WC1E 6BT -
+44 (0)20 7679 7214 - Copyright 1999-2006 UCL