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

  Write c program which has parent process and child process

Write a C program that has a parent process, a child process, and a grandchild process. The parent process should print its id and the square or 5.

  Access a two-dimensional array one element at a time by rows

Nested for loops provide sequential access to multidimensional array elements. To access a two-dimensional array one element at a time by rows.

  Write a program that takes a string as input

Write a program that takes a string as input (from the user) and then reverses the contents of the string. Your program should work by using two pointers.

  Write code that will create a two dimensional array

show how you would determine from within the hitWalker method how many columns are in this array. You may assume the array is perfectly rectangular and is not "ragged". Write code that will create a two dimensional array representing the following ma..

  For this program reads the first 11 characters

E main for this program reads the first 11 characters from input, saving them. It then reads 26 short integers into |vals|, and passes them and the characters to EmbedWatermark, which subtly alters the contents of vals to contain the characters. A..

  What is the effective access time for memory

Let the page fault service time be 10 millisecond(ms) in a computer with average memory access time being 20 nanosecond(ns). If one page fault is generated for every 106 memory accesses, what is the effective access time for memory?

  Write the sorted data to the specified output file

How the user would like the contents of the file sorted. The user must be able to sort on any of the columns. in ascending or descending order - Write the sorted data to the specified output file using the same format as the input file.

  Er diagram to the corresponding tables

Chen, the Customer Analyst of Shopping Spree, has to make the ER diagram to represent the preceding situation, and then to map the ER diagram to the corresponding tables. Help Chen to do the same.

  Transformations of the graphic objects

The second project builds on the first project by adding the ability to specify transformations of some of the graphic objects. The specification for those objects now will require less information about their position and size because both will b..

  Write a program that prompts the user to input the masses

Write a program that prompts the user to input the masses of the bodies and the distance between the bodies. The program then outputs the force between the bodies.

  Create a main program that accept as command line parameter

Create a main program (C or C++) in Linux that will accept (as a command line parameter) a number of seconds that the main process is to run, as well as a number of work processes to be created. The function of the main program will be to create a nu..

  If a class is derived protected

If a class is derived protected from a base class, explain how this affects the inheritance of all public, protected, and private members of the base class by the derived class.

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