What's new

Java Java - Hirap naman

Status
Not open for further replies.

Sanji Ken

Eternal Poster
Joined
Aug 10, 2016
Posts
841
Reaction
140
Points
262
Ano po ang mali?saan ako nagkamali?

Java:
import java.util.Scanner;



public class Circle implements Shape {

  private double radius;

  private double xc;

  private double yc;

  public Circle(double radius, double xc, double yc) {

    this.radius = radius;

    this.xc = xc;

    this.yc = yc;

  }



  public double area() {

    return Math.PI * radius * radius;

  }

  public boolean contains(double x, double y) {

    double distance = Math.sqrt((x - xc) * (x - xc) + (y - yc) * (y - yc));

    return distance <= radius;

  }

  public static void main(String[] args) {

    Scanner scanner = new Scanner(System.in);



    System.out.print("Enter the radius of the circle: ");

    double radius = scanner.nextDouble();



    System.out.print("Enter the x coordinate of the center of the circle: ");

    double xc = scanner.nextDouble();



    System.out.print("Enter the y coordinate of the center of the circle: ");

    double yc = scanner.nextDouble();



    Circle circle = new Circle(radius, xc, yc);

    System.out.println("Area of the circle: " + circle.area());



    System.out.print("Enter a point to check if it is within the circle (enter x and y coordinates separated by a space): ");

    double x = scanner.nextDouble();

    double y = scanner.nextDouble();



    if (circle.contains(x, y)) {

      System.out.println("The point (" + x + ", " + y + ") is within the circle.");



    } else {



      System.out.println("The point (" + x + ", " + y + ") is not within the circle.");



    }

  }

}
 
Dahil incomplete question, AI nalang tinanong ko.
Eto daw problems kaya may error:

1671283663518.png


For more info dito ka mag ask:

You do not have permission to view the full content of this post. Log in or register now.
 

Attachments

Status
Not open for further replies.

Similar threads

Back
Top