Creates an array capable of holding four shape objects

Assignment Help C/C++ Programming
Reference no: EM132076134

Need help with this java program

use the code below to solve this problem

The Shape class is abstract and contains one method: getArea. Your task is to create two subclasses of Shape: Circle and Square. Then, you should write a driver program with a main method that creates an array capable of holding four Shape objects.

Populate your array with two Circle objects and two Square objects. Finally, call the getArea method on each Shape in your array and display the results.

You should not make any changes to Shape.java.

Hints: In case you have repressed your memories of geometry class, the area of

a circle is pi times the radius squared, where pi is approximately 3.14159. Java has the value of pi stored more accurately as the constant Math.PI. The area of a square is

the length of its side, squared. You will likely need to declare fields in your Circle and Square classes to hold the radius and side length, respectively.

You will also need constructors for each class, to initialize the fields of the class.

Example Assume your array of Shape object contains the following:

A circle with a radius of 1

A circle with a radius of 5.27

A square with a side of length 14

A square with a side of length 10

Then the output of your driver program should be:

3.141592653589793

87.25113860888395

196.0

100.0

here is the code so far:

******lab.pkg1.practice.starting.code******(driver class)

package lab.pkg1.practice.starting.code;

public class Lab1PracticeStartingCode {

public static void main(String[] args) {
// TODO write code here to create an array of four Shape objects,
// call the getArea method of each one, and display the results.
}

}

*****shape.java*******

package lab.pkg1.practice.starting.code;

public abstract class Shape {

public abstract double getArea();
}

Reference no: EM132076134

Questions Cloud

Find the total distance traveled by the object : Find the total distance traveled by the object during the time interval 0
Create a gui application for a pizzeria : Extra Large ($14) The user may also choose any number of toppings at a cost of $1.00 per topping.
Construct a contour diagram : Construct a contour diagram for z=e^(x-y^2-1) with two level curves. show your steps
Critical points of f as either saddle : Find and classify all critical points of f as either saddle, local min or local max.
Creates an array capable of holding four shape objects : Create two subclasses of Shape: Circle and Square. Then, you should write a driver program with a main method .
Using recursion determine the number of tribble for any hour : Write a JAVA program that uses recursion to determine the number of tribble for any hour.
Write three overloaded methods that calculate averages : The first method takes two integer parameters, the second takes three integer parameters, and the third takes four integer parameters.
Write a recursive function called sumdigits : Write a recursive function called sumDigits with the following signature: public static long sumDigits(long n).
Create a package named reading_with_exceptions : Create a package named "reading_with_exceptions". Write a class named: Reading_With_Exceptions with the following method.

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd