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
-
Use iContract, a Design by Contract library for Python3, and two Python3\'s standard libraries xmlrpc and threading, to implement a client-server banking application. This application has three...
-
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...
-
Find all v R2 such that (a) ||v||1 = ||v|| (b) ||v||1 = ||v|| (c) ||v||2 = ||v|| (d) ||v|| = 1/2 ||v||
-
When returned items and empty boxes move backward in the supply chain, from retail s to distribution centers, the management of this flow of materials is referred to as: Operations Reverse logistics...
-
A distillation column with \(8.01 \mathrm{~m}\) of packing operating at total reflux separates methanol from ethanol at \(101.3 \mathrm{kPa}\). Average relative volatility is 1.69 . Methanol mole...
-
Firm Z, operating in a perfectly competitive market, can sell as much or as little as it wants of a good at a price of $16 per unit. Its cost function is C = 50 + 4Q + 2Q2. The associated marginal...
-
What is the purpose of article Prahalad, C.K., & Hamel, G. " The core competence of the corporation ." Harvard Business Review, May-June 1990
-
Classify each function as a power function, root function, polynomial (state its degree), rational function, algebraic function, trigonometric function, exponential function, or logarithmic function....
-
One-factor ANOVA is used to compare O Multiple proportions O Multiple variances O Multiple means O Multiple standard deviations O All of the above
-
Use the quotient rule to find the derivative of the following. 7x+1 y= 2 x +9 dy dx =
-
What creates change within a culture of integrity that helps the organization thrive over the long haul by promoting openness and honesty, positive relationships, and long-term innovation?
-
As the organization changes, the culture within the organization can also change and be shaped by the current leadership behaviors as this will cascade to the employees' structure, routines, rules,...
-
Why do some organizations have to change the culture and values of the company? Explain.
-
what extent does a culture of open communication and feedback influence job satisfaction, and how can organizations cultivate an environment where employees feel valued and heard ?
-
XKL Co. plans a new project that will generate $135018 of continuous cash flow each year for 9 years and additionally $102141 at the end of the project. If the continuously compounded rate of...
-
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 ...
-
Consider the following accounting principles: 1. Entity principle 2. Revenue recognition principle 3. Matching concept Define these accounting principles. Discuss how these principles relate to one...
-
Key Performance Indicators: The Income Statement. Describe or define the following key performance indicators (KPIs) from the income statement: 1. Operating revenue 2. Gross profit 3. Operating...
-
The return on shareholders equity ratio can be decomposed into three separate financial ratiosthe return on sales, asset turnover, and financial leverage. Define each of the ratios assuming the firm...
Study smarter with the SolutionInn App