import tester.*; /** * HtDC Labs * Lab 1: Data definitions for simple classes and classes with containment * * Copyright 2013 Viera K. Proulx * This program is distributed under the terms of the * GNU Lesser General Public License (LGPL) * * @since 29 August 2013 */ /* +--------------+ | Circle | +--------------+ | CartPt loc |--+ | int rad | | | String color | | +--------------+ | v +--------+ | CartPt | +--------+ | int x | | int y | +--------+ */ // to represent a circle class Circle { CartPt loc; int rad; String color; Circle(CartPt loc, int rad, String color) { this.loc = loc; this.rad = rad; this.color = color; } } // to represent a Cartesian point in a plane class CartPt { int x; int y; CartPt(int x, int y) { this.x = x; this.y = y; } } // examples for the classes CartPt and Circle class ExamplesShapes { // make examples of CartPt-s CartPt p50x50y = new CartPt(50, 50); CartPt p20x40y = new CartPt(20, 40); CartPt p30x40y = new CartPt(30, 40); // make examples of Circle-s Circle circle1 = new Circle(new CartPt(50, 50), 50, "red"); Circle circle2 = new Circle(new CartPt(20, 40), 10, "green"); Circle circle3 = new Circle(new CartPt(30, 40), 20, "blue"); // test the data for the class Circle boolean testCircles(Tester t) { return t.checkExpect(this.circle1, new Circle(this.p50x50y, 50, "red")) && t.checkExpect(this.circle2, new Circle(this.p20x40y, 10, "green")) && t.checkExpect(this.circle3, new Circle(this.p30x40y, 20, "blue")); } }