View Single Post
Old 11-30-2012, 08:05 PM   PM User | #1
CodyJava
New Coder

 
Join Date: Sep 2012
Posts: 25
Thanks: 21
Thanked 0 Times in 0 Posts
CodyJava is an unknown quantity at this point
Need turning user input into an object

I need to ask a user for the radius of a circle. Which will then be turned into an object that i can use in a different class to find different measurements. My question is how do i set the user input to an object. Also how do I refernce back to the class to print out those values. Thanks.


Code:
public class Circle {
    double radius;
    final double PI = 3.14159;
    
    Circle(double newradius){
        newradius = radius;
    }
    Circle(){
        radius = 0.0;
    }
    void setRadius(double inputradius){
        radius = inputradius;
    }
    double getRadius(){
        return radius;
    }
    
    double getArea(){
       return PI * radius * radius;
    }
    
   double getDiameter(){
       return radius * 2;
    }
   double getCircumference(){
       return 2 * PI * radius;
   }
}
Code:
import java.util.Scanner;
public class CircleTester {
    public static void main(String [] args){
       
        Scanner scan = new Scanner(System.in);
        
        System.out.println("What is the radius of the circle");
        
        
        System.out.println("The circle's area is ");
        
        System.out.println("The circle's diameter is ");
        
        System.out.println("The circumference is ");
    }
}
Thanks again.
CodyJava is offline   Reply With Quote