Assignment #2           

 

Write a Java standalone application program that calculates the perimeter, area and volume of geometric figures. The permissible figures are shown below:

 

 


                                                                               

 

 

 

   Rectangle                                     Triangle                                                       Circle

 

 

 


      h                                h

               

 

 

 


 Cone                              Pyramid                             Cuboid                            Cylinder

 

·         Define the following classes to find perimeters.

q       perimeterOfTriangle

q       circumferenceOfCircle

q       perimeterOfRectangle inherits perimeterOfTriangle

Put these classes in a package called Perimeter

 

·         Define the following classes to find areas:

q       areaOfCircle

q       areaOfTriangle

q       areaOfRectangle

q       areaOfCylinder inherits circumferenceOfCircle, including the button and the top lids.

q       areaOfCuboid inherits areaOfRectangle

Put these classes in a package called Area

 

·         Define the following classes to find volumes: 

q       volumeOfCylinder inherits areaOfCircle

q       volumeOfCone inherits volumeOfCylinder

q       volumeOfCone inherits volumeOfCylinder

q       volumeOfCuboid inherits areaOfRectangle

q       volumeOfPyramid inherits volumeOfCuboid

Put these classes in a package called Volume

 

·         Define an abstract class called measurement to contain the following abstract methods. 

q       perimeter () - that finds the distance around any triangle, rectangle, or circle.

q       area () - that finds the surface area of the figures in package area.

q       volume ()- that finds the volume of those figures in package Volume.

 

Note:

1.    This class must be used by the classes that finds perimeter, area, or volume.

2.    The volume of: the cone is: 1/3 * p * r2* height, the volume of the pyramid is:

1/3 * area of the base * height.

 

·         Define an interface called constants containing the following:

q       Numeric values such as 1/3.

q       A numeric array containing the dimensions of each figure.

q       A string array containing the name of each of the figures.

q       An abstract method called print (), which will be used to print the name of each figure, once the figure has been identified in processing.

 

Define a class called dimensions.  This class will contain the driver program.  Place this class also in the package called mainSolid.

 

Place the four packages – Perimeter, mainSolid, Area, and Volume - on the same directory level.

 

Place the abstract class, measurement and the interface, constants, in a directory called geometry.  Place this directory one level below the directory mainSolid.

 

Make each of the following classes a terminal class: volumeOfCone, volumeOfPyramid, perimeterOfRectangle, and areaOfCylinder.

 

·   Use the following data set to test your program: (The data is in italic bold).  The x represents the values that must be calculated.  The dashed lines indicate that no value is given, nor are you expected to fill them with calculated values.

 

Figure               Side/Radius    Side         Side    Height    Perimeter          Area        Volume

Triangle                 3                4            5          -              x                 x                -

Circle                     5                -           -             -              x                 x                -

Cylinder               10                -           -           20             -                  x                x

Cuboid                   4               4           -            8              -                   x               x

Rectangle           10              20           -           -              x                 x                -

Triangle                9              12           15        -               x                 x                -

Cone                     4                -            -          8               -                  x                x

Pyramid                6                6           -         12               -                  -                 x

 

 

·         Note:

q       Use a two dimensional numeric array to store the numeric values as you did in assignment 1.

 

q       Use a one dimensional string array to store the name of each figure. For example,

                    String figure [] = {“Triangle”, “Circle”…,};

 

 


Go Back