a6
This commit is contained in:
17
assignment6/Question1/IShape.java
Normal file
17
assignment6/Question1/IShape.java
Normal file
@@ -0,0 +1,17 @@
|
||||
import java.awt.Graphics;
|
||||
|
||||
public interface IShape {
|
||||
public int getX();
|
||||
|
||||
public int getY();
|
||||
|
||||
public void setX(int x);
|
||||
|
||||
public void setY(int y);
|
||||
|
||||
public boolean isVisible(int w, int h);
|
||||
|
||||
public boolean isIn(int x, int y);
|
||||
|
||||
public void draw(Graphics g);
|
||||
}
|
||||
51
assignment6/Question1/Shape.java
Normal file
51
assignment6/Question1/Shape.java
Normal file
@@ -0,0 +1,51 @@
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
|
||||
public abstract class Shape {
|
||||
private int x;
|
||||
private int y;
|
||||
private Color color;
|
||||
|
||||
/**
|
||||
* Constructor for Shape
|
||||
*
|
||||
* @param x
|
||||
* the x coordinate of the shape
|
||||
* @param y
|
||||
* the y coordinate of the shape
|
||||
*/
|
||||
public Shape(int x, int y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
color = new Color((float) Math.random(), (float) Math.random(), (float) Math.random());
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public void setX(int x) {
|
||||
this.x = x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setY(int y) {
|
||||
this.y = y;
|
||||
}
|
||||
|
||||
public abstract boolean isVisible(int w, int h);
|
||||
|
||||
public abstract boolean isIn(int x, int y);
|
||||
|
||||
public void draw(Graphics g) {
|
||||
g.setColor(color);
|
||||
}
|
||||
|
||||
public static void testShape() {
|
||||
// TODO: implement this method
|
||||
// Because this is the abstract so we don't test anything here.
|
||||
}
|
||||
}
|
||||
5
assignment6/Question1/Start.java
Normal file
5
assignment6/Question1/Start.java
Normal file
@@ -0,0 +1,5 @@
|
||||
public class Start {
|
||||
public static void main(String[] args) {
|
||||
Shape.testShape();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user