Question: create a public class Circle.java with variables radius and color. Write down the default constructor for radius 1.0 and color blue of the circle. Write

create a public class Circle.java with variables radius and color. Write down the default constructor for radius 1.0 and color blue of the circle. Write down the custom constructor that initializes the circle to the given radius and given color. An exception IllegalArgumentException is thrown if the radius is less than 0.0. Consult the test cases provided in Circletest to figure out the correct names of the getter and setter methods.

Circletest:

import static org.junit.Assert.*;

import org.junit.Test;

import java.awt.Color; import java.lang.reflect.Constructor; import java.lang.reflect.Field; import java.lang.reflect.Modifier;

import org.junit.runners.MethodSorters; import org.junit.FixMethodOrder;

@FixMethodOrder(MethodSorters.NAME_ASCENDING) public class Circletest {

@Test public void test00() { Circle c = new Circle(); for (Field f : Circle.class.getDeclaredFields()) { if (f.getName().equals("color")) { this.checkColor(f, c, Color.BLUE); } else if (f.getName().equals("radius")) { this.checkRadius(f, c, 1.0); } } } @Test public void test01() { Circle c = new Circle(1.5, Color.RED); for (Field f : Circle.class.getDeclaredFields()) { if (f.getName().equals("color")) { this.checkColor(f, c, Color.RED); } else if (f.getName().equals("radius")) { this.checkRadius(f, c, 1.5); } } } @Test public void test02() { Circle c = new Circle(0.0, Color.CYAN); for (Field f : Circle.class.getDeclaredFields()) { if (f.getName().equals("color")) { this.checkColor(f, c, Color.CYAN); } else if (f.getName().equals("radius")) { this.checkRadius(f, c, 0.0); } } } @Test(expected = IllegalArgumentException.class) public void test03() { Circle c = new Circle(-0.0001, Color.BLACK); } private void checkColor(Field f, Circle c, Color exp) { f.setAccessible(true); try { Color color = (Color) f.get(c); assertEquals("Circle constructor failed to set the color correctly ", exp, color); } catch (IllegalAccessException x) { fail("cannot access field \"color\""); } } private void checkRadius(Field f, Circle c, double exp) { f.setAccessible(true); try { double radius = f.getDouble(c); assertEquals("Circle constructor failed to set the radius correctly ", exp, radius, 1e-9); } catch (IllegalAccessException x) { fail("cannot access field \"radius\""); } }

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!