Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

LE 9.2 DUE 2/13/19 (Inheritance 2) Use all classes you have created in LE 9.1 and create a test class called TestShape2. In the main

image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
LE 9.2 DUE 2/13/19 (Inheritance 2) Use all classes you have created in LE 9.1 and create a test class called TestShape2. In the main method of this class create one array of Cylinder class and one array of Cone class. The size of both arrays should be 3. For each array use a for loop for asking user to input radius and height (3 times) to create objects. Then use an enhanced for loop for each array to show surface area and volume for each object. Sample output has been provided in the next page Sample Output Enter Eadius for eylinder 1: R Enter height for cylinder 1: 2 Enter Eadius for cylinder 2: 5 Enter height for eylinder 2: 10 Enter radius for cylinder 3: Enter height for cylinder J: 11 Enter radius for cone 1: Enter height for cone 1s 6 Enter radius for cone 2: 3 Enter height for cone 2: 2 Enter Eadius for cone 3: B Enter height for cone 3: 15 Acray of Cylinders Surface Area: 18.85 Volume:6.28 Surface Area: 471.24 Volume: 785.40 Surface Area: 791.68 Volume: 1693.32 Atzay of Cones Surface Area: 140-88 Volume : 100.53 Surface Area: 2.26 Volume: 18.85 Surface Area: 20-32 Volume: 1005.31 pablic class Circle double radius final double Pl Math P public Cinclesdoulble rad) this radius-rad publis voidstadiudouble rad) publie double getRadiust return radx public dosble getPl) return Pt: publie double circumferemoco) return (2 Pl radius) public double area) return P" Math powtadia2) k public String toString return "Shape: Cincle nRadius:geRadius) nCiecumferenance: pablic class Cylindcr cxlends Circke double beight: public Cylinderidouble raddouble h) supentrad) this height-h public void setheighidouble h this height h publie double gelfeigh) neturn this height; publix double sarfaccarca0 public double volume return (this height Pl'Math powfradius.2)) Override public String toString return "Shape: CylinderinRadius:gRadius) "nheight this height -nSurfacearea:+surfacearea)inVolume: +volume To change this livense header, choose License Headers in Project Properties. To change this template file, choose Tools | Templates and open the template in the editor. package matheircle author Gajendra public class Cone extends Cylinder f public Cone(double rad, double h) super(rad, h) @Override public double surfacearea0 return (PI'Math.pow super.radius,2+ PI super.radius Math.sqr(Math.pow(super.height,2)+Math pow(super.radius,2) Override public double volume) return (super.volume03) Override public String toString) return "Shape: ConcinRadius: gctRadius0+nheight utput: Shape: Cirele Radius: 2.0 Circumferenance: 12.566370614359172 Area 12.566370614359172 Shape : Cylinder Radius: 5.0 height: 6.0 Surfaccarea: 116.23892818282235 Volume Shape : Cone

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 Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions