Menu

[Solved]Create Java Class Output Would Come Input X Y R 1 2 3 User Puts Number Input Type 1 Circle Q37254306

create java class

output would come out as this:

Input x,y,r

1 2 3 // user puts any number here

Input type -1: Circle | 2:triangle | 3:square | others:polygon

1//user selects number

Polygon’s area is 0.0

triangle area frac{3sqrt{3}times r^{2}}{4}

circle area pi r^{2}

square area 2r^{2}

here is the code that I’m going to use

class Point {
private int x;
private int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
public int getX() {
return this.x;
}
  
public int getY() {
return this.y;
}
}

class Polygon {
protected Point center;
   protected double radius;
   protected double area;

   public Polygon(Point cent, double r) {
       this.center = newPoint(cent.getX(), cent.getY());
       this.radius = r;
this.area = 0;

   }
  
   public Point getCenter() {
       return newPoint(this.center.getX(),
          this.center.getY());
   }
  
   public double getRadius() {
       return this.radius;
   }
  
   public void explain() {
       System.out.println(“This ispolygon.”);
       System.out.println(“Center : [” +center.getX() + “, ” + center.getY() + “]”);
       System.out.println(“Radius : ” +radius);
   }
public String toString() {
   return “Polygon’s area is ” + this.area;
   }
}

class Circle extends Polygon {
public Circle(Point p, double r) {
// create code
}
  
public void explain() {
// create code
}
}

class Triangle extends Polygon {
public Triangle(Point p, double r) {
// create code
}
  
public void explain() {
// create code
}
}

class Square extends Polygon {
public Square(Point p, double r) {
// create code
}
  
public void explain() {
// create code
}
}

class Main {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
       int x = 0, y = 0, type = 0;
       double r = 0;
       Polygon p;
      
       System.out.println(“Input x, y,r”);
       x = keyboard.nextInt();
       y = keyboard.nextInt();
       r = keyboard.nextDouble();
      
       System.out.println(“Input type – 1:circle | 2: triangle |
                      3: square| others: polygon”);
       type = keyboard.nextInt();
      
       // create code
       // Don’t use System.out.println athere.
       // System.out.println should beplaced on explain function.
      
       p.explain();
      
       keyboard.close();
}
}

We were unable to transcribe this imageWe were unable to transcribe this imageWe were unable to transcribe this imageWe were unable to transcribe this imageShow transcribed image text

Expert Answer


Answer to create java class output would come out as this: Input x,y,r 1 2 3 // user puts any number here Input type -1: Circle | … . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *