organize imports; format code

This commit is contained in:
Z Toups committed 2020-07-15 15:51:56 -06:00
1 parent bf3f5aa10c
commit 64d610bbd4
6 files changed
+174 -180

No files matched your search

+58 -50
View File
@@ -1,61 +1,69 @@
package edu.nmsu.cs.circles;
/**
* Implements a base abstract class for a circle. Everything except
* a intersects() method is implemented here. Subclass must implement
* the intersects() method.
**/
* Implements a base abstract class for a circle. Everything except a intersects() method is
* implemented here. Subclass must implement the intersects() method.
**/
public abstract class Circle
{
protected Point center;
protected double radius;
protected Point center;
/**
* Create new circle
* @param x is the x coordinate of the center
* @param y is the y coordinate of the center
* @param radius is the radius
**/
public Circle(double x, double y, double radius)
{
center = new Point();
center.x = x;
center.y = y;
this.radius = radius;
}
protected double radius;
/**
* Change size of circle
* @param factor is the scaling factor (0.8
* make it 80% as big, 2.0 doubles its size)
* @return the new radius
**/
public double scale(double factor)
{
radius = radius + factor;
return radius;
}
/**
* Create new circle
*
* @param x
* is the x coordinate of the center
* @param y
* is the y coordinate of the center
* @param radius
* is the radius
**/
public Circle(double x, double y, double radius)
{
center = new Point();
center.x = x;
center.y = y;
this.radius = radius;
}
/**
* Change position of circle relative to current position
* @param xOffset is amount to change x coordinate
* @param yOffset is amount to change y coordinate
* @return the new center coordinate
**/
public Point moveBy(double xOffset, double yOffset)
{
center.x = center.x + xOffset;
center.y = center.y + xOffset;
return center;
}
/**
* Change size of circle
*
* @param factor
* is the scaling factor (0.8 make it 80% as big, 2.0 doubles its size)
* @return the new radius
**/
public double scale(double factor)
{
radius = radius + factor;
return radius;
}
/**
* Test if this circle intersects another circle.
* @param other is the other circle
* @return True if the circles' outer edges intersect
* at all, False otherwise
**/
public abstract boolean intersects(Circle other);
/**
* Change position of circle relative to current position
*
* @param xOffset
* is amount to change x coordinate
* @param yOffset
* is amount to change y coordinate
* @return the new center coordinate
**/
public Point moveBy(double xOffset, double yOffset)
{
center.x = center.x + xOffset;
center.y = center.y + xOffset;
return center;
}
/**
* Test if this circle intersects another circle.
*
* @param other
* is the other circle
* @return True if the circles' outer edges intersect at all, False otherwise
**/
public abstract boolean intersects(Circle other);
}
+11 -13
View File
@@ -1,21 +1,19 @@
package edu.nmsu.cs.circles;
public class Circle1 extends Circle
{
public Circle1(double x, double y, double radius)
{
super(x,y,radius);
}
public Circle1(double x, double y, double radius)
{
super(x, y, radius);
}
public boolean intersects(Circle other)
{
if (Math.abs(center.x - other.center.x) < radius &&
Math.abs(center.y - other.center.y) < radius)
return true;
return false;
}
public boolean intersects(Circle other)
{
if (Math.abs(center.x - other.center.x) < radius &&
Math.abs(center.y - other.center.y) < radius)
return true;
return false;
}
}
@@ -1,79 +1,68 @@
package edu.nmsu.cs.circles;
/***
* Example JUnit testing class for Circle1 (and Circle)
*
* - must have your classpath set to include the JUnit jarfiles
* - to run the test do:
* java org.junit.runner.JUnitCore Circle1Test
* - note that the commented out main is another way to run tests
* - note that normally you would not have print statements in
* a JUnit testing class; they are here just so you see what is
* happening. You should not have them in your test cases.
***/
* Example JUnit testing class for Circle1 (and Circle)
*
* - must have your classpath set to include the JUnit jarfiles - to run the test do: java
* org.junit.runner.JUnitCore Circle1Test - note that the commented out main is another way to run
* tests - note that normally you would not have print statements in a JUnit testing class; they are
* here just so you see what is happening. You should not have them in your test cases.
***/
import org.junit.*;
public class Circle1Test
{
// Data you need for each test case
private Circle1 circle1;
// Data you need for each test case
private Circle1 circle1;
//
// Stuff you want to do before each test case
//
@Before
public void setup()
{
System.out.println("\nTest starting...");
circle1 = new Circle1(1,2,3);
}
//
// Stuff you want to do before each test case
//
@Before
public void setup()
{
System.out.println("\nTest starting...");
circle1 = new Circle1(1, 2, 3);
}
//
// Stuff you want to do after each test case
//
@After
public void teardown()
{
System.out.println("\nTest finished.");
}
//
// Stuff you want to do after each test case
//
@After
public void teardown()
{
System.out.println("\nTest finished.");
}
//
// Test a simple positive move
//
@Test
public void simpleMove()
{
Point p;
System.out.println("Running test simpleMove.");
p = circle1.moveBy(1,1);
Assert.assertTrue(p.x == 2 && p.y == 3);
}
//
// Test a simple positive move
//
@Test
public void simpleMove()
{
Point p;
System.out.println("Running test simpleMove.");
p = circle1.moveBy(1, 1);
Assert.assertTrue(p.x == 2 && p.y == 3);
}
//
// Test a simple negative move
//
@Test
public void simpleMoveNeg()
{
Point p;
System.out.println("Running test simpleMoveNeg.");
p = circle1.moveBy(-1,-1);
Assert.assertTrue(p.x == 0 && p.y == 1);
}
//
// Test a simple negative move
//
@Test
public void simpleMoveNeg()
{
Point p;
System.out.println("Running test simpleMoveNeg.");
p = circle1.moveBy(-1, -1);
Assert.assertTrue(p.x == 0 && p.y == 1);
}
/*** NOT USED
public static void main(String args[])
{
try {
org.junit.runner.JUnitCore.runClasses(
java.lang.Class.forName("Circle1Test"));
} catch (Exception e) {
System.out.println("Exception: " + e);
}
}
***/
/***
* NOT USED public static void main(String args[]) { try { org.junit.runner.JUnitCore.runClasses(
* java.lang.Class.forName("Circle1Test")); } catch (Exception e) { System.out.println("Exception:
* " + e); } }
***/
}
+14 -17
View File
@@ -1,25 +1,22 @@
package edu.nmsu.cs.circles;
public class Circle2 extends Circle
{
public Circle2(double x, double y, double radius)
{
super(y,x,radius);
}
public Circle2(double x, double y, double radius)
{
super(y, x, radius);
}
public boolean intersects(Circle other)
{
double d;
d = Math.sqrt(Math.pow(center.x - other.center.x, 2) +
Math.pow(center.y - other.center.y, 2));
if (d < radius)
return true;
else
return false;
}
public boolean intersects(Circle other)
{
double d;
d = Math.sqrt(Math.pow(center.x - other.center.x, 2) +
Math.pow(center.y - other.center.y, 2));
if (d < radius)
return true;
else
return false;
}
}
+35 -32
View File
@@ -1,40 +1,43 @@
package edu.nmsu.cs.circles;
/**
* Sample tester for Circle1 and Circle2
**/
* Sample tester for Circle1 and Circle2
**/
public class CircleRun
{
/**
* Accept command line args for two circles and then run their
* intersect() methods.
**/
public static void main(String args[])
{
Circle1 c1;
Circle2 c2;
if (args.length != 6) {
System.out.println("Error: args must be x1 y1 r1 x2 y2 r2");
return;
}
try {
double x, y, r;
x = Double.parseDouble(args[0]);
y = Double.parseDouble(args[1]);
r = Double.parseDouble(args[2]);
c1 = new Circle1(x,y,r);
x = Double.parseDouble(args[3]);
y = Double.parseDouble(args[4]);
r = Double.parseDouble(args[5]);
c2 = new Circle2(x,y,r);
} catch (Exception e) {
System.out.println("Bad arguments! " + e);
e.printStackTrace();
return;
}
System.out.println("Circle 1 says: " + c1.intersects(c2));
System.out.println("Circle 2 says: " + c2.intersects(c1));
}
/**
* Accept command line args for two circles and then run their intersect() methods.
**/
public static void main(String args[])
{
Circle1 c1;
Circle2 c2;
if (args.length != 6)
{
System.out.println("Error: args must be x1 y1 r1 x2 y2 r2");
return;
}
try
{
double x, y, r;
x = Double.parseDouble(args[0]);
y = Double.parseDouble(args[1]);
r = Double.parseDouble(args[2]);
c1 = new Circle1(x, y, r);
x = Double.parseDouble(args[3]);
y = Double.parseDouble(args[4]);
r = Double.parseDouble(args[5]);
c2 = new Circle2(x, y, r);
}
catch (Exception e)
{
System.out.println("Bad arguments! " + e);
e.printStackTrace();
return;
}
System.out.println("Circle 1 says: " + c1.intersects(c2));
System.out.println("Circle 2 says: " + c2.intersects(c1));
}
}
+3 -4
View File
@@ -1,9 +1,8 @@
package edu.nmsu.cs.circles;
public class Point
{
double x;
double y;
}
double x;
double y;
}