Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello, I have a java code public class ReadingMaterial { //class private member variables protected String title; protected String author; protected int numPages; //Constructor public

Hello, I have a java code

public class ReadingMaterial { //class private member variables protected String title; protected String author; protected int numPages; //Constructor public ReadingMaterial(String title, String author, int numPages) { this.title = title; this.author = author; this.numPages = numPages; } /** * Determines whether the book has more than 250 pages * @return true or false */ public boolean isLong(){ return numPages > 250; } //summary method public void summary(){ System.out.println(title + ", written by " + author); } } public class Novel extends ReadingMaterial{ //Class private member variable String[] characters; //Constructor public Novel(String title, String author, int numPages,String[] characters) { super(title, author, numPages); this.characters = characters; } //listCharacters method /** * Lists each of the character in characters in a new line */ public void listCharacters(){ for(String character : characters) System.out.println(character); } } public class GraphicNovel extends Novel{ //Class private member variable public String illustrator; //Constructor public GraphicNovel(String title, String author, int numPages, String[] characters,String illustrator) { super(title, author, numPages, characters); this.illustrator = illustrator; } //Oerriding summary method @Override public void summary() { System.out.println(title + ", written by " + author + ", illustrated by " + illustrator); } } public class Article extends ReadingMaterial{ //Class private member variable private String publication; //Constructor public Article(String title, String author, int numPages,String publication) { super(title, author, numPages); this.publication = publication; } //Overriding summary method @Override public void summary() { System.out.println(title + ", written by " + author + ", published in " + publication); } } public class ReadingMaterialDriver { public static void main(String[] args){ //Creating Novel 'harryPotter' String[] characters = {"Harry Potter", "Hermione Granger", "Ronalid Weasley", "Voldemort"}; Novel harryPotter = new Novel("Harry Potter","JK Rowling",303,characters); //Creating GraphicNovel 'avengers' String[] avengersCharacters = { "Iron Man", "Captain America", "Black Widow", "The Hulk", "Thor" }; GraphicNovel avengers = new GraphicNovel("Avengers","Stan Lee",50,avengersCharacters,"Jack Kirby"); //Creating Article 'pc' Article pc = new Article("The Social Meaning of the Personal Computer","Bryan Pfaffenberger",10,"Anthropological Quarterly"); //Summary of harryPotter harryPotter.summary(); //The result of harryPotter's isLong() function System.out.println(harryPotter.isLong()); //List of characters in avenegers avengers.listCharacters(); //Summary of avengers avengers.summary(); //Result of pc's isLong() function System.out.println(pc.isLong()); //Summary of pc pc.summary(); } }

I am getting the error

Driver.java:1: error: class ReadingMaterial is public, should be declared in a file named ReadingMaterial.java public class ReadingMaterial { ^ Driver.java:28: error: class Novel is public, should be declared in a file named Novel.java public class Novel extends ReadingMaterial{ ^ Driver.java:50: error: class GraphicNovel is public, should be declared in a file named GraphicNovel.java public class GraphicNovel extends Novel{ ^ Driver.java:68: error: class Article is public, should be declared in a file named Article.java public class Article extends ReadingMaterial{ ^ Driver.java:85: error: class ReadingMaterialDriver is public, should be declared in a file named ReadingMaterialDriver.java public class ReadingMaterialDriver {

I am trying to get a desired input of

HarryPotter,writtenbyJKRowling true IronMan CaptainAmerica BlackWidow TheHulk Thor Avengers,writtenbyStanLee,illustratedbyJackKirby false TheSocialMeaningofthePersonalComputer,writtenbyBryanPfaffenberger,publishedinAnthropologicalQuarterly

I am writing this code onto the website directly and from there the website will compile and tell me if its correct or wrong since I can't upload a file to it. Would I just need to remove the 'public' before the class to get the desired output?

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

Java How To Program Late Objects Version

Authors: Paul Deitel, Deitel & Associates

8th Edition

0136123716, 9780136123712

More Books

Students also viewed these Programming questions