0

problem in more on class lesson in sololearn

hi in the last project of more on classes on java my code doesn't pass test case 3, but it seems fine to me. can somebody explain why, please. this is my code: import java.util.Scanner; abstract class Shape { int width; abstract void area(); } class Square extends Shape { public Square(int width){ this.width=width; } public void area(){ System.out.println(width*width); } } class Circle extends Shape{ public Circle (int width){ this.width=width; } public void area(){ System.out.println(width*width*Math.PI); } } 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(); } }

1st Sep 2021, 9:04 AM
May Kaz
May Kaz - avatar
2 Answers
0
I don't know anything about it but i am assuming the inputs need to be integer only . In Circle class try Math.PI*width*width instead of width*width*Math.PI.
1st Sep 2021, 9:15 AM
Abhay
Abhay - avatar
0
Thanks a lot. That worked
1st Sep 2021, 10:23 AM
May Kaz
May Kaz - avatar