package edu.luc.etl.cs313.android.shapes.model; import java.util.List; /** * A shape visitor for calculating the bounding box, that is, the smallest * rectangle containing the shape. The resulting bounding box is returned as a * rectangle at a specific location. */ public class BoundingBox implements Visitor<Location> { // TODO entirely your job (except onCircle) @Override public Location onCircle(final Circle c) { final int radius = c.getRadius(); return new Location(-radius, -radius, new Rectangle(2 * radius, 2 * radius)); } @Override public Location onFill(final Fill f) { return f.getShape().accept(this); } @Override public Location onGroup(final Group g) { // Fill this method } @Override public Location onLocation(final Location l) { Location location = l.shape.accept(this); return new Location(l.x+location.x, l.y+location.y, location.shape); } @Override public Location onRectangle(final Rectangle r) { return new Location(0, 0, new Rectangle(r.getWidth(), r.getHeight())); } @Override public Location onStroke(final Stroke c) { return c.getShape().accept(this); } @Override public Location onOutline(final Outline o) { return o.getShape().accept(this); } @Override public Location onPolygon(final Polygon s) { // Fill this method } }
package edu.luc.etl.cs313.android.shapes.model;
import java.util.List;
/**
* A shape visitor for calculating the bounding box, that is, the smallest
* rectangle containing the shape. The resulting bounding box is returned as a
* rectangle at a specific location.
*/
public class BoundingBox implements Visitor<Location> {
// TODO entirely your job (except onCircle)
@Override
public Location onCircle(final Circle c) {
final int radius = c.getRadius();
return new Location(-radius, -radius, new Rectangle(2 * radius, 2 * radius));
}
@Override
public Location onFill(final Fill f) {
return f.getShape().accept(this);
}
@Override
public Location onGroup(final Group g) {
int xMin=0, xMax=0, yMin=0, yMax=0;
int count = 0;
Location location;
Rectangle rectangle;
for(Shape shape : g.shapes) {
location = shape.accept(this);
rectangle = (Rectangle) location.shape;
if(count == 0) {
xMin = location.x;
xMax = location.x + rectangle.width;
yMin = location.y;
yMax = location.y + rectangle.height;
} else {
if(location.x < xMin) {
xMin = location.x;
}
if(location.y < yMin) {
yMin = location.y;
}
if(location.x + rectangle.width > xMax) {
xMax = location.x + rectangle.width;
}
if(location.y + rectangle.height > yMax) {
yMax = location.y + rectangle.height;
}
}
count++;
}
return new Location(xMin, yMin, new Rectangle(xMax-xMin, yMax-yMin));
}
@Override
public Location onLocation(final Location l) {
Location location = l.shape.accept(this);
return new Location(l.x+location.x, l.y+location.y, location.shape);
}
@Override
public Location onRectangle(final Rectangle r) {
return new Location(0, 0, new Rectangle(r.getWidth(), r.getHeight()));
}
@Override
public Location onStroke(final Stroke c) {
return c.getShape().accept(this);
}
@Override
public Location onOutline(final Outline o) {
return o.getShape().accept(this);
}
@Override
public Location onPolygon(final Polygon s) {
int xMin=0, xMax=0, yMin=0, yMax=0;
int count = 0;
Point point;
for(Shape shape : s.shapes) {
point = (Point) shape;
if(count == 0) {
xMin = point.x;
xMax = point.x;
yMin = point.y;
yMax = point.y;
} else {
if(point.x < xMin) {
xMin = point.x;
}
if(point.y < yMin) {
yMin = point.y;
}
if(point.x > xMax) {
xMax = point.x;
}
if(point.y > yMax) {
yMax = point.y;
}
}
count++;
}
return new Location(xMin, yMin, new Rectangle(xMax-xMin, yMax-yMin));
}
}
package edu.luc.etl.cs313.android.shapes.model; import java.util.List; /** * A shape visitor for calculating the bounding box, that is,...
I need some help with some homework questions. How would I implement the to-do's? ----------------------------------------------------------------------------------------------------------------------------------------------------------- AbstractArrayHeap.Java package structures; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; import java.util.NoSuchElementException; public abstract class AbstractArrayHeap<P, V> { protected final ArrayList<Entry<P, V>> heap; protected final Comparator<P> comparator; protected AbstractArrayHeap(Comparator<P> comparator) { if (comparator == null) { throw new NullPointerException(); } this.comparator = comparator; heap = new ArrayList<Entry<P, V>>(); } public final AbstractArrayHeap<P, V> add(P priority, V value) { if (priority == null || value...
package scheduler; import java.util.List; public class Scheduler { /** * Instantiates a new, empty scheduler. */ public Scheduler() { } /** * Adds a course to the scheduler. * * @param course the course to be added */ public void addCourse(Course course) { } /** * Returns the list of courses that this scheduler knows about. * * This returned object does not share state with the internal state of the Scheduler. * * @return the list of courses */...
package week_4; import input.InputUtils; import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Random; import static input.InputUtils.positiveIntInput; import static input.InputUtils.yesNoInput; /** Write a program to roll a set of dice. Generate a random number between 1 and 6 for each dice to be rolled, and save the values in an ArrayList. Display the total of all the dice rolled. In some games, rolling the same number on all dice has a special meaning. In your program, check if all dice have the same value,...
ANNOTATE BRIEFLY LINE BY LINE THE FOLLOWING CODE: package shop.data; import junit.framework.Assert; import junit.framework.TestCase; public class DataTEST extends TestCase { public DataTEST(String name) { super(name); } public void testConstructorAndAttributes() { String title1 = "XX"; String director1 = "XY"; String title2 = " XX "; String director2 = " XY "; int year = 2002; Video v1 = Data.newVideo(title1, year, director1); Assert.assertSame(title1, v1.title()); Assert.assertEquals(year, v1.year()); Assert.assertSame(director1, v1.director()); Video v2 = Data.newVideo(title2, year, director2); Assert.assertEquals(title1, v2.title()); Assert.assertEquals(director1, v2.director()); } public void testConstructorExceptionYear()...
Receiveing this error message when running the Experts code below please fix ----jGRASP exec: javac -g GeometricObject.java GeometricObject.java:92: error: class, interface, or enum expected import java.util.Comparator; ^ 1 error ----jGRASP wedge2: exit code for process is 1. ----jGRASP: operation complete. 20.21 Please code using Java IDE. Please DO NOT use Toolkit. You can use a class for GeometricObject. MY IDE does not have access to import ToolKit.Circle;import. ToolKit.GeometricObject;.import ToolKit.Rectangle. Can you code this without using the ToolKit? Please show an...
Implement the missing methods in java! Thanks! import java.util.Iterator; import java.util.NoSuchElementException; public class HashTableOpenAddressing<K, V> implements DictionaryInterface<K, V> { private int numEntries; private static final int DEFAULT_CAPACITY = 5; private static final int MAX_CAPACITY = 10000; private TableEntry<K, V>[] table; private double loadFactor; private static final double DEFAULT_LOAD_FACTOR = 0.75; public HashTableOpenAddressing() { this(DEFAULT_CAPACITY, DEFAULT_LOAD_FACTOR); } public HashTableOpenAddressing(int initialCapacity, double loadFactorIn) { numEntries = 0; if (loadFactorIn <= 0 || initialCapacity <= 0) { throw new IllegalArgumentException("Initial capacity and load...
Templates
Apartment.java
package hwk7;
public class Apartment {
int numOfApartments; // the number of apartments of
this type
Room[] rooms; // rooms in this type of
apartment
Apartment(int numOfApartments, Room[] rooms) {
this.numOfApartments =
numOfApartments;
this.rooms = rooms;
}
// Return the window orders for one apartment of
this type as TotalOrder object
TotalOrder orderForOneUnit() {
// TODO
}
// Return the window...
***Code to solve***
package functions;
import java.math.*; // for BigInteger
public class NodeTransitionFunction {
public NodeTransitionFunction(Integer exp, Integer
KVal) {
// CONSTUCTOR: Sets the class to
calculate f(x) = (x ^ exp) mod KVal
// TODO
}
public Integer apply(Integer val) {
// PRE: -
// POST: Implements f(val)
return null;
}
public BigInteger apply(BigInteger val) {
// PRE:...
package week_3; import java.util.Scanner; import java.util.*; //import java.lang.*; //import java.io.*; /** Write a program that can help decide if a particular programming project is best solved using a Waterfall or Agile methodology. Your program should ask the user: • How many programmers will be on the team [ More than 30 programmers -> Waterfall ] • If there needs to be firm deadlines and a fixed schedule [ Yes - > Waterfall ] • If the programmers have experience in...
import javax.swing.*; import java.awt.*; import java.util.List; import java.util.*; /** * Canvas is a class to allow for simple graphical drawing on a canvas. * This is a modification of the general purpose Canvas, specially made for * the BlueJ "shapes" example. * * @author: Bruce Quig * @author: Michael Kolling (mik) * Minor changes to canvas dimensions by William Smith 6/4/2012 * * @version: 1.6 (shapes) */ public class Canvas { // Note: The implementation of this class (specifically the...