Question: My code: import m250.library.OUPolygon; import java.awt.Color; public class DrawingJG { // Fields for the polygons representing the initials private OUPolygon letterJ; private OUPolygon letterG; //
My code:
import m250.library.OUPolygon; import java.awt.Color;
public class DrawingJG { // Fields for the polygons representing the initials private OUPolygon letterJ; private OUPolygon letterG; // A polygon to represent the space inside the G private OUPolygon spaceInG; /** * Constructor for objects of class DrawingJG */ public DrawingJG() { // Initialize the polygon for letter J letterJ = new OUPolygon( "100,50 100,170 125,175 125,125 225,125 250,100 250,50 225,50 225,100 125,100 125,50", Color.RED ); // Initialize the polygon for letter G letterG = new OUPolygon( "100,275 100,400 125,400 125,300 225,300 225,375 200,375 200,350 175,350 175,400 250,400 250,275", Color.RED ); // Initialize the polygon for the space inside G spaceInG = new OUPolygon( "175,350 200,350 200,375 175,375", Color.WHITE // Matches the canvas background ); // Make all polygons visible letterJ.setVisible(true); letterG.setVisible(true); spaceInG.setVisible(true); } /** * Constructor for object DrawiungJG that determains the polygon colour * based on the hashcode of the users first and last name */ public DrawingJG(String firstName, String lastName) { // Set the name fields this.firstName = firstName; this.lastName = lastName;
// Determine colors based on hash codes of the names Color firstNameColor = new Color(Math.abs(firstName.hashCode()) % 256); Color lastNameColor = new Color(Math.abs(lastName.hashCode()) % 256);
// Initialize the polygons for letters J and G letterJ = new OUPolygon( "100,50 100,170 125,175 125,125 225,125 250,100 250,50 225,50 225,100 125,100 125,50", firstNameColor ); letterG = new OUPolygon( "100,275 100,400 125,400 125,300 225,300 225,375 200,375 200,350 175,350 175,400 250,400 250,275", lastNameColor );
// Initialize the polygon for the space inside G spaceInG = new OUPolygon( "175,350 200,350 200,375 175,375", Color.WHITE // Matches the canvas background );
// Make all polygons visible letterJ.setVisible(true); letterG.setVisible(true); spaceInG.setVisible(true); } /** * An example of a method - replace this comment with your own * * @param y a sample parameter for a method * @return the sum of x and y */ public int sampleMethod(int y) { return y * 2; //Example method; customise as needed } }
Questions


Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
