Why does Sololearn not accept this? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Why does Sololearn not accept this?

Answered; thank you! Hi! I'm trying to complete a task for the solo learn java course (specifically the one about abstract classes called "Shape", however every time I run my program, all the test cases are correct except for No. 3 (a hidden test case). Please could you help by suggesting a bug fix in the code below? Thanks! (the bug is not inputting a double value and changing it to an int, I have tried this fix and it did not work.) import java.util.Scanner; abstract class Shape { int width; abstract void area(); } //your code goes here class Circle extends Shape{ Circle(int x){ width = x; } public void area(){ System.out.println(width*width*Math.PI); } } class Square extends Shape{ Square(int y){ width = y; } public void area(){ System.out.println(width*width); } } public class ProgramforSolo { 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(); } }

22nd Jun 2022, 3:44 PM
Michael
1 Answer
+ 2
Use Math.PI * width * width Instead of width * width * Math.PI (There you get slite difference in result)
22nd Jun 2022, 3:53 PM
Jayakrishna 🇮🇳