-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
852 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
example/chapter08/src/main/java/com/nhnacademy/exam080101/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 8 additions & 33 deletions
41
practice/240723/cannonball/src/main/java/com/nhnacademy/Ball.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,43 @@ | ||
package com.nhnacademy; | ||
|
||
import java.awt.Color; | ||
import java.awt.Rectangle; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
public class Ball { | ||
public class Ball implements Regionable { | ||
public static final Color DEFAULT_COLOR = Color.BLACK; | ||
static Logger log = LogManager.getLogger(Ball.class); | ||
|
||
int x; | ||
int y; | ||
int radius; | ||
Region region; | ||
Color color; | ||
|
||
public Ball(int x, int y, int radius, Color color) { | ||
if (radius < 0) { | ||
throw new IllegalArgumentException(); | ||
} | ||
|
||
this.x = x; | ||
this.y = y; | ||
this.radius = radius; | ||
this.region = new Region(x, y, 2 * radius, 2 * radius); | ||
this.color = color; | ||
} | ||
|
||
public Ball(int x, int y, int radius) { | ||
this(x, y, radius, DEFAULT_COLOR); | ||
} | ||
|
||
public int getX() { | ||
return x; | ||
} | ||
|
||
public int getY() { | ||
return y; | ||
} | ||
|
||
public int getMinX() { | ||
return x - radius; | ||
} | ||
|
||
public int getMaxX() { | ||
return x + radius; | ||
} | ||
|
||
public int getMinY() { | ||
return y - radius; | ||
} | ||
|
||
public int getMaxY() { | ||
return y + radius; | ||
public Ball(Location location, int radius, Color color) { | ||
this(location.getX(), location.getY(), radius, color); | ||
} | ||
|
||
public int getRadius() { | ||
return radius; | ||
return region.getWidth() / 2; | ||
} | ||
|
||
public Color getColor() { | ||
return color; | ||
} | ||
|
||
public Rectangle getBounds() { | ||
return new Rectangle(x - radius, y - radius, 2 * radius, 2 * radius); | ||
public Region getRegion() { | ||
return region; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
practice/240723/cannonball/src/main/java/com/nhnacademy/Bounded.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.nhnacademy; | ||
|
||
import java.awt.Rectangle; | ||
|
||
public interface Bounded { | ||
Rectangle getBounds(); | ||
|
||
void setBounds(Rectangle bounds); | ||
|
||
boolean isOutOfBounds(Rectangle bounds); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
practice/240723/cannonball/src/main/java/com/nhnacademy/Box.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.nhnacademy; | ||
|
||
import java.awt.Color; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
public class Box implements Regionable { | ||
public static final Color DEFAULT_COLOR = Color.BLACK; | ||
static Logger log = LogManager.getLogger(Box.class); | ||
|
||
Region region; | ||
Color color; | ||
|
||
public Box(int x, int y, int width, int height, Color color) { | ||
if ((width < 0) || (height < 0)) { | ||
throw new IllegalArgumentException(); | ||
} | ||
|
||
this.region = new Region(x, y, width, height); | ||
this.color = color; | ||
} | ||
|
||
public Box(int x, int y, int width, int height) { | ||
this(x, y, width, height, DEFAULT_COLOR); | ||
} | ||
|
||
public Color getColor() { | ||
return color; | ||
} | ||
|
||
public Region getRegion() { | ||
return region; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
practice/240723/cannonball/src/main/java/com/nhnacademy/Dimension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.nhnacademy; | ||
|
||
public class Dimension { | ||
int width; | ||
int height; | ||
|
||
public Dimension(int width, int height) { | ||
this.width = width; | ||
this.height = height; | ||
} | ||
|
||
public int getWidth() { | ||
return width; | ||
} | ||
|
||
public int getHeight() { | ||
return height; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
return (o instanceof Dimension) | ||
&& (getWidth() == ((Dimension) o).getWidth()) | ||
&& (getHeight() == ((Dimension) o).getHeight()); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
practice/240723/cannonball/src/main/java/com/nhnacademy/DisplacementVector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package com.nhnacademy; | ||
|
||
public class DisplacementVector extends Vector { | ||
|
||
public DisplacementVector(int angle, int magnitude) { | ||
super((int) (magnitude * Math.cos(Math.toRadians(angle))), | ||
(int) (magnitude * Math.sin(Math.toRadians(angle)))); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
practice/240723/cannonball/src/main/java/com/nhnacademy/Location.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.nhnacademy; | ||
|
||
import java.awt.Point; | ||
|
||
public class Location { | ||
int x; | ||
int y; | ||
|
||
public Location(int x, int y) { | ||
this.x = x; | ||
this.y = y; | ||
} | ||
|
||
public Location(Location location) { | ||
x = location.getX(); | ||
y = location.getY(); | ||
} | ||
|
||
public int getX() { | ||
return x; | ||
} | ||
|
||
public int getY() { | ||
return y; | ||
} | ||
|
||
public void translate(int dx, int dy) { | ||
x += dx; | ||
y += dy; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
return (o instanceof Location) | ||
&& (getX() == ((Location) o).getX()) | ||
&& (getY() == ((Location) o).getY()); | ||
} | ||
} |
Oops, something went wrong.