Loading .idea/inspectionProfiles/Project_Default.xml 0 → 100644 +8 −0 Original line number Diff line number Diff line <component name="InspectionProjectProfileManager"> <profile version="1.0"> <option name="myName" value="Project Default" /> <inspection_tool class="JavadocDeclaration" enabled="true" level="WARNING" enabled_by_default="true"> <option name="ADDITIONAL_TAGS" value="note:,note:" /> </inspection_tool> </profile> </component> No newline at end of file src/edu/bu/ec504/hw3/p1/Canvas.java +28 −16 Original line number Diff line number Diff line Loading @@ -24,12 +24,16 @@ public abstract class Canvas implements Iterable<CanvasPoint> { * @param pnt The point to add. It must be that: * The X coordinate of the point: 0<= pnt.x <={{@link #Xsize}}. * The Y coordinate of the point. 0<=pnt.y <={{@link #Ysize}}. * @throws IllegalArgumentException if the point is out of the bounds of this Canvas. * @note: There can be only one point at any given location. * @note: You may want to override this method. */ public void addPoint(CanvasPoint pnt) { _checkPoint(pnt); points.add(pnt); } public void addPoint(CanvasPoint pnt) throws IllegalArgumentException { if (_checkPoint(pnt)) points.add(pnt); else throw new IllegalArgumentException("Point coordinates off canvas:" + pnt); } /** * Deletes the point at location <code>pnt</code> in the plane, if it exists. Loading @@ -40,12 +44,15 @@ public abstract class Canvas implements Iterable<CanvasPoint> { * @note: You may want to override this method. */ public boolean deletePoint(CanvasPoint pnt) { _checkPoint(pnt); return points.remove(pnt); } if (_checkPoint(pnt)) return points.remove(pnt); else return false; } /** * Produce a covering of the entire canvas. More specifically, * produce an list of centers such that each point on the canvas * produce a list of centers such that each point on the canvas * is within a unit-radius circle around at least one of the centers. * * @return A list of centers of unit circles. Loading @@ -63,8 +70,7 @@ public abstract class Canvas implements Iterable<CanvasPoint> { } /** * * @param centers * @param centers The centers of circles of a covering. * @return true iff unit circles centered at the points in <code>centers</code> * cover all the points in this data structure. */ Loading @@ -85,12 +91,18 @@ public abstract class Canvas implements Iterable<CanvasPoint> { return true; } final private void _checkPoint(CanvasPoint pnt) { if ((pnt.x<0) || (pnt.x>Xsize) || (pnt.x<0) || (pnt.y>Ysize)) throw new RuntimeException("Point coordinates off canvas"); /** * @param pnt The point being checked. * @return true iff <code>pnt</code> is within the bounds of this Canvas */ private boolean _checkPoint(CanvasPoint pnt) { if ((pnt.x<0) || (pnt.x>Xsize) || (pnt.y<0) || (pnt.y>Ysize)) return false; else return true; } final private double _distance(CanvasPoint pnt1, CanvasPoint pnt2) { private double _distance(CanvasPoint pnt1, CanvasPoint pnt2) { return Math.sqrt( Math.pow(pnt1.x - pnt2.x,2) + Math.pow(pnt1.y - pnt2.y,2) Loading Loading @@ -120,8 +132,8 @@ public abstract class Canvas implements Iterable<CanvasPoint> { } // FIELDS protected double Xsize; protected double Ysize; protected ArrayList<CanvasPoint> points; protected final double Xsize; protected final double Ysize; protected final ArrayList<CanvasPoint> points; } src/edu/bu/ec504/hw3/p1/GraphicalMain.java +2 −8 Original line number Diff line number Diff line Loading @@ -6,12 +6,11 @@ import edu.bu.ec504.hw3.p1.Canvas.CanvasPoint; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Point; import javax.swing.JFrame; import javax.swing.JPanel; /** * A graphical version of the main class. * A graphical version of the main class, which may be useful for debugging. * (FYI: modeled after chatGPT4 response to "Please give me a sample program that draws a line on a 2d java window.") */ public class GraphicalMain extends JFrame { Loading Loading @@ -77,11 +76,6 @@ public class GraphicalMain extends JFrame { } public static void main(String[] args) { invokeLater(new Runnable() { @Override public void run() { new GraphicalMain(); } }); invokeLater(GraphicalMain::new); } } src/edu/bu/ec504/hw3/p1/MyCanvas.java +2 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,8 @@ public class MyCanvas extends Canvas { @Override public ArrayList<CanvasPoint> generateCovering() { // This demo implementation generates a trivial covering, where there is // a circle around each point. ArrayList<CanvasPoint> centers = new ArrayList<>(); for (CanvasPoint pnt: this) { centers.add(new CanvasPoint(pnt.x, pnt.y)); Loading Loading
.idea/inspectionProfiles/Project_Default.xml 0 → 100644 +8 −0 Original line number Diff line number Diff line <component name="InspectionProjectProfileManager"> <profile version="1.0"> <option name="myName" value="Project Default" /> <inspection_tool class="JavadocDeclaration" enabled="true" level="WARNING" enabled_by_default="true"> <option name="ADDITIONAL_TAGS" value="note:,note:" /> </inspection_tool> </profile> </component> No newline at end of file
src/edu/bu/ec504/hw3/p1/Canvas.java +28 −16 Original line number Diff line number Diff line Loading @@ -24,12 +24,16 @@ public abstract class Canvas implements Iterable<CanvasPoint> { * @param pnt The point to add. It must be that: * The X coordinate of the point: 0<= pnt.x <={{@link #Xsize}}. * The Y coordinate of the point. 0<=pnt.y <={{@link #Ysize}}. * @throws IllegalArgumentException if the point is out of the bounds of this Canvas. * @note: There can be only one point at any given location. * @note: You may want to override this method. */ public void addPoint(CanvasPoint pnt) { _checkPoint(pnt); points.add(pnt); } public void addPoint(CanvasPoint pnt) throws IllegalArgumentException { if (_checkPoint(pnt)) points.add(pnt); else throw new IllegalArgumentException("Point coordinates off canvas:" + pnt); } /** * Deletes the point at location <code>pnt</code> in the plane, if it exists. Loading @@ -40,12 +44,15 @@ public abstract class Canvas implements Iterable<CanvasPoint> { * @note: You may want to override this method. */ public boolean deletePoint(CanvasPoint pnt) { _checkPoint(pnt); return points.remove(pnt); } if (_checkPoint(pnt)) return points.remove(pnt); else return false; } /** * Produce a covering of the entire canvas. More specifically, * produce an list of centers such that each point on the canvas * produce a list of centers such that each point on the canvas * is within a unit-radius circle around at least one of the centers. * * @return A list of centers of unit circles. Loading @@ -63,8 +70,7 @@ public abstract class Canvas implements Iterable<CanvasPoint> { } /** * * @param centers * @param centers The centers of circles of a covering. * @return true iff unit circles centered at the points in <code>centers</code> * cover all the points in this data structure. */ Loading @@ -85,12 +91,18 @@ public abstract class Canvas implements Iterable<CanvasPoint> { return true; } final private void _checkPoint(CanvasPoint pnt) { if ((pnt.x<0) || (pnt.x>Xsize) || (pnt.x<0) || (pnt.y>Ysize)) throw new RuntimeException("Point coordinates off canvas"); /** * @param pnt The point being checked. * @return true iff <code>pnt</code> is within the bounds of this Canvas */ private boolean _checkPoint(CanvasPoint pnt) { if ((pnt.x<0) || (pnt.x>Xsize) || (pnt.y<0) || (pnt.y>Ysize)) return false; else return true; } final private double _distance(CanvasPoint pnt1, CanvasPoint pnt2) { private double _distance(CanvasPoint pnt1, CanvasPoint pnt2) { return Math.sqrt( Math.pow(pnt1.x - pnt2.x,2) + Math.pow(pnt1.y - pnt2.y,2) Loading Loading @@ -120,8 +132,8 @@ public abstract class Canvas implements Iterable<CanvasPoint> { } // FIELDS protected double Xsize; protected double Ysize; protected ArrayList<CanvasPoint> points; protected final double Xsize; protected final double Ysize; protected final ArrayList<CanvasPoint> points; }
src/edu/bu/ec504/hw3/p1/GraphicalMain.java +2 −8 Original line number Diff line number Diff line Loading @@ -6,12 +6,11 @@ import edu.bu.ec504.hw3.p1.Canvas.CanvasPoint; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Point; import javax.swing.JFrame; import javax.swing.JPanel; /** * A graphical version of the main class. * A graphical version of the main class, which may be useful for debugging. * (FYI: modeled after chatGPT4 response to "Please give me a sample program that draws a line on a 2d java window.") */ public class GraphicalMain extends JFrame { Loading Loading @@ -77,11 +76,6 @@ public class GraphicalMain extends JFrame { } public static void main(String[] args) { invokeLater(new Runnable() { @Override public void run() { new GraphicalMain(); } }); invokeLater(GraphicalMain::new); } }
src/edu/bu/ec504/hw3/p1/MyCanvas.java +2 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,8 @@ public class MyCanvas extends Canvas { @Override public ArrayList<CanvasPoint> generateCovering() { // This demo implementation generates a trivial covering, where there is // a circle around each point. ArrayList<CanvasPoint> centers = new ArrayList<>(); for (CanvasPoint pnt: this) { centers.add(new CanvasPoint(pnt.x, pnt.y)); Loading