Você está na página 1de 2

TUTORIAL 2: ON OBJECTS & CLASSES,

INHERITANCE AND POLYMORPHISM

28 March 2017
Lectured by Jerelyn Pillay and Alicia Nair

1. Develop a java application. Your application should have two classes, a Stock class and a
test/main class. Design a class named Stock that contains:
A string data field named symbol for the stocks symbol.
A string data field named name for the stocks name.
A double data field named previousClosingPrice that stores the stock price for the
previous day.
A double data field named currentPrice that stores the stock price for the current
time.
A constructor that creates a stock with the specified symbol and name.
A method named getChangePercent() that returns the percentage changed from
previousClosingPrice to currentPrice.

Create a test/main class to create your Stock objects and invoke your methods.

2. Develop an application to manage a database of multimedia items. The user has many
multimedia items that include audio CDs, DVDs and PC games. The application/project
must allow the user to :
Store his multimedia items
Search through the database of stored items to find particular items.
Print out items
1. Create a project called DOME, within that create a package called dome.
2. Write a class called Item. The Item class represents all that is common between various
multimedia items. It should have the following attributes :

- A String name to store the name of the item


- A String comment to store a comment about the item
- A double value to store the items cost

3. It should have the following methods :


- Getters and setter methods for all the attributes
- A toString method
4. Now create two additional classes to represent the multimedia items, CDs and DVDs, we
store.
(Note: the use of inheritance)
5. Write a CD class that extends the Item class. The CD class has a String artist field and an
int playTime field.
6. Write a DVD class that extends the Item class. The DVD class has a String director (the
director of the movie) and an int runningTime. Provide the correct constructors and
override the toString() method.
7. Write a main class/ test class and create objects to test your classes

Você também pode gostar