Download COMP 241: Object-Oriented Programming with Java

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
COMP 241: Object-Oriented Programming with Java
Fall 2003
Homework Assignment 7
Due by 23:59, Friday, Dec. 3, 2004
1- Do Exercise 8.16 in your textbook (about IntegerSet).
2- Create a class FancyIntegerSet that extends the class IntegerSet from
Problem 1. FancyIntegerSet should include the following extra methods:



minElement() returns the smallest integer in the set
maxElement() returns the largest integer in the set
elementByRank(int k) returns the kth smallest integer in the set, if one
exists, -1 otherwise (assume that no negative numbers are stored in the set).
To achieve efficient implementations for minElement() and maxElement(), maintain two
fields, minElt and maxElt that contain the smallest and largest integers among the current
contents of the set, respectively.
Argue the pros and cons of making the Boolean array in IntegerSet protected
vs. private. Insert this as a comment into your code in FancyIntegerSet. Write a
test class that tests your new class. Let the user first give the contents of the
set by entering a number of integers, and then remove some integers from the list, and
also give the minimum and maximum integers in the set at the end.
MenuItem
FoodItem
Salad
Drink
Pide
3- Pideci: Download the file pideci.zip
(http://network.ku.edu.tr/~stasiran/comp241/Homework/pideci.zip) which contains
skeletons for the classes shown in the hierarchy above.
For each field and method listed in each class skeleton, choose the visibility (i.e., public,
private, protected, or package). Implement all methods listed in skeletons. Implement proper
constructors for each class. Additionally, for each class, override the toString() method and
implement a toDetailedString() method that returns in a String more information than
toString(). The cost() and profit() methods should return the cost and profit of the particular
menu item to the Pideci. For the getNumberOfCalories() method of FoodItem, use the fact
that each gram of carbohydrates and protein gives 4 calories, each gram of fat gives 9
calories. Put all the classes in this hierarchy in a package called “lokanta”.
Also implement a class called CustomerOrder in another package called “customer” that
represents a meal including (possibly) a salad, a drink and a pide. It should have
-
A reasonable set of constructors
Fields (with proper visibility), add() and remove() methods for the salad, drink and pide
Methods for computing the total price, total calories, and total cost to the restaurant of the
customer’s order.
A “toString()” method that lists the items and the total price of the meal
A “main()” method whose purpose is to build several (at least two) CustomerOrder
objects (by creating Drink, Pide and Salad objects first) and to test them. Let the user to
determine his/her menu by asking several questions about the menu items.