Program takes three types of polyhedra from an input file


1. The Problem

This assignment deals with a program takes three types of Polyhedra from an input file and constructs the appropriate objects.

In this exercise, you will be completing the Polyhedron Hierarchy-specifically the Composite class.

In this assignment, you will be solving a similiar problem, in Java.

1 Input

The program reads data from one file, polyhedra1.txt. File extensions on Linux may be arbitrary-i.e., this file could have been named with .dat as the extension.

sphere 1
cylinder 2 1
sphere 4
cylinder 2 3
composite 3
    sphere 3
    sphere 5
    sphere 7

composite 2
    cylinder 1 2
sphere 5
sphere 3

Each polyhedron line is formatted as a keyword-i.e., the name of the polyhedron-and all appropriate attributes. A sphere is defined by a radius:

sphere 1

A cylinder with height 2 and radius 3 would take the form:
cylinder 2 3

A composite shape us defined by an integer representing the number, n, of polyhedra of which it is composed. It is then followed by n polyhedron input entries:

composite 2
cylinder 1 2
sphere 5

You may assume a valid input file. All input is well-formed.

1.2 Output

The output consists of two reports written to standard output, one after the other.

1. A report listing all polyhedra that were read from polyhedra1.txt.

2. A report listing the result of scaling all polyhedra.

If the program is run with the polyhedra1.txt as the input file, the following output should be generated:

Original Polyhedra
------------------------------------------------------------
[Sphere] (2.0, 2.0, 2.0)->Radius: 1.0 Diameter: 2.0
[Cylinder] (2.0, 2.0, 2.0)->Radius: 1.0 Height: 2.0
[Sphere] (8.0, 8.0, 8.0)->Radius: 4.0 Diameter: 8.0
[Cylinder] (6.0, 6.0, 2.0)->Radius: 3.0 Height: 2.0
[Composite] (14.0, 14.0, 14.0)->3 polyhedra
 [Sphere] (6.0, 6.0, 6.0)->Radius: 3.0 Diameter: 6.0
 [Sphere] (10.0, 10.0, 10.0)->Radius: 5.0 Diameter: 10.0
 [Sphere] (14.0, 14.0, 14.0)->Radius: 7.0 Diameter: 14.0

[Composite] (10.0, 10.0, 10.0)->2 polyhedra
 [Cylinder] (4.0, 4.0, 1.0)->Radius: 2.0 Height: 1.0
 [Sphere] (10.0, 10.0, 10.0)->Radius: 5.0 Diameter: 10.0

[Sphere] (6.0, 6.0, 6.0)->Radius: 3.0 Diameter: 6.0

Scaled Polyhedra (Clones)
------------------------------------------------------------
[Sphere] (4.0, 4.0, 4.0)->Radius: 2.0 Diameter: 4.0
[Cylinder] (4.0, 4.0, 4.0)->Radius: 2.0 Height: 4.0
[Sphere] (16.0, 16.0, 16.0)->Radius: 8.0 Diameter: 16.0
[Cylinder] (12.0, 12.0, 4.0)->Radius: 6.0 Height: 4.0
[Composite] (28.0, 28.0, 28.0)->3 polyhedra
 [Sphere] (12.0, 12.0, 12.0)->Radius: 6.0 Diameter: 12.0
 [Sphere] (20.0, 20.0, 20.0)->Radius: 10.0 Diameter: 20.0
 [Sphere] (28.0, 28.0, 28.0)->Radius: 14.0 Diameter: 28.0

[Composite] (20.0, 20.0, 20.0)->2 polyhedra
 [Cylinder] (8.0, 8.0, 2.0)->Radius: 4.0 Height: 2.0
 [Sphere] (20.0, 20.0, 20.0)->Radius: 10.0 Diameter: 20.0

The easiest way to see generate the expected output is to run the sample executable solution I have provided. These two files are named as command-line parameters when the program is executed.

For example, if the sample data above is kept in polyhedra1.txt, to run this program, type:
java -jar CreatePolyhedra.jar polyhedra1.txt 2

Run the compiled solution with both the provided input file and your own test input files.

Once you have completed your solution, compare the output generated by your solution to the output generated by my solution. The two sets must be identical.

(On a Windows system, you would omit the "./". If you are running from Eclipse or a similar development environment, you may need to review how to supply command-line parameters to a running program.)

Your Tasks

Complete clone (copy constructor portion), scale, and toString functions for Composite class.
- Note that I have provided you a clone function and a skeleton for a copy constructor. Complete the copy constructor.
- Note the hints in the toString function.

Attachment:- Java.zip

Solution Preview :

Prepared by a verified Expert
JAVA Programming: Program takes three types of polyhedra from an input file
Reference No:- TGS01372699

Now Priced at $75 (50% Discount)

Recommended (97%)

Rated (4.9/5)