Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use Java... (a) Inheritance Design and implement a set of classes that define various types of reading material. Start by defining a parent class called

Use Java...

(a) Inheritance

Design and implement a set of classes that define various types of reading material. Start by defining a parent class called ReadingMaterial. This class should contain the following instance variables : title - a String containing the title of the reading material author - a String containing the author of reading material numPages - an integer containing the number of pages in the reading material All three variables should be initialized with values passed into the constructor . ReadingMaterial should also have two functions: isLong - takes no parameters and returns a boolean . If the book has more than 250 pages, this function should return true . Otherwise it returns false . summary - takes no parameters and returns nothing. This function should print out information about the book in the form "[title], written by [author]". Three classes should inherit from Reading Material: Novel, GraphicNovel, and Article. The Novel class should have the following specifications: An instance variable called characters that contains an array of Strings with the names of the principle characters in the novel (this variable should be initialized with a value passed into the constructor , along with the novel's title, author, and number of pages). A function called listCharacters which prints out the name of all the primary characters in the order that they are listed, each on their own line. The Article class should have the following specifications: A String instance variable called publication that indicates which publication the article was published in. This should be initialized in the constructor . An overridden version of the summary function that prints out information about the article in the folowing form: "[title], written by [author], published in [publication]" The GraphicNovel class should inherit directly from the Novel class and have the following specifications: A String instance variable called illustrator that contains the name of the person who illustrated the Graphic Novel. (This variable should be initialized with a value passed into the constructor , along with the novel's title, author, and number of pages, and main characters .) An overridden version of the summary function that prints out information about the book in the following form: "[title], written by [author], illustrated by [illustrator]." Test the classes in a Driver class . Make one of each object : A Novel, harryPotter, with the title Harry Potter, author JK Rowling, 303 pages, and the main characters Harry Potter, Hermione Granger, Ronald Weasley, and Voldemort. A GraphicNovel, avengers, with the title Avengers, author Stan Lee, 50 pages, the characters Iron Man, Captain America, Black Widow, The Hulk, and Thor, and the illustrator Jack Kirby. An Article, pc, with the title The Social Meaning of the Personal Computer, author Bryan Pfaffenberger, 10 pages, and the publication Anthropological Quarterly. In the Driver class , print out the summary of harryPotter, the result of harryPotter's isLong function, the list of characters in avengers, the summary of avengers, the result of pc's isLong function, and the summary of pc, with each item on its own line.

(b) Polymorphism:

Implement the Speaker interface: public interface Speaker { public void speak(); public void announce(String str); } Then, create three classes that implement Speaker in various ways:

SpeakerOfTheHouse: speak method prints "I am Speaker of the House.", and the announce method takes the name of a bill in the form of a string and prints it in the sentence "The [bill] has passed!"

SportsAnnouncer: speak method prints "Goal!", and the announce method takes the name of a team in the form of a string and prints the sentence "The [team] have scored a goal!"

Actor: speak method prints "I've been nominated for three Academy Awards.", and the announce method takes the name of a movie in the form of a string and prints the sentence, "I'm currently staring in [movie]."

Create a driver class , and in the main method , prompt the user to enter three Strings -- the name of a bill, the name of a sports team, and the name of a movie. Then, create an object from each of the classes described above and call the speak and announce methods of each object , using the strings provided by the user.

(c) Using Classes in java Library

(1) Write a program

to create a 2x10 two dimensional integer array .

use Math.random() from java.util.Random to generate 20 integer numbers from 100 to 1000

store each random number in the two dimension array.

At the end, print the array. Then switch numbers between two rows then print the array again.

(2) Write a program to accept input string from keyboard and uses substring method to revert

the string and print it out.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introductory Relational Database Design For Business With Microsoft Access

Authors: Jonathan Eckstein, Bonnie R. Schultz

1st Edition

1119329418, 978-1119329411

More Books

Students also viewed these Databases questions

Question

Define knowledge management and describe its purposes.

Answered: 1 week ago

Question

What are the types of companies that benefit from implementing CRM?

Answered: 1 week ago

Question

What is the Definition for Third Normal Form?

Answered: 1 week ago

Question

Provide two examples of a One-To-Many relationship.

Answered: 1 week ago