Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this lab assignment, you are asked to write java code of given classes in the following class diagram. Instructions: - Create classes with defined

image text in transcribed

image text in transcribed

image text in transcribed

In this lab assignment, you are asked to write java code of given classes in the following class diagram. Instructions: - Create classes with defined attributes. - Write the methods of classes according to the given signatures. - You can get class name using the following code in java: this.getClass().getSimpleName(): - The methods print(), getPrintingPrice() give information when it is invoked. It prints out the class name and "...method is invoked ". i.e. print() method has the following line: System.out, print1n(this, getclass().betsimplevare() + " Print wothod is Inmoteme:" ); - Part of the code for this class given below. public ciass Material pubaic doubla getwumberofpages () \{ raturn numberOfPages: 3 publie vold setNumberDfpages(double nuaberofpages) ( thas, numberofpages a nuaberofpagni;, ) public double getPagePrice() \{ return pagePrice; ) public void setpageprice(double pagepmire) 1 this pagePrice = potepricis 3 public vold print() ( Systen.out.println(this. getClass(). getsimplelane() , " print rethod is involied"); Systen, out, printlin("This methou phint naterial of class" + this,getClass().getsimplevare()); 1 - In the subclasses: - Override the getPrintingPrice () method of super class, The method calculates the price of the instance Price formulation for book: Price=Number of Pages * Page Price + starting Price Price formulation for journal: Price=Number of Pages " Page Price + Fixed Journal Price + starting Price (fixed journal price as a constant final attribute. (fixed journal price =10) ) - Overload the print) methods (with a parameter to call that method). - The method calls the print method of the super class at the first line. o prints out the name of the class and the method: System.out.printin(this. getchass () -getsimpleName() + " print method is invoked"); prints out the following line: * "This method is overloaded with an double parameter the value is: " + val. (for Journal and book classes) - To test your code, inside main method, invoke getPrintingPrice() and print() methods of related classes to obtain the given output. Expected Output: Material getPrintingPrice nethod is invoked Material price is: 160.0 Book getprintingPrice nethod is invoked Book price is: 116,0 Journal getPrintingPrice nethod is invoked Journal price is: 225.6 Material print method is invoked This method print material of class Material Book print method is invoked This method print material of class Book Book print method is invoked This method print matertal of class Book Book print method is invoked This methad is overloaded with a double parancter the value is: 20.0 Pournal print method is invoked This wethod print material of class Journal pourna1 print method is invoked This method print material of class Jaurnal journal print wethod is invoked This method is overloaded with a double paraneter the value is: 10

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

More Books

Students also viewed these Databases questions