Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Define an interface named Shape with a single method named area that calculates the area of the geometric shape: public double area(); Next, define a

  • Define an interface named Shape with a single method named area that calculates the area of the geometric shape:

public double area();

  • Next, define a class named Circle that implements Shape. The Circle class should have an instance variable for the radius, a constructor that sets the radius, an accessor and a mutator method for the radius, and an implementation of the area method.
  • Define another class named Rectangle that implements Shape. The Rectangle class should have instance variables for the height and the width, a constructor that sets the height and the width, accessor/mutator methods for the height and the width, and an implementation of the area method.

The following test code should then output the area of the Circle and Rectangle objects:

public static void main (String[] args) {

Circle c = new Circle(4); //Radius=4 Rectangle r = new Rectangle(4, 3); // Height = 4, Width = 3

ShowArea(c); ShowArea(r);

}

public static void ShowArea(Shape s) {

double area = s.area();

System.out.println(The area of the shape is + area);

}

Defining an Inner Class

  • Rewrite the given classes Employee, HourlyEmployee, so that the class Date is an inner class of the class Employee and an inherited class of the class HourlyEmployee.
  • Write a program to instantiate at least two objects each of type Employee and HourlyEmployee. Display the hire dates for each employee and then modify and display the hire dates for each of the employees.

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

Database Design Query Formulation And Administration Using Oracle And PostgreSQL

Authors: Michael Mannino

8th Edition

1948426951, 978-1948426954

More Books

Students also viewed these Databases questions

Question

8. Explain the contact hypothesis.

Answered: 1 week ago

Question

7. Identify four antecedents that influence intercultural contact.

Answered: 1 week ago