Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Instructions Create a Shape class 1. Using the abstraction concept of OOP, define variables and methods in the Shape class that are common to the

Instructions Create a Shape class

1. Using the abstraction concept of OOP, define variables and methods in the Shape class that are common to the Circle and Rectangle classes (see UML Class Diagram section)

A. Encapsulate the variables and methods appropriately

1. Public All objects in the program have access

2. Protected Only objects that inherit the class have access

3. Private Only the object has access

2. Update the Circle and Rectangle classes to inherit the Shape class Note: In Java, a class inherits another class using the extends keyword.

3. Remove the common variables and methods from the Circle and Rectangle classes

A. Override methods as needed Note: Overriding a method is necessary when an object behaves differently from the inherited objects behavior.

1. Use @Override to indicate the method is overriding an inherited method

4. Create a UML Class Diagram of the Circle, Rectangle and Shape classes

A. Show that the Circle and Rectangle classes inherit the Shape class Create a Java program that performs the following tasks:

1. Implement the classes defined in the UML Class Diagram created in step 4 above

2. Prompt the user for the following inputs (doubles)

A. The radius (length) of a circle

B. The length and width of a rectangle

3. Create the object instances of the Circle and Rectangle classes

A. Pass the radius (length) as the parameter for the Circle class constructor 1. Circle circle = new Circle(radius);

B. Pass the length and width as the parameters for the Rectangle class constructor 1. Rectangle rectangle = new Rectangle(length, width);

4. Perform the calculations

A. Calculate Area 1. circle.calcArea();

B. Calculate Perimeter 1. rectangle.calcPerimeter();

5. Display the results of the Circle and Rectangle calculations (see Example Output section)

A. Display decimal values to three decimal places

Example Output

Homework 6 Ima Java Programmer

Enter the radius of a cicle [1 to 10]: 4

Enter the length of a rectangle [1 to 10]: 5

Enter the width of a rectangle [1 to 10]: 8

Circle:

Area: 50.265

Perimeter: 25.133

Rectangle:

Area: 40.000

Perimeter: 26.000

image text in transcribed

UML Class Diagram Circle Rectangle area double area double length double length double perimeter double perimeter double width double width double Circle (length double) void Rectangle(length double, width double) void calcArea( void calcArea void calcPerimeter void calcPerimeter void getArea double getArea double getPerimeter(): double getPerimeter(): double setLength (length double) void setLength (length double) void setWidth (width double) void

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

Advanced Database Systems

Authors: Carlo Zaniolo, Stefano Ceri, Christos Faloutsos, Richard T. Snodgrass, V.S. Subrahmanian, Roberto Zicari

1st Edition

155860443X, 978-1558604438

More Books

Students also viewed these Databases questions

Question

Describe the factors influencing of performance appraisal.

Answered: 1 week ago

Question

What is quality of work life ?

Answered: 1 week ago

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago