Assignment - Our Rectangle Class Suppose that rectangles in a Cartesian plane are represented by a...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Assignment - Our Rectangle Class Suppose that rectangles in a Cartesian plane are represented by a class Our Rectangle that has four private fields: integer x- the x-coordinate of the left edge integer y-the y-coordinate of the bottom edge integer width-the width of the rectangle integer height - the height of the rectangle 1. Define the class. (2 Marks) 2. Write a constructor method that has four parameters representing the four fields of the class (in the order they are listed above). The constructor should replace any negative length parameters with zero. (2 marks) 3. Write a toString method. For the rectangle with a lower left corner located at (3, 2) and having a width of 4 and a height of 5, the method should return "base: (3,2) w: 4 h:5". (1 Mark) 4. Write an instance method, area, that returns the area of a rectangle. (2 Marks) 5. Write an instance method, perimeter, that returns the perimeter of a rectangle. (2 Marks) 6. Write a class method, intersection, that has two Rectangle parameters. The method should return the rectangle formed by the area common to the two rectangles (ie., the rectangle formed where they overlap with each other). If they do not intersect, the method should return a rectangle where all fields are zero. If the rectangles only touch, but do not overlap, then the width or height should be zero, but all other parameters should be properly calculated and stored. (6 Marks) 7. Write a class method, totalPerimeter, that has two Rectangle parameters. The method should return the total perimeter of the figure formed by the two rectangles. It should only count those portions that are on the edges of the exterior of the resulting figure. If one rectangle is completely contained by the other, then return the perimeter of the outer rectangle. If the rectangles do not intersect, the method should return the sum of the individual perimeters. (3 Marks) 8. Write an instance method, contains, that has one parameter of type Rectangle. The method should return true if every point of the specified rectangle (i.e., passed by the explicit parameter) is on or within the implicit parameter (i.e., the object invoking the instance method). It should return false otherwise. (2 Marks) For example, a.contains (b); would return true if the rectangle b is entirely within a. You are welcome to design and write additional code to help you accomplish this task, but you must hide them using encapsulation. Assignment - Our Rectangle Class Suppose that rectangles in a Cartesian plane are represented by a class Our Rectangle that has four private fields: integer x- the x-coordinate of the left edge integer y-the y-coordinate of the bottom edge integer width-the width of the rectangle integer height - the height of the rectangle 1. Define the class. (2 Marks) 2. Write a constructor method that has four parameters representing the four fields of the class (in the order they are listed above). The constructor should replace any negative length parameters with zero. (2 marks) 3. Write a toString method. For the rectangle with a lower left corner located at (3, 2) and having a width of 4 and a height of 5, the method should return "base: (3,2) w: 4 h:5". (1 Mark) 4. Write an instance method, area, that returns the area of a rectangle. (2 Marks) 5. Write an instance method, perimeter, that returns the perimeter of a rectangle. (2 Marks) 6. Write a class method, intersection, that has two Rectangle parameters. The method should return the rectangle formed by the area common to the two rectangles (ie., the rectangle formed where they overlap with each other). If they do not intersect, the method should return a rectangle where all fields are zero. If the rectangles only touch, but do not overlap, then the width or height should be zero, but all other parameters should be properly calculated and stored. (6 Marks) 7. Write a class method, totalPerimeter, that has two Rectangle parameters. The method should return the total perimeter of the figure formed by the two rectangles. It should only count those portions that are on the edges of the exterior of the resulting figure. If one rectangle is completely contained by the other, then return the perimeter of the outer rectangle. If the rectangles do not intersect, the method should return the sum of the individual perimeters. (3 Marks) 8. Write an instance method, contains, that has one parameter of type Rectangle. The method should return true if every point of the specified rectangle (i.e., passed by the explicit parameter) is on or within the implicit parameter (i.e., the object invoking the instance method). It should return false otherwise. (2 Marks) For example, a.contains (b); would return true if the rectangle b is entirely within a. You are welcome to design and write additional code to help you accomplish this task, but you must hide them using encapsulation.
Expert Answer:
Related Book For
Posted Date:
Students also viewed these programming questions
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
Predictive text entry systems are familiar on touch screens and mobile phones. This question asks you to consider how the same principles might be used in a programming editor for creating Java code....
-
Which of the following industries would most likely have the highest ratio of sales revenue to property, plant and equipment? Question 9 options: 1) Airline 2) Consumer product manufacturing company...
-
How do frequency and period relate to each other?
-
Find the perimeter of each triangle. Isosceles triangle, equal sides of 2.45 in., third side of 3.22 in.
-
What are some indicators that a digital device has been infected?
-
Denzel Brooks opens a Web consulting business called Venture Consultants and completes the following transactions in March. March 1 Brooks invested $150,000 cash along with $22,000 in office...
-
1. You invest $2000 in an account that pays simple interest of 7% for 10 years. The amount of money you'll have at the end of 10 years is: 2. Use the compound interest formula to determine the...
-
Flowmaster Forge Inc. is a designer and manufacturer of industrial air-handling equipment that is a wholly owned subsidiary of Howden Industrial Inc. Howden is interested in selling Flowmaster to an...
-
Calculate the monthly payments for 2 of these options given that interest is compounded monthly.
-
Why are my provisional tax payments for next year higher than those for this year?
-
Spare Parts, Inc. has purchased 2.479.000 from its supplier. The supplier will be willing to grant a 1,20% discount provided Spare Parts, Inc. pays the full invoice within 10 days. The invoice will...
-
"Double taxation agreements eliminate economic double taxation." Explain whether or not you agree with this statement.
-
Energas plc is a shipping company, which specialises in transportation of crude oil using tankers. The company is constantly exanding and it currently considers to buy one additional second-hand...
-
Several companies, including Barnyard and Energy Solutions Corporation, are considering project A, which is believed by all to have a level of risk that is equal to that of the average-risk project...
-
About two decades ago, estimates of the prevalence of Alzheimer's disease have been provided by Preffer et al. (1987). Complete the table with scrambled data as given below: Age group 65-69 70-74...
-
Funds are separate fiscal and accounting entities, each with its own self-balancing set of accounts. The newly established Society for Ethical Teachings maintains two funds-a general fund for...
-
Prove that is continuous on R2. f(x, y) = 0
-
Prove each of the following statements. a) 2n + 1 < 2n for n = 3, 4,.... b) n < 2n for n = 1, 2,.... c) n2 < 2n + 1 for n = 1, 2,.... d) n3 < 3n for n = 1, 2,....
-
Let a > 0 and recall that (x) = ax-1 and (log x)' = 1/x for all x > 0. a) Prove that log x < xa for x large. Prove that there exists a constant Ca such that log x < Caxa for all x [1, ), Ca as ...
-
Lewis Edwards decides to branch out on his own and set up his own private practice as an accountant. Events occurring in March 2019 are as follows. Ignore GST. Required (a) After analyzing the events...
-
On 1 March 2017, James Taylor decided to open Taylors Tailormade that makes suits, trousers and jackets, and repairs and alters clothes. He contributed for this purpose sewing equipment $46 000 and a...
-
In December 2019, Mike Mills opened a miniature golf course to cater for the summer holiday tourists and completed the transactions below during its first month of operations. For the sake of...
Study smarter with the SolutionInn App