Java Help


Limp Gawd
Feb 18, 2005
Alright heres the deal. Use to know some Java but its been a while and now its coming back to haunt me. BTW: I am aware that you guys dont give out answers for programs to students. Im looking for help, someone who can let me know what im doing wrong. So calm down before you jump down my throat.

I needed to write a circle class that has the following fields:
radius- a double
PI- a final double intitialized with the value 3.14159

Should have constructor, setRadius, getRadius, getArea, getDiameter, getcirumference.

Then write a program that demonstrates the Circle class by asking the user for the circles radius, creating a Circle object, and then reporting the circles area, diameter, and circumference.

This is what I got (after too much time, like I said, its been awhile)

As you can see, i thought this may of been correct since it does what I wanted, but i forgot that its all in one file. Its calling itself in its own program. I tried creating the two files, where I would place the methods in one, and call them in the other, but its not working at all. This method seems to work, but its not efficient according to my sources. Is there a simple way of converting this to a class and then a program? grr

Thanks guys

import java.util.Scanner;
import java.text.DecimalFormat;

public class practice
public static void main(String[] args)
double radius, // To hold a radius
area; // To hold an area
double diameter; // To hold a diameter
double circumference; // To hold a circumference
String inputLine; // To hold a line of input
char choice; // To hold the user's choice
final double PI = 3.14159;

// Create a Scanner object for keyboard input.
Scanner keyboard = new Scanner(;

// Create a DecimalFormat object for output formatting.
DecimalFormat formatter = new DecimalFormat("0.00");

// Process the data for one or more circles.
// Get the circle's radius.
System.out.print("Please enter the circle's radius: ");
radius = keyboard.nextDouble();

// Calculate and display the area.
area = Math.PI * radius * radius;
System.out.println("The area is " +

// Calculate and display the diameter.
diameter = radius * 2;
System.out.println("The diameter is " +

// Calculate and display the circumference.
circumference = 2 * Math.PI * radius;
System.out.println("The circumference is " +

// Repeat this?
System.out.print("Would you like to " +
"enter different values and try again? (Y or N) ");
keyboard.nextLine(); // Consume the remaining newline.
inputLine = keyboard.nextLine();
choice = inputLine.charAt(0); // Get the first char.

} while (Character.toUpperCase(choice) == 'Y');


Oct 25, 2006
Maybe this will help kick things off. Start with two files:
public class Circle {
    // Class implementation here
public class CircleTest {
    public static void main(String[] args) {
        // Test code that creates a Circle here


Nov 24, 2006
I'll be happy to help you but please put code around your code, I can't read it well like that, my eyes get lost.