Hello everybody,
Its great to see there's a community of people who are willing to help out. If anyone could solve my dilemma that would be awesome because my Computer Science professor is a worthless poop head. With that said, I feel like most of this is right yet the output is not showing up correctly. The main problem being that the radius outputs properly but none of the calculations of area, circumference, or diameter do.
Thank you in advance!
import java.text.DecimalFormat; import javax.swing.JOptionPane; public class Circle { public static void main(String[] args) { CircleRadius radius = new CircleRadius(); CircleRadius area = new CircleRadius(); CircleRadius circumference = new CircleRadius (); CircleRadius diameter = new CircleRadius(); String input; double r; DecimalFormat twodigits = new DecimalFormat("#.00"); input = JOptionPane.showInputDialog("Please enter the radius of the circle"); r = Double.parseDouble(input); radius.set_radius(r); area.get_Area(); diameter.get_Diameter(); circumference.get_Circumference(); JOptionPane.showMessageDialog(null, "The radius of the circle is " + twodigits.format(radius.get_radius())); JOptionPane.showMessageDialog(null, "The area of the circle is " + twodigits.format(area.get_Area())); JOptionPane.showMessageDialog(null, "The diameter of the circle is " + twodigits.format(diameter.get_Diameter())); JOptionPane.showMessageDialog(null, "The circumference of the circle is " + twodigits.format(circumference.get_Circumference())); } }
public class CircleRadius { private double radius; public double PI = 3.14159; public CircleRadius() { radius = 0.0; } public CircleRadius(double r) { radius = r; } public double get_radius() { return radius; } public void set_radius(double r){ radius = r; } public double get_Area() { return PI * radius * radius; } public double get_Diameter() { return radius * 2; } public double get_Circumference() { return 2 * PI * radius; } }