The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 1 Day Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
Square:
a) Write a class to represent a Square. This should include the following:
i). A single attribute named length
ii). A default constructor which should set the length attribute to a default value of 1.
iii). A second constructor which should set the length attribute to a value which is passed to the constructor.
iv). Getter and setter methods for the length attribute.
v). A method, called getArea(), to calculate and return the area of the Square.
vi). A method called toString() that returns the value of the attribute length (see sample output below for format)Â
Â
b) Write a main method in a new class called TestSquare and in this method:
i). Create an array containing 4 square objects.
ii). Use a ‘for’ loop to set each object to default values when created.
iii). Use the setter method on the 1st and 3rd objects in the array of Square objects to set the length to 10.
iv). Print out the length of each of Square object in the array.
v). Print out the area of the 1st and 2nd objects in the array.
vi). Call the toString() method on the 3rd Square object in the array.Â
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly