Designate the following statements as either True or False:
Circle the best answer to each question:
int a = 4;
int b = 1;
int c = 2;
int d = 6;
int e = 3;
int f = 10;
int v, w, x, y, z;
v = a + b/c + d * e; // v = 22
w = f % c + a; // w = 4
x = (e * e + c/e) * c; // x = 18
y = f + (int) 5.8; // y = 15
z = f % a - e; // z = -1
Area = Math.PI * (radius) * (radius)
Circumference = 2 * Math.PI * radius
class DriverClass{
public static void main(String args[])
{
Calculation myCalculator = new Calculation();
myCalculator.start(5.2); // 5.2 is the radius of the circle
}
}
----------------------------------------------------------------------------
import javabook.*;
/**
* Class with 4 methods: start, calcArea, calcCircumference, display.
* I chose to use the default constructor and have no data members for
* this class.
**/
class Calculation{
/**
* start calls all other methods: calcArea,calcCircumference,display
* @param r is the radius of the circle
* @return none
* Bug: Does not check parameter, lets other methods check this.
**/
public void start(double r){
display(calcArea(r),calcCircumference(r));
}
/**
* calcArea uses the formula for the area of a circle to calculate the
* area, returns -1 if radius is negative
* @param radius is radius of the circle
* @return area of circle
**/
private double calcArea(double radius){
if(radius < 0)
return -1; //error condition
else
return Math.PI * radius * radius;
}
/**
* calcCircumference uses the formula for the circumference of a circle to
* calculate the circumference, returns -1 if the radius is negative
* @param radius is the radius of the circle
* @return circumference of the circle
**/
private double calcCircumference(double radius){
if(radius < 0)
return -1; //error condition
else
return Math.PI * 2 * radius;
}
/**
* display takes an area and circumference and displays them. If either
* is negative, an error message is displayed.
* @param a is the area of the circle
* @param c is the circumference of the circle
**/
private void display(double a, double c){
MainWindow window = new MainWindow();
window.show();
OutputBox output = new OutputBox(window);
if(a < 0 || c < 0) //problem with negative numbers
output.printLine("Negative values are illegal");
else
output.printLine("The area is " + a + " and the circumference is "+c);
output.show();
}
}