Java-class,methods and objects
Go to solution
Solved by jslowik,
You're getting errors on the return because you're returning something from a method that has no return type. The method signature is also incorrect. You're also lacking getters and setters which means the setColor and setRadius calls in the driver class won't work.
Here's a functioning example of what your class should at least resemble. I added some comments in to hopefully help clear up any questions. Though feel free to ask more.
public class Circle { private String color; private int radius; /** * Constructor that accepts all values. You aren't using this, but I * included it out of habit * * @param color * @param radius */ public Circle(String color, int radius) { this.color = color; this.radius = radius; } /** * This is the constructor that the CircleDriver class is calling * */ public Circle() { } public String getColor() { return color; } /** * Setter method for color. Required for driver class as written * * @param color */ public void setColor(String color) { this.color = color; } public int getRadius() { return radius; } /** * Setter method for radius. Required for driver class as written * * @param radius */ public void setRadius(int radius) { this.radius = radius; } /** * Your display method. Void return type, handles the print line itself * */ public void display() { System.out.println("I am a circle"); System.out.println("My color is " + color); System.out.println("My radius is " + radius); } /** * Compute area. Returns a double which is output by the driver class * * @return - radius = pi r ^2 */ public double computeArea() { return (Math.PI * Math.pow(radius, 2)); } /** * Compute circumference. Same as area, but different formula * * @return - circumference = 2 pi r */ public double computeCircumference() { return (2 * Math.PI * radius); } }
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now