Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

NOTE : Make sure to answer each exercise independent to the others. If a problem asks to modify the solution of a previous problem

imageimageimage

NOTE :   Make sure to answer each exercise independent to the others. If a problem asks to modify the solution of a previous problem to add a feature, add a new solution with the requested tasks to your package.( so after completing the exercise 1, if anything is to be added in the square class in the next question add that part and modify the code according to the present question. In that way there'll be 8 individual codes and at the end the exercise 8 is combination of all exercises)  

 

-> Do not modify your previous solution/source code 


Exercise 1. (10 pts) Create a Square class, which declares a side instance variable of type int. Then create a public method called perimeter () that returns the perimeter of the square, and a public area () method that returns the area of the square. i Remember that the perimeter is the sum of the sides of the square, while the area is calculated by multiplying the side by itself. Finally, the symbol to perform a multiplication in Java is the asterisk *. Exercise 2. (10 pts) Create a SquareTest class that contains a main () method that instantiates an object of type Square, with side of value 5. Then print the perimeter and the area of the object just created. Exercise 3. (10 pts) After doing the previous exercise, you should have set the variable side with a statement like the following: objectName.side = 5; To avoid to write this statement, create a constructor in the Square class of the Exercise 1, which takes the value of the variable side as input. Once done, compile the Square class. The SquareTest class, on the other hand, will no longer compile due to the instruction specified above and the non-use of the new constructor. Modify the code of the SquareTest class so that it compiles and runs correctly. Exercise 4. (10 pts) In the Square class created in the Exercise 1, replace the value 4 used to calculate the perimeter, with an instance constant named SIDES_NUMBER. This should not affect the SquareTest class. i Note that for the constant, a name consisting of only uppercase letters separated with an underscore symbol was used. This is a convention that is used for all constants.

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_2

Step: 3

blur-text-image_3

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

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions