Saturday, April 12, 2014

Circle detais with JOptionPane


import javax.swing.JOptionPane;
public class Circle{
private double radius, diameter, circleArea, circumference;
public static final String CN="Circle";
Circle(double radius){
this.radius=radius;
computeDiameter();
computeCircumference();
}
void computeDiameter(){
diameter=2*radius;
}
void computeCicleArea(){
circleArea=Math.PI*radius*radius;
}
void computeCircumference(){
circumference=2*Math.PI*radius;
}
public double getRadius(){
return radius;
}
public double getDiameter(){
return diameter;
}
public double getCircleArea(){
return circleArea;
}
public double getCircumference(){
return circumference;
}
public void setRadius(double newR){
radius= newR;
computeDiameter();
computeCicleArea();
computeCircumference();
}
public String toString(){
return "Circle's radius is "+radius+"\n Circumference is "+circumference + "\n Area is "+circleArea;
}
public static void main(String args[]){
Circle c1=new Circle(7.0);
Circle c2=new Circle(0.0);
JOptionPane.showMessageDialog(null, c2.toString(), "Circle Details", 1);
c2.setRadius(11.3);
String cDetails2=""+c2;
JOptionPane.showMessageDialog(null, c2.toString(), "Circle Details", 1);
JOptionPane.showMessageDialog(null, "=>"+c1, "Circle Details", 1);
}
}