Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Exercise 1: answer the questions a, b, c and d in the code below. import uwcse.graphics.*; import java.awt.Color; public class Graphics { // instance fields

Exercise 1: answer the questions a, b, c and d in the code below.

import uwcse.graphics.*; import java.awt.Color; public class Graphics { // instance fields private GWindow window; /** * method makeGreenBorderedDot */ private void makeGreenBorderedDot(int x, int y, GWindow w) { Oval dot, border; dot = new Oval(x, y, 100, 100, Color.green, true); border = new Oval(x, y, 100, 100, Color.black, false); w.add(dot); w.add(border); } /** * Question a: * window is an instance field of type GWindow (see above) * What is wrong with the last three the statements listed in this method? */ public void question_a() { this.window = new GWindow(); this.makeGreenBorderedDot(); this.makeGreenBorderedDot(20, 20); this.makeGreenBorderedDot(20, this.window, 20); } /** * Question b: * What does the following method generate? */ public void question_b() { this.window = new GWindow("Question b", 300, 300); this.makeGreenBorderedDot(20, 20, this.window); this.makeGreenBorderedDot(150, 0, this.window); this.makeGreenBorderedDot(80, 80, this.window); this.window.doRepaint(); } /** * Question c: * Explain the run time error from executing the following code * Assume that only this method is called, i.e. question_a or * question_b haven't been called before question_c */ public void question_c() { this.makeGreenBorderedDot(20, 20, this.window); } /** * Question d (not the same as in the text) * Is this possible to complete the following method (and only this method) * to change the color of the dot to red? * If yes, write the code. If no, explain why. */ public void question_d() { this.window = new GWindow("Question d", 400, 400); this.makeGreenBorderedDot(100, 100, this.window); // Can we change the color of the dot to red? } } 

Exercise 2:

For each of the following methods, write a precondition (= what must be true for the method to execute correctly) and a postcondition (= what the method guarantees to be true once it has been executed) in plain English:

  1. public double mysteryMethod1(double a, double b, double c) { return Math.sqrt(b*b - 4*a*c); } 
  2. public void mysteryMethod2(Oval o1, Oval o2) { Color c1 = o1.getColor(); Color c2 = o2.getColor(); o1.setColor(c2); o2.setColor(c1); }
  3. public String mysteryMethod3(String s) { return s + "s"; }
 
 

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

Flash XML Applications Use AS2 And AS3 To Create Photo Galleries Menus And Databases

Authors: Joachim Schnier

1st Edition

0240809173, 978-0240809175

Students also viewed these Databases questions