NOTE : Make sure to answer each exercise independent to the others. If a problem asks
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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. 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.
Expert Answer:
Related Book For
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
CANMNMM January of this year. (a) Each item will be held in a record. Describe all the data structures that must refer to these records to implement the required functionality. Describe all the...
-
In Exercises, use the alternative form of the derivative to find the derivative at x = c (if it exists). f(x) = 1 x + 4' c = 3
-
The miles per gallon (mpg) for each of 20 medium-sized cars selected from a production line during the month of March follow. a. What are the maximum and minimum miles per gallon? What is the range?...
-
In each of the following cares, find the least square approximation of degrees 0,1 and 2 for the function f(x)=sin(x) on the interval (a, b) with respect to the weight function w(x) = 1. (a)...
-
This is actually a paired data situation (since each person was measured before and after eating organic), so we create a new variable, the differences in pesticide concentration, by taking pesticide...
-
At December 31, 2012, the trading securities for Lynette, Inc., are as follows. Instructions(a) Prepare the adjusting entry at December 31, 2012, to report the securities at fair value.(b) Show the...
-
Spring Appliances received an invoice dated August 1 5 with terms 4 / 1 0 E . O . M . for the items listed below. 6 refrigerators at $ 9 2 0 each less 3 0 % and 6 % 5 dishwashers at $ 7 2 3 each less...
-
I am looking for the Restaurant Genreral Manger postion. Can you provide me a research of salaries for this position (or similar positions). Include an original graph (that you make in excel) that...
-
How can teams focus first and foremost on performance? What are the obstacles to focusing on team performance?
-
What is social chat, and why is it advantageous in an online meeting?
-
Why is it useful to find common ground with others? How do we validate the views and feelings of others?
-
What types of noise are necessary to overcome in a difficult conversation?
-
Why is it useful to commit to listening to peoples stories?
-
Write an article about Workplace Safety and Health
-
Accounting policies and practices that are most important to the portrayal of the companys financial condition and results, and require managements most difficult, subjective, or complex judgments...
-
A bank offers customers the option of receiving interest compounded quarterly, semi-annually, or annually. If the rate of interest is the same, which is the best option for the customer?
-
The director of marketing of your organization asks for your advice regarding sponsorship deals she is contemplating. She has to choose from the following: a 15-year sponsorship paying \($100,000\)...
-
An athlete signs a five-year endorsement deal with a prominent sponsor. Under this deal the athlete will receive \($5,000\) each year for the first three years and \($6,500\) each year for the final...
Study smarter with the SolutionInn App