Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Learning Java (Classes/Constructors

Name: Anonymous 2011-10-20 18:58

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.)

Name: Anonymous 2011-10-20 20:59




public class Circle
{
    public int radius;
    public int diameter;
   
    public int getRadius()
    {
        return radius;
    }
   
    public int getDiameter()
    {
        return diameter;
    }
}




public class CircleProg
{
    public static void main(String[]args)
    {
        Circle shit = new Circle();
        Scanner keyboard = new Scanner(System.in);
       
        System.out.println("Please enter a radius and a diameter.");
        int radiusInput = keyboard.nextInt();
        int diameterInput = keyboard.nextInt();
       
       
        shit.radius = radiusInput;
        shit.diameter = diameterInput;
       
       
        System.out.println("Returned radius is "+shit.getRadius());
        System.out.println("and returned diameter is "+shit.getDiameter());
       
    }
}


This what you are trying to do?

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List