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
-
Notson, Inc. produces several models of clocks. An outside supplier has offered to produce the commercial clocks for Notson for $420 each. Notson needs 1,200 clocks annually. Notson has provided the...
-
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
-
Refer to Exercise 2.65. Construct a box plot for the data. Are there any outliers? Does this conclusion agree with your results in Exercise 2.65? Exercise 2.65 The miles per gallon (mpg) for each of...
-
The Centers for Disease Control and Prevention (CDC) is tracking the spread of a virus. The CDC is attempting to determine where the virus began by identifying where each known carrier contracted the...
-
Jerry Hasbrow, a sales representative for Penn Office Supplies Corporation, is compensated on a commission basis and received a substantial bonus for meeting his annual sales goal. The companys...
-
As more and more components are placed on a single integrated circuit (chip), the amount of heat that is dissipated continues to increase. However, this increase is limited by the maximum allowable...
-
I can not get the correct percentage to calculate for this problem. Can someone help and advise how they get the answer? If a project costs $72,000 and returns $18,500 per year for 5 years, what is...
-
Google Stock Value on 12/11/09 $590.51 Stock Value on 1/11/10 $601.11 Stock Value on 2/11/10 $536.40 A. Suppose that it is the end of the day on December 11, 2009. The current stock price of Google...
-
In what ways do culturally embedded leadership styles influence cross-cultural collaboration, communication, and conflict resolution within multinational corporations and globalized markets ?
-
1.) Draw the DETAILED and COMPLETE MECHANISM of the following. Show also the other products of the reaction and its mechanism. (INTRAMOLECULAR ALDOL REACTIONS) NaoEt ----> re-draw CH3 EtOH CH2 CH2...
-
Cast Iron Fabrication allocates manufacturing overhead to each job using departmental overhead rates. The company's operations are divided into a casting department and a finishing department. The...
-
Name: Marks Sections Journal Type # of Questions 57 G/L Accounts 68 Trial Balance Income Statement Statement of Owners Equity 20 13 6 Balance Sheet 12 TOTAL 176 Once complete, submit as instructed....
-
Write a C++ program to show a randomized 30 results with the following characteristics: 25% show "Heads" 65% Show "Tails" 10% Show "No clear results" Attach your output. //Ex2 solution #include using...
-
At the beginning of the year, Southern Valley Health Services, a health and welfare notfor-profit entity, had the following Net Assets balances: Net Assets: Without donor restriction $2,090,000 With...
-
According to a recent survey, 40% of millennials (those born in the 1980s or 1990s) view themselves more as spenders than savers. The survey also reveals that 75% of millennials view social...
-
A 40 in plasma television uses about \(175 \mathrm{~W}\). How many kilowatt-hours are needed to run the television in a month if the television is on for an average of 3 hours a day?
-
Which of the following is true regarding the accounting cycle? a. The accounts are adjusted after preparing the financial statements. b. Journal entries are made prior to the transaction being...
-
How many pills would be needed for a patient who has been prescribed \(25.5 \mathrm{mg}\) of a drug if each pill contains \(4.25 \mathrm{mg}\).
Study smarter with the SolutionInn App