// Doing computations in java
import uwcse.io.*;
import javax.swing.JOptionPane; //for the dialog boxes
import java.util.*;
/**
* A MakingCoasters object has a rectangular piece of fabric, defined by its
* width and length.
* It can compute the number of coasters of a certain radius that can be cut out
* of that piece of fabric and the percentage of fabric that goes unused
*/
public class MakingCoasters {
// instance variables
// Dimensions of the piece of fabric (in feet)
private int width;
private int length;
// Note: using the same name for more than one method (here for
// the constructors) is an example of overloading.
/**
* Default constructor for objects of type MakingCoasters.
* The dimensions of the piece of fabric are input by the user.
* If any input is negative or 0, the corresponding dimension is set to 1
* foot.
*/
public MakingCoasters() {
// Initialize the dimensions of the piece of fabric
// Input from the user via an input object
// Check that the input is valid (dimension>0)
// Use a method checkWidthAndLength()
// (we will use it again in the other constructor)
}
/**
* MakingCoasters constructor
* Width and length are set to w and l if w and l are positive integers.
* If any of them is negative or zero, the corresponding dimension is set to
* one foot.
*
* @param w
* the width of the piece of fabric
* @param l
* the length of the piece of fabric
*/
public MakingCoasters(int w, int l) {
}
/**
* Compute the number of coasters of a given radius that can be cut out of
* the piece of fabric.
*
* @param radius
* the radius of one coaster in feet.
*/
public int computeNumberOfCoasters(int radius) {
// If the radius is negative or 0, no coaster is cut out
// Display an error message and return 0
if (radius <= 0) {
} else {
// To find the number of coasters:
// Multiply the number of coasters that fit along the length by the
// number of coasters that fit along the width and return the
// result.
// IMPORTANT NOTE: / between integers is the integer division
// 50/3 is 16 (not 16.6666)
}
}
/**
* Compute the percentage of fabric that goes unused when cutting out
* coasters of a given radius
*
* @param radius
* the radius of one coaster in feet
*/
public double computePercentageUnused(int radius) {
// If the radius is negative or 0, no coaster is cut out
// Display an error message and return 100
if (radius <= 0) {
} else {
// Area of the piece of fabric
double fabricArea;
// compute the area used for the coasters
// Math.PI is a constant within the Math class (=3.1415...)
// There is no exponent in Java. To square radius, write
// radius*radius
// (for higher exponents, use the Math.pow method)
double usedArea;
// area unused
double unusedArea;
// return it as a percentage
}
}
/**
* Check that the width and length are positive integers.
* Set to one foot any of them that is negative or 0 and display an error
* message.
*/
private void checkWidthAndLength() {
}
}