- 1

My test case 1 is wrong please help my output is 1st is 144 and 2nd 15.7 but the expected output should be 144 and 78.5.imabegin

import java.util.Scanner; abstract class Shape { int width; abstract void area(); } //your code goes here class Square extends Shape{ public int area2; public Square(int x) { width=x; } public void area() { area2=width*width; System.out.println(area2); } } class Circle extends Shape{ public double area1; public Circle(int y) { width=y; } public void area() { area1=Math.PI*width; System.out.println(area1); } } public class Program { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int y = sc.nextInt(); Square a = new Square(x); Circle b = new Circle(y); a.area(); b.area(); } }

15th Sep 2022, 10:18 AM
Mark Angelo Alarcon
Mark Angelo Alarcon - avatar
4 ответов
+ 2
The formula for the area of the circle is not correct.
15th Sep 2022, 10:21 AM
Lisa
Lisa - avatar
+ 2
In the circle class, it should be: MathPI*width*width
15th Sep 2022, 10:23 AM
Jan
Jan - avatar
+ 1
Thank you so much. I finished it
15th Sep 2022, 10:53 AM
Mark Angelo Alarcon
Mark Angelo Alarcon - avatar
0
Why is it still wrong 😭
15th Sep 2022, 10:47 AM
Mark Angelo Alarcon
Mark Angelo Alarcon - avatar