Receive data from an array
I've only been programming in Java for three weeks, so take it easy on me.
I have created an array inside of a class. I want to receive the values of that array from within another class. The programs compile, but the answers are wrong.
Code:
public class Circle
{
private double radius; //instance variable
/**
* Constructor for objects of class Circle
*/
public Circle()
{
radius = 0; //initialise instance variables
}
public Circle(double r)
{
radius = r;
}
public void SetRadius(double r)
//modifying method allowing you to assign a new value to the variable
{
radius = r;
}
public double[] GetProperties()
{
double[] Properties = new double[3];
Properties[0] = 2 * radius; //Diameter
Properties[1] = 2 * Math.PI * radius; //Circumference
Properties[2] = Math.PI * Math.pow(radius, 2); //Area
return Properties;
}
}
Code:
import java.util.Scanner;
public class CircleTester
{
public static void main (String[]args)
{
Scanner keyboard = new Scanner(System.in);
while (true)
{
System.out.print("Please enter the radius: ");
Circle circle = new Circle(keyboard.nextDouble());
//Below, shouldn't I be declaring which position in the array I want
// to access from?
System.out.println("Diameter: " + circle.GetProperties());
System.out.println("Circumference: " + circle.GetProperties());
System.out.println("Area: " + circle.GetProperties());
}
}
}
When I input 1 for my radius, here is my output:
Diameter: [D@fefe3f
Circumference: [D@e61a35
Area: [D@c2b2f6
What am I doing wrong?