difficulty understanding writing classes
Hey again guys, I got stuck again and was wondering if people wouldn't mind helping out this guy again. This time I got stuck learning how to create classes and then using them in different methods. So here's what the assignment is about:
Design and implement a class called Sphere that contains instance data that represents the sphere's diameter.
1. Define the Sphere constructor to and initialize the diameter, and include getter and setter methods for the diameter.
2. Include methods that calculate and return the volume and surface area of the sphere
3. Include a toString method that returns a one-line description of the sphere.
4. Create a driver class called MultiSphere, whose main method instantiates and updates several Sphere objects.
Code:
// Sphere project for pp0401. *Works together with MultiSphere project.
public class Sphere {
{
private double diameter;
public Sphere (double width)
{
diameter = width;
}
public double radius()
{
radius = diameter / 2;
r = radius;
}
public double volume()
{
volume = 4 * Math.PI * Math.pow(r, 3);
}
public double SA()
{
SA = 4 * Math.PI * Math.pow(r, 2);
}
public String toString()
{
return diameter + "/t" + radius + "/t" + volume "/t" + SA;
}
}
}
Code:
// MultiSphere project for pp0401. *Works together with Sphere project.
public class MultiSphere {
public static void main (String[] args)
{
Sphere sphere1 = new Sphere (54);
Sphere sphere2 = new Sphere (24);
Sphere sphere3 = new Sphere (1);
System.out.println (sphere1);
System.out.println (sphere2);
System.out.println (sphere3);
}
}
WHEN I RUN MultiSphere I GET THE ERROR:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The constructor Sphere(int) is undefined
The constructor Sphere(int) is undefined
The constructor Sphere(int) is undefined
WHEN I RUN Sphere I GET THE ERROR:
Exception in thread "main" java.lang.Error: Unresolved compilation problems:
The constructor Sphere(int) is undefined
The constructor Sphere(int) is undefined
The constructor Sphere(int) is undefined
at MultiSphere.main(MultiSphere.java:7)
What am I doing wrong? Please tell me in details, but in English... Speaking in Java still confuses me to the point where I say "huh?" and would point back the the question like you might not have understood my question. :P
Thanks in advance guys~! I am just waiting until I get to the point I am fluent enough in Java to give back to the community, but it's not happening as quickly as possible... please be understanding.