Please read carefully and follow the instruction: Create the following classes. Use appropriate access modifiers (instance variables should be private!) and data types for each. Don’t forget to add getter and setter functions.
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
Please read carefully and follow the instruction:
Create the following classes. Use appropriate access modifiers (instance variables should be private!) and data types for each. Don’t forget to add getter and setter functions.
- Item: This class has the attributes (member variables) called title, description, and price.
- Book: This class inherits from Item Book extends Item. It has an instance variable called pageCount
- Movie: This class inherits from Item. Movie extends Item. It has an instance variable called length
- CD: This class inherits from Item. CD extends Item. It has an instance variable called trackCount.
2.Write a class called Book that contains instance data for the title, description, price, pageCount and copyright date. Define the Book constructor to accept and initialize this data. Include setter and getter methods for all instance data. Override toString() method to returns a nicely formatted, multi-line description of the book.
3.Write another class called Bookshelf, which has a name and array of Book objects. Bookshelf capacity is maximum of five books (do not use an arrayList) . Includes method for Bookshelf that adds, removes, isFull( returns Boolean), isEmpty(returns Boolean) and toString() method that returns all information about the Books in the Bookshelf.
4. Create a driver class called TestProject, whose main method instantiates five Book objects, two Movie objects and two CD objects. Use a constant name, no need for scanner.
Example:
Book b1 = new Book(“Java Book”,”Laing”,200.0,2016,”11-20-2020”);
Movie x = new Movie(“ET…”,”Et was from Jupiter”,6.0, 2);
CD cd = new CD(“Best”,”Xcompany”,15.0, 120);
.5.Create an array of Item of size 9.
Item [] ar = new Item[9];
- Assign all nine objects created to this array.
7.Use the loop for each to print all element of the array ar.
for(Item aItem : ar)
System.out.println(aItem);
8.Now you have nine objects in the array of ar. Five books, two Movies and two CDs.
9 Use the following loop:
for(int i=0; I < ar.lenght; i++)
{
// try to add books from array ar to Bookshelf array.
// print the book pageCount using getPageCount() method
// print Movie length using getLength()
// print CD trackCount using getTrackCount.
}
10 Print Bookshelf content
11 Now create a new book.
Book aNew = new Book((“Java Book”,”Laing”,”Pearson”,200.0,2016);
Add aNew book to the Bookshelf using its add method.
The Bookshelf should print if there is a duplicate.
- at last print content of array ar.
Submit .java files only.
Trending now
This is a popular solution!
Step by step
Solved in 5 steps with 4 images