Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a class named Tract that has two fields: one for the tract's length and one for the width. Both are double values. The class

image text in transcribedimage text in transcribed

Write a class named Tract that has two fields: one for the tract's length and one for the width. Both are double values. The class should have two constructors, one regular constructor that takes two arguments - length and width; the other constructor takes a Tract object as the argument. The class should also contain getters, setters, a method that returns the tract's area (area = length * width), and a toString method to return a string. Then write a class named LandGrass that has a Tract object as a field. It should also have a field for the price per pallet of grass (double). The class should have a constructor and the following methods: The getNumPallets method that returns the number of pallets needed to cover the tract. Each pallet of grass covers 500 sq. ft. (num Pallets = tractArea / 500). This method must get the area from the Tract object and returns number of pallets as an integer, you need to use Math.ceil(number) to round up. The getCost method should return the total cost of the grass (cost = price * num Pallets). The toString method to return a string. Demonstrate the classes in a program (LandGrassDemo), in the main method, ask the user for the length and width of the land, create a Tract object, then ask the user for the price per pallet of grass, create a LandGrass object, and then display the dimensions of the tract, number of pallets needed, and total cost. Sample Output Enter length of your tract in footage: 45.6 Enter width of your tract in footage: 67.8 Enter price per pallet: 159.5 Land dimensions: 45.6 feet by 67.8 feet Number of pallets needed: 7 Total cost: $1116.50

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

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions