Directions: Fill in answers on the pages below. Don't spend too much time on any one problem.
Questions about classes.
The Circle class should have data fields giving the circle's radius, x-coordinate of center, and y-coordinate of center.
There should be methods to return each of these fields, as well the methods getArea() and getCircumference(). (Recall for a circle of radius r, the area is pi * r 2, and the circumference is 2 * pi * r. You should also use Math.PI as the source of the constant pi.)
There should be two constructors, the second one letting the coordinates of the center default to zeros. In both constructors, if the parameter for the radius is negative, set it equal to zero.
Fill in the blanks below to complete the Java implementation of this class:
public class Circle {
// data fields for the object
private double myRadius;
private double myX; // x coordinate of center
private double myY; // y coordinate of center
// constructors
public Circle(double radius, double x, double y) {
}
// center defaults to (0, 0)
public Circle(double radius) {
}
//accessors
public double getRadius( ) {
}
public double getX( ) {
}
public double getY( ) {
}
// other methods
public double getArea( ) {
}
public double getCircumference( ) {
}
}
public class CircleTest {
public static void main (String[] args) {
}
}
Circle: Radius: 10.0, Center: (2.0, 3.0), Area: 314.1592653589793, Circumference: 62.83185307179586
public int compareTo(Circle c) {
}
Give an if statement that will check if string s comes before string t in lexicographic order and will print "s precedes t" if it is true.
String s = "UTSA";
and will print each character of s on a separate line, so that in this case it will print:
U T S A
You must use a loop and it should work no matter what s is.