Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Java Expert


Home >> Java

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

Java, Programming

  • Category:- Java
  • Reference No.:- M91751261
  • Price:- $75

Priced at Now at $75, Verified Solution

Have any Question?


Related Questions in Java

Answer the following question whats the difference public

Answer the following Question : What's the difference public inheritance and private inheritance? What can derived classes inherit from base classes? What cannot be inherited from base classes?

Question slideshows or carousels are very popular in

Question : Slideshows (or carousels) are very popular in websites. They allow web developers to display news or images on the website in limited space. In this code challenge, you are required to complete the JavaScript ...

Assessment socket programmingtaskwrite a java gui program

Assessment: Socket Programming Task Write a JAVA GUI program that would facilitate text chatting/exchanging between two or multiple computers over the network/internet, using the concept of JAVA socket programming. If yo ...

Assessment instructionsin this assessment you will complete

Assessment Instructions In this assessment, you will complete the programming of two Java class methods in a console application that registers students for courses in a term of study. The application is written using th ...

In ruby the hash class inherits from enumerable suggesting

In Ruby, the Hash class inherits from Enumerable, suggesting to a programmer that Hashes are collections. In Java, however, the Map classes are not part of the JCF (Java Collections Framework). For each language, provide ...

Assignment - method in our madnessthe emphasis for this

Assignment - "Method in our Madness" The emphasis for this assignment is methods with parameters. In preparation for this assignment, create a folder called Assign_3 for the DrJava projects for the assignment. A Cityscap ...

Solving 2nd degree equationsbull write the following java

Solving 2nd degree equations • Write the following Java methods • boolean real-sols(double a, double b, double c): it returns true if the 2nd degree equation ax2 + bx + c has real solutions • double solution1(double a, d ...

Assignment game prototypeoverviewfor this assessment task

Assignment: Game Prototype Overview For this assessment task you are expected to construct a prototype level/area as a "proof of concept" for the game that you have designed in Assignment 1. The prototype should function ...

Can someone kindly help me to consider whether java

Can someone kindly help me to consider whether Java provides the facility of operator overloading? If it does, may you kindly describe how overloading operators can be accomplished? If not, may you kindly describe why yo ...

Assignment taskwrite a java console application that allows

Assignment task Write a java console application that allows the user to read, validate, store, display, sort and search data such as flight departure city (String), flight number (integer), flight distance (integer), fl ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As