0% found this document useful (0 votes)
2 views

Problem 1

The document outlines the implementation of a class hierarchy involving a Publication class, a Book subclass, and a NewsStand class. It includes specifications for constructors, getters, setters, and toString methods, as well as a Demo program to test the functionality with an array of Publication and Book objects. Additionally, it describes methods for displaying specific objects, searching for NewsStand instances, and finding the one with the highest price.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Problem 1

The document outlines the implementation of a class hierarchy involving a Publication class, a Book subclass, and a NewsStand class. It includes specifications for constructors, getters, setters, and toString methods, as well as a Demo program to test the functionality with an array of Publication and Book objects. Additionally, it describes methods for displaying specific objects, searching for NewsStand instances, and finding the one with the highest price.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Problem to manipulate classes, array of objects, inheritance polymorphism, composition,

and recursion.
Implement the following classes:
1- Declare the class Publication with 2 members: owner, which is a string, and price, which is a double.
Members of this class must be accessible only by its subclasses. Inside this class, do the following:
a. Write a constructor for this class that initializes all members from its parameters.
b. Write a getter for every member of the class.
c. Write a setter for every member of the class.
d. Write the toString method that returns the details of all members in one string.

2- Declare the class Book as a subclass of the Publication class with one private string member ISBN and the
following methods:
a. Write a constructor for this class that initializes all the members, including superclass members, from
its parameters.
b. Write the toString method that returns the details of all members, including superclass members.

3- Declare the class NewsStand with two private data members: standName, which is a string, and pub, which is
a Publication. Inside this class, do the following:
a. Write a constructor for this class that initializes all the members from its parameters.
b. Write a getter method for standName.
c. Write the toString method that returns the details of all members in one string.

4- Write a program Demo to test your implementation. In the main method:


a. Declare an array P of six elements that can hold objects of type Publication and Book.
b. Type the following code:
P[0] = new Publication("owner1", 1020);
P[1] = new Book("Malek", 1199.98, "12332100");
P[2] = new Publication ("owner3", 3670);
P[3] = new Book ("Bravaco", 999.95, "98778911");
P[4] = new Book ("Simonson", 1024.99, "45665433");
P[5] = new Publication ("owner2", 2510);
c. Call the method display that, using a loop, displays ONLY the elements of P that contain Book
objects. Write this method.
d. Call the recursive method recPrint that displays all the elements of P. Write this method.
e. Declare an array myStands of five elements that can hold objects of type NewsStand.
f. Insert into myStands three instances of NewsStand with these stand names, publication owners, and
prices:
(Stand1, Saleem, 789.0),
(Stand2, Saeed, 123.4), and
(Stand3, Sameer, 456.7).
g. Call the method Search that, using a loop, returns the NewsStand object with Stand2 as a name.
Write this method.
h. Call the method HighestPrice that, using a loop, returns the NewsStand object with the highest price.
To write this method, what member methods must be added to the class NewsStand?

You might also like