Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ONLY SOLVE TASK 2 PE1.java contains the following code: package ProgrammingExam1; import java.awt.Color; public class PE1 { public static void main(String[] args) { Draw blankCanvas

ONLY SOLVE TASK 2

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedPE1.java contains the following code:

package ProgrammingExam1;

import java.awt.Color;

public class PE1 {

public static void main(String[] args) {

Draw blankCanvas = new Draw("Programmign Exam 1");

blankCanvas.point(0.7, 0.7);

blankCanvas.circle(0.5, 0.5, 0.5);

blankCanvas.square(0.5, 0.5, 0.4);

blankCanvas.setPenColor(new Color(150, 150, 150));

blankCanvas.line(0.0, 0.5, 1, 0.5);

}

public static String nestedCircle (double x, double y, double radius, double diff, Draw page, String radiusList) {

// your code goes here. Task 1

return "";

}

public static String squares (double x, double y, double halfLength, int order, Draw page) {

// your code goes here. Task 2

return "";

}

public static ArrayList drillPoints(Point p1, Point p2, Point p3, int order, Draw page, ArrayList array) {

// your code goes here. Task 3

return new ArrayList();

}

}

class Point {

double x;

double y;

public Point(double x, double y) {

// your code goes here. Task 0

}

public static Point midpoint(Point p1, Point p2) {

// your code goes here. Task 0

return new Point(0, 0);

}

public String toString() {

return "["+this.x + ", "+ this.y +"]";

}

}

Problem Description: There is a robot on an assembly line whose job is to take a plate of different materials (i.e. metal, plastic, wood, etc.) and drill a number of holes in it at specific (x, y) coordinates, or draw a geometric shapes on the plate. These plates are later used for a variety of applications. As a very simple example, to make a mold for making chocolate boxes, the robot has drawn the following shapes, where the brown, red and cream color shapes are used to place dark, strawberry and chocolate respectively. As a more complex example, the robot is commanded to draw and drill an electronic circuit board to show where resistors, capacitors etc. should be soldered. See the image below that was taken from Wikimedia as an example. In this assignment, you are going to write recursive functions that command this robot to draw different shapes or drill at different coordinates in a plate. How to Draw? First, let's see a couple of examples of how you can draw different shapes. In the starter code, we have provided a complete documentation of how you can draw a point, line, square and circle. Play with these methods by changing their input parameters and see how they work. You can also change the pen color in case it helps you in debugging the code. Please note that we do not execute your main() method to check for the correctness of your code. Instead, we run Junit tests that call your method and check the output. This means you must stick to the format that is provided for you. (i.e. you do not change the input parameters of the method or methods' name etc.) Task 0: This task has no marks but without it, the rest of your code would not work. You should complete class Point, by implementing a constructor that initializes the x and y coordinate of a point. Then you should implement the midpoint () method that returns a Point, which is in the middle of two given points. The coordinates of the middle point should be cut to two decimal points. e.g. 0.38764 should be converted to 0.38. Task 2: For this task, you are required to implement a recursive method that draws a set of squares where the center of one square falls on one corner of another square. The number of squares that should be drawn is given as an input parameter called order. If the order is one, then only one square is drawn. If the order is two, then 5 squares will be drawn when on each corner of the central square another square is drawn, whose side length is half the central square's side length. Please see the picture below that shows the drawing for order = 1 to 4. The output of this method is a list of the coordinates of the smallest squares that are drawn. More information on this method can be found in the javaDoc. order = 1 order = 2 order = 3 order = 4 Sue placa co hoo. Plaa Sample Call: PE1.squares (0.5, 0.5, 0.2, 2, blankCanvas); Corresponding Output: [0.7, 0.7] [0.7, 0.3] [0.3, 0.7] [0.3, 0.3] Marking Scheme: [20 points]: For the correctness of the method. Please note that you will not receive any points if your function is not recursive. Also, make sure that you test your code thoroughly, as we have only provided a subset of the test cases by which Problem Description: There is a robot on an assembly line whose job is to take a plate of different materials (i.e. metal, plastic, wood, etc.) and drill a number of holes in it at specific (x, y) coordinates, or draw a geometric shapes on the plate. These plates are later used for a variety of applications. As a very simple example, to make a mold for making chocolate boxes, the robot has drawn the following shapes, where the brown, red and cream color shapes are used to place dark, strawberry and chocolate respectively. As a more complex example, the robot is commanded to draw and drill an electronic circuit board to show where resistors, capacitors etc. should be soldered. See the image below that was taken from Wikimedia as an example. In this assignment, you are going to write recursive functions that command this robot to draw different shapes or drill at different coordinates in a plate. How to Draw? First, let's see a couple of examples of how you can draw different shapes. In the starter code, we have provided a complete documentation of how you can draw a point, line, square and circle. Play with these methods by changing their input parameters and see how they work. You can also change the pen color in case it helps you in debugging the code. Please note that we do not execute your main() method to check for the correctness of your code. Instead, we run Junit tests that call your method and check the output. This means you must stick to the format that is provided for you. (i.e. you do not change the input parameters of the method or methods' name etc.) Task 0: This task has no marks but without it, the rest of your code would not work. You should complete class Point, by implementing a constructor that initializes the x and y coordinate of a point. Then you should implement the midpoint () method that returns a Point, which is in the middle of two given points. The coordinates of the middle point should be cut to two decimal points. e.g. 0.38764 should be converted to 0.38. Task 2: For this task, you are required to implement a recursive method that draws a set of squares where the center of one square falls on one corner of another square. The number of squares that should be drawn is given as an input parameter called order. If the order is one, then only one square is drawn. If the order is two, then 5 squares will be drawn when on each corner of the central square another square is drawn, whose side length is half the central square's side length. Please see the picture below that shows the drawing for order = 1 to 4. The output of this method is a list of the coordinates of the smallest squares that are drawn. More information on this method can be found in the javaDoc. order = 1 order = 2 order = 3 order = 4 Sue placa co hoo. Plaa Sample Call: PE1.squares (0.5, 0.5, 0.2, 2, blankCanvas); Corresponding Output: [0.7, 0.7] [0.7, 0.3] [0.3, 0.7] [0.3, 0.3] Marking Scheme: [20 points]: For the correctness of the method. Please note that you will not receive any points if your function is not recursive. Also, make sure that you test your code thoroughly, as we have only provided a subset of the test cases by which

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2015 Porto Portugal September 7 11 2015 Proceedings Part 3 Lnai 9286

Authors: Albert Bifet ,Michael May ,Bianca Zadrozny ,Ricard Gavalda ,Dino Pedreschi ,Francesco Bonchi ,Jaime Cardoso ,Myra Spiliopoulou

1st Edition

3319234609, 978-3319234601

More Books

Students also viewed these Databases questions