Seems like I am the only one who is posting in the java section =(
Well its not that I have the problems , I am just want you to look over my code and tell me what you think. You know, I just need a professional advice. I will delete the problem text so people wont cheat on the homework.
The problem:
Circle Class Write a Circle class that has the following fields: • radius: a double • PI: a final double initialized with the value 3.14159 The class should have the following methods: • Constructor. Accepts the radius of the circle as an argument. • Constructor. A no-arg constructor that sets the radius field to 0.0. • setRadius. A mutator method for the radius field. • getRadius. An accessor method for the radius field. • getArea. Returns the area of the circle, which is calculated as area = PI * radius * radius • getDiameter. Returns the diameter of the circle, which is calculated as diameter = radius * 2 • getCircumference. Returns the circumference of the circle, which is calculated as circumference = 2 * PI * radius Write a program that demonstrates the Circle class by asking the user for the circle's radius, creating a Circle object, and then reporting the circle's area, diameter, and circumference.
My solution:
THE CIRCLE CLASS
/*
* The Circle class hold data about a circle.
*
*/
/**
*
* @author Alexander Trowell
*/
public class Circle
{
// Fields
private double radius; // Radius of the circle
final private double PI = 3.14159; // The value of the PI
/**
* Constructor
*
* @param radius The circles radius
*/
public Circle(double radius)
{
this.radius = radius;
}
/**
* Constructor No arg constructor that the sets the radius field to 0.0
*/
public Circle()
{
radius = 0.0;
}
/**
* The setRadius method sets the Circles radius
* @param radius returns radius of the circle
*/
public void setRadius(double radius)
{
this.radius = radius;
}
/**
* The getRadius method
* @return the radius of the circle
*/
public double getRadius()
{
return radius;
}
/**
* The getArea method
* @return the area of the circle
*/
public double getArea()
{
return PI * radius * radius;
}
/**
* The getDiameter method
* @return the diameter of the circle
*/
public double getDiameter()
{
return radius * 2;
}
/**
* The getCircumference method
* @return the circumference of the circle
*/
public double getCircumference()
{
return 2 * PI * radius;
}
}
Main MEHOD
import java.util.Scanner;
/**
*
* @author Alexander Trowell
*/
public class CircleDemo {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
double radius; // To hold a radius
// Create a Scanner object for keyboard input
Scanner scan = new Scanner(System.in);
// Get the number for the radius
System.out.println("Please enter the circle's radius");
radius = scan.nextDouble();
// Create an instance of the Circle class,
// passing the data that was entered as arguments
// to the constructor.
Circle circle1 = new Circle(radius);
// Output
System.out.println("The area of the circle with radius of "+radius+" is "+ circle1.getArea()
+" with diameter of "+circle1.getDiameter()+" and with circumference of "+circle1.getCircumference());
}
}
Loading
VulpesPosted Mar 12, 2012, 5:38 PM
Sam HobbsPosted Mar 14, 2012, 10:10 PM
I tried Netbeans but that was back when my processor was slow. Netbeans does not do well with a slow processor. Back then, Netbeans was designed for use in Unix/Linux and the documentation was written using Unix terminology that was difficult for me to understand. The main problem is that the Netbeans users were more sarcastic than helpful for explaining the parts that are unique to Unix/Linux. I think they said things like mounting a file system, which is essentially never done in Windows. I assume there is a Windows equivalent but the Netbeans users was just critical and said read the documentation. I sure hope you get more help here than in the Netbeans forums and/or the Netbeans users are more helpful now than in the past.
I have no doubt that Netbeans is useful but Eclipse seems to be getting more use.
Prime bPosted Mar 14, 2012, 5:48 PM
VulpesPosted Mar 13, 2012, 5:41 AM
Curiously, Microsoft use the word 'accessor' for both 'get' and 'set' even though it's really only applicable to the former. Yet another example of confusing terminology!
See for example:
http://msdn.microsoft.com/en-us/library/x9fsa0sw(VS.80).aspx
Sam HobbsPosted Mar 13, 2012, 12:08 AM
The code seems to work for me in Eclipse. I assume you do not use VS for Java, so what IDE do you use?
VulpesPosted Mar 12, 2012, 7:45 PM
Nor am I member of any social networking sites.
I'm a bit of a Luddite in some ways :)
Prime bPosted Mar 12, 2012, 6:50 PM
Vulpes do you have like skype or msn?