Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ex2 Define the class Rectangle that contains double instance variables named width and height, and a static variable named printChar. Include the following: A no-arg

ex2 image text in transcribed
Define the class Rectangle that contains double instance variables named width and height, and a static variable named printChar. Include the following: A no-arg constructor that creates a default rectangle with 1.0 for both width and height. A constructor that creates a rectangle with the specified width, and height. Get and set methods for all the instance variables. A method getArea() that returns the area of the rectangle. A static method setPrintChar() that modifies the static variable A toString() method that returns a String that represents an outline drawing of the rectangle using the character given by printChar, For example, if printChar were 'c' and one Rectangle had a width of 5 and a height of 4, then printing the toString() method to output would give ccccc c c ccccc Write a test program that first sets the printChar for the Rectangle class as '*', then creates two Rectangle Objects of reasonable sizes. Print out each rectangle separately to output using the toString() method, followed by the value of that rectangle's area. Change the printChar to a reasonable (non-white-space) character of your choosing, modify both instance variables for both Rectangle Objects, and then repeat the output process: print out each rectangle separately to output followed by the value of that rectangle's area

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_2

Step: 3

blur-text-image_3

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