1 /* it contains exactly 9 painted (filled in) circles 2 it contains circles of exactly 4 different sizes 3 it contains circles of exactly 4 different colors 4 none of the circles touch 5 the image is symmetric about the Y-axis 6 not all of the circles touch the Y-axis*/ 7 8 package npw; 9 import java.awt.Color; 10 import javax.swing.SwingUtilities; 11 import painter.SPainter; 12 import shapes.SCircle; 13 14 public class Dots { 15 // THE SOLUTION TO THE DOTS PROBLEM 16 private void paintTheImage() { 17 SPainter klee = new SPainter ("Dots", 600, 600); 18 SCircle dot = new SCircle (10); 19 klee.mrt(200); 20 21 klee.setColor(Color.BLUE); 22 klee.paint(dot); 23 klee.mlt(200); 24 klee.mlt(200); 25 klee.paint(dot); 26 klee.mrt(200); 27 paintRedDots(dot, klee); 28 paintYellowDots(dot, klee); 29 paintGreenDots(dot, klee); 30 paintBlackDot(dot, klee); 31 } 32 33 private void paintBlackDot(SCircle dot, SPainter klee) { 34 klee.setColor(Color.black); 35 dot.x5(); 36 klee.paint(dot); 37 } 38 39 private void paintGreenDots(SCircle dot, SPainter klee) { 40 dot.s5(); // decrease the radius by 7 41 klee.setColor(Color.green); // set the color to green 42 klee.mlt(200); // move to the left by 200 units 43 klee.mbk(100); // move down by 200 units 44 klee.paint(dot); // paint the first dot 45 klee.mrt(400); // mirror effect 46 klee.paint(dot); // paint second dot 47 klee.moveToCenter(); 48 } 49 50 private void paintYellowDots(SCircle dot, SPainter klee) { 51 dot.x3(); // increase the radius by 3 52 klee.setColor(Color.yellow); // set the color to yellow 53 klee.mfd(200); // move up by 200 units 54 klee.mrt(200); // move to the right by 200 units 55 klee.paint(dot); 56 klee.mlt(400); // move all the way to the left (mirror) 57 klee.paint(dot); // paint second dot 58 klee.mbk(200); // move back down 59 klee.mrt(200); // back to starting point 60 } 61 62 private void paintRedDots(SCircle dot, SPainter klee) { 63 64 dot.x2(); // increase the radius by 2 65 66 klee.setColor(Color.red); // set the color to red 67 klee.mfd(100); // move up by 100 units 68 klee.mrt(100); // move to the right by 100 units 69 klee.paint(dot); 70 klee.mlt(200); // move all the way to the left (mirror) 71 klee.paint(dot); // paint second dot 72 klee.mbk(100); // move back down 73 klee.mrt(100); // back to starting point 74 } 75 76 // REQUIRED INFRASTRUCTURE 77 public Dots() { 78 paintTheImage(); 79 } 80 public static void main(String[] args) { 81 SwingUtilities.invokeLater(new Runnable() { 82 public void run() { 83 new Dots (); 84 } 85 }); 86 } 87 88 } 89