What do I need to look into to understand this better?
My professor gave an assignment to create a class called Circle in which I store the radius and diameter, using a constructor, then create a program that populates those variables using user input. I'm a bit confused because the book uses Rectangle as an example, and it seems that "Rectangle" and "box" are specifically part of java, whereas using "Circle" and "round" doesn't work for me.
I'm about to completely scratch what I have, copy the rectangle code, complile and run it to check it works, then try to customize it to work with a circle. Any advice would be much appreciated. Thanks. (Please don't just post code and do it for me.)
Alright, retyping their code, I realized that box and Rectangle are just arbitrary words they used to build their rectangle to call upon the method. Essentially Rectangle was referencing a previous code and box was a method of that code.
I used a similar method but now I'm getting the following error:
----------------------------------------------------------------
Circle.java:13: error: cannot find symbol
return rad;
^
symbol: variable rad
location: class Circle
Circle.java:17: error: cannot find symbol
return dia;
^
symbol: variable dia
location: class Circle
2 errors
double posting and quote fail Nigger, what are you doing?
Name:
Anonymous2011-10-20 22:33
Welcome to Java!
interface ICircle {
public void setRadius(double radius);
public double getRadius();
public void setDiameter(double diameter);
public double getDiameter();
}
class Circle implements ICircle {
private double radius;
private double diameter;
public void setRadius(double radius) {
this.radius = radius;
}
public double getRadius() {
return this.radius;
}
public void setDiameter(double diameter) {
this.diameter = diameter;
}
public double getDiameter() {
return this.diameter;
}
}
class CircleFactory {
public ICircle create() {
return new Circle;
}
}
public class CircleDriver {
public static void main(String[] args) {
ICircle circle = (new CircleFactory()).create();
Scanner input = new Scanner(System.in);
System.out.println("Please enter a radius and a diameter.");
circle.setRadius(input.nextDouble());
circle.setDiameter(input.nextDouble());
System.out.println("Your radius is: " + circle.getRadius());
System.out.println("Your diameter is: " + circle.getDiameter());
}
}