Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JAVA HELP 4. (2 points) Write the missing constructor for the Polygon class below. Hint, you need to make sure each Polygon has its OWN

JAVA HELPimage text in transcribed

4. (2 points) Write the missing constructor for the Polygon class below. Hint, you need to make sure each Polygon has its OWN array of Point and isnt sharing that array with another Polygon. You also need to make sure the points are not also shared between two arrays. Your code must work for any number of points, not just with 3 as shown in the example.

5. (2 points) Add the missing add() method to Polygon so that new points can be added as shown by the last 2 lines of main(). Your code should allow add() to be called multiple times to add multiple points. Do not use an ArrayList. Hint: you will need to make a new larger array and copy the values from the old array to the new larger array.

image text in transcribedimage text in transcribed

2. (3 points) Complete the figure to the right to show the contents of the memory and enter the output of the program in the large box. The figure has been started reflecting the memory after the completion of the first assignment to p2 (line 2 of main). Use the Point class showing on the screen. class PointTestP2 public static void main (String[] args) pl 9000 p2 9008 1000 1004 Point p1-new Point (22, 33) Point p2 = new Point (45, 67); mystery (pl) System.out.println (p1); p1 - new Point (17, 18) p2 = p1; p1.translate (200, 300) System.out.println (pl) System.out.println (p2) x 22 Y 33 x 45 y 67 9000 9004 9008 9012 9016 9020 9024 9028 static void mystery (Point p) p.translate (10,20) 3. (1 point) Write the missing method needed to proplery compare Point objects as shown in the example below. The missing method would be added to the Point class shown on the board class PointTestP3 public static void main (String[] args) int pl - new Point (5, 6) i Point p2 = new Point (5, 6); System.out.println (pl.equals (p2))/7 prints "true" ArrayList. Hint: you will need to make a new larger array and copy the values from the old array to the nevw larger array class PolygonTest public static void main (String[] args) Point] tri new Point (10,20),new Point (10,40), new Point (40,40)1 Polygon plnew Polygon (tri) Polygon p2-new Polygon (tri) pl.translate (5, 6) System.out.println (pl // prints "(15,26) (15,46) (45, 46)" System.out.printin (p2): 1/ prints "(10,20) (10,40) (40, 40)" p2.add (new Point (40,20)) System.out.printin (p2): 1/ prints "(10,20) (10,40) (40, 40) (40,20)" class Polygon private Point[] thePoints; Polygon (Point somePoints) 77 missing code goes here for problem 4 public String toStringO String result- for (int - 0:

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

Step: 3

blur-text-image

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

Microsoft Outlook 2023

Authors: James Holler

1st Edition

B0BP9P1VWJ, 979-8367217322

More Books

Students also viewed these Databases questions