Question: write java program Exercise: Write a Rectanglesprinter program that constructs a Rectangle object square representing a square where its original location is given in the
Exercise: Write a Rectanglesprinter program that constructs a Rectangle object square representing a square where its original location is given in the table below (see column relating to your section), prints its location by calling System.out.println(square), applies the grow and translate methods, and calls System.out.println(square) again. The calls to grow and translate should modify the square so that If the squares were drawn, they would look like the figure given in the table below (see column relating to your section). Your program should also construct a new Rectangle object r with a top-left corner (0,0), a width between (20,200), and a length double its width. Finally, your program should print the result of the intersection method when the square and r overlap (if they were drawn they will look like the figure at right). Add a comment to your program that explains how you can tell whether the resulting rectangle is empty or not. Note: Your program will not produce a drawing. It will simply print informative texts and the locations of rectangles before and after calling the methods by calling System.out.print ln(box), where box is the rectangle object name. Hint: - Look up the description of the grow, translate, and intersection methods in the API documentation. Besides, look for a method that checks whether a rectangle is empty. - To come up with suitable values, draw the squares on graph paper. \begin{tabular}{|c|c|c|c|} \hline \multicolumn{1}{|c|}{ Sec 10 } & \multicolumn{1}{c|}{ Sec 21 } & \multicolumn{1}{c|}{ Sec 22 } & \multicolumn{1}{c|}{ Sec 30 } \\ \hline Originalsquarelocation:Top-leftcorner(10,10)andsidelength200 & Originalsquarelocation:Top-leftcorner(50,50)andsidelength200 & Originalsquarelocation:center(100,100)andsidelength200 & Originalsquarelocation:bottom-leftcorner(100,80)andsidelength200 \\ \hline & & & \\ \hline Themodifiedsquare(inred)hashalfthewidthandisonthetopleftoftheoriginalsquare & Themodifiedsquare(inred)hashalfthewidthandisonthetoprightoftheoriginalsquare & Themodifiedsquare(inred)hashalfthewidthandisonthenextrightoftheoriginalsquare & Themodifiedsquare(inred)hashalfthewidthandisonthenextleftoftheoriginalsquare \\ \hline \end{tabular}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
