My code all works fine and I have a user defined class called Circle. When I type "y" or "Y" it will not re run the program.
import java.util.Scanner; public class CircleTest { public static void main (String [] args) { String choice; do{ Circle crcl1 = new Circle(5.5); Scanner scan = new Scanner(System.in); System.out.println("Please enter the radius of the circle: "); crcl1.setRadius(scan.nextDouble()); System.out.println("\nThe radius of the circle is " + crcl1.getRadius()); System.out.println("\nThe area of the circle is " + crcl1.getArea()); System.out.println("\nThe perimeter of the circle is " + crcl1.getPerimeter()); System.out.println("\n\nWould you like to perform another calculation? <Y for yes, N for no> "); choice = scan.next(); }while(choice == "y" || choice == "Y"); } }
This is my user defined class:
public class Circle { private double radius; private double area; private double perimeter; double PI = 3.14159; public Circle (double pRadius) { radius = pRadius; } public double getRadius() { return radius; } public double setRadius(double newRadius) { if(newRadius<0) { System.out.println("Radius cannot be negative."); } else { radius = newRadius; } return radius; } public double getArea() { area = PI * radius * radius; return area; } public double getPerimeter() { perimeter = 2 * PI * radius; return perimeter; } }