Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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_2

Step: 3

blur-text-image_3

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

Database And Expert Systems Applications Dexa 2023 Workshops 34th International Conference Dexa 2023 Penang Malaysia August 28 30 2023 Proceedings

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Atif Mashkoor ,Johannes Sametinger ,Maqbool Khan

1st Edition

303139688X, 978-3031396885

Students also viewed these Databases questions

Question

=+2. What is the reputation of your organization?

Answered: 1 week ago