Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This program consists of three Java files: Apple, Worm, and Tester. Create a documentation comment in the Tester class describing the overall program. The Worm

This program consists of three Java files: Apple, Worm, and Tester. Create a documentation comment in the Tester class describing the overall program.

The Worm class has a double field for the length of the Worm. This class will have five methods: a parameterized constructor that takes a length to be set as the length of the object, a copy constructor to set the length field as the length of the passed in Worm object, a setter and getter for the length field, and a toString method. The toString method returns the following String, assuming a length of 1.0:

The worm has a length of 1.0 in.

The Apple class has a field for a Worm object. This class will have three methods: a parameterized constructor that takes a Worm to be set as the Worm of that Apple object (remember to set the Worm field securely), a getWorm method that securely returns the reference to the Worm object, and a toString method. The toString method should use the Worm field to return the following String, assuming a length of 1.0 for that Worm object:

The apple has a worm inside of it. The worm has a length of 1.0 in.

The Tester class holds the main method to demonstrate proper aggregation. Construct two objects: a Worm with a length of 1.5 and an Apple with that newly constructed Worm object. Next, use the setLength method on the Worm object in the main method and change its length to 3.0. Finally, make two print statements: one to print the Worm object in the main method, which should have a length of 3.0, and one to print the Apple object in the main method, which should have a Worm field with a length of 1.5.

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

Students also viewed these Databases questions