import java.awt.Graphics; import java.awt.Color; public class MethodHeaderExample { /** Given method parameter of type Circle named circ Send the message "getBoundary" to "circ" Assign the return value to a var named "boundary" Get the top of the boundary and assign the value to a var named result of type int Return result */ public int problem1(Circle circ) { //Declare local var boundary Frame boundary; //Get the boundary of the Circle and assign to var boundary //We reference the "Method Headers" for Circle and see this method header: // public Frame getBoundary() //We know from the "Big Three" (See chapter section "Definition") that //the method boundary returns a data type "Frame" //This data type (Frame) matches up to the data type of our variable "boundary" //Thus we can do the following line boundary = circ.getBoundary(); //Get the top of the boundary int result = boundary.getTop(); //Return result //Note that method header return type must be type "int" because result is an int return result; } /** Given method parameter named ellipse of type Ellipse Given additional method parameter named rec of type Rectangle Send the message getLongDimension to the var ellipse. Assign the return value to a var named dim Send the message setLongDimension to the Rectangle object using a var that you have available Return the Rectangle variable */ public Rectangle problem2(Ellipse ellipse, Rectangle rec) { int dim; //Send message to ellipse and assign the returned value to var dim dim = ellipse.getLongDimension(); //Set long dimension of rec using var dim rec.setLongDimension(dim); //Return rec return rec; } /** Given two method parameters both of type Point: p1 and p2 Send the message plus to the first point with the other point as a method parameter, and assign the result to a var named p3 Return p3 */ public Point problem3(Point p1, Point p2) { //Declare new point p3 Point p3; //Add p1 + p2 and assign result to p3 p3 = p1.plus(p2); //Return p3 return p3; } public OuterSpace problem4(OuterSpace space, Graphics g) { //Send message drawOn to space passing var g space.drawOn(g); return space; } /** Given two method parameters: a Point named p, and a Frame named frame Send a message to determine if frame contains p Assign the result to a var named result Return result */ public boolean problem5(Point p, Frame frame) { //Declare variable boolean result; //Ask frame if it contains p result = frame.contains(p); //Return result return result; } /** Given two method parameters: an Ellipse named ellipse, and a Circle named circ Send the message getAnchor to ellipse and assign the result to a var p1 Send the message getAnchor to circ and assign the result to a var p2 Sum p1 and p2 using the message plus and assign the result to a var sum Return sum */ public Point problem6(Ellipse ellipse, Circle circ) { //Declare vars Point p1, p2; //Assign ellipse's anchor to p1 p1 = ellipse.getAnchor(); //Assign circle's anchor to p2 p2 = circ.getAnchor(); Point sum; //Sum p1 and p2 sum = p1.plus(p2); //Return sum return sum; } public Point problem7(ForwardIndicator fw, int x, int y) { int x2, y2; x2 = fw.conformX(x); y2 = fw.conformY(y); Point p; p = new Point(); p.setX(x2); p.setY(y2); return p; } public Point problem8() { Point p; p = new Point(); p.setX(808); p.setY(707); return p; } public Point problem9(Point a, Point b, int k) { Point product; product = a.multiply(b); product = product.multiply(k); return product; } public Circle problem10(Circle circ, Graphics g, Color color) { circ.drawOn(g, color); return circ; } public int problem11(Ellipse ellipse) { Frame f = ellipse.getBoundary(); int area = f.getWidth() * f.getHeight(); return area; } public Circle problem12(Ellipse ellipse) { Circle circ; circ = new Circle(); circ.setAnchor(ellipse.getAnchor()); circ.setLongDimension(1093); return circ; } public String problem13(Circle circ, Ellipse elli) { return "No Solution"; } public String problem14(Frame frame, String lastName) { return "No Solution"; } public String problem15(Circle circ, Color favColor) { return "No Solution"; } }