0

I am busy working on code project for "More on Classes" and can't see what is wrong with my code!

I Solved most of the test cases but the hidden Test Case 3 is failing me and I don't know why. Here is my code https://code.sololearn.com/cec8LiASslJu import java.util.Scanner; abstract class Shape { protected int width; abstract void area(); } //your code goes here public class Square extends Shape{ public Square(int w){ width = w; } public void area(){ System.out.println(width*width); } } public class Circle extends Shape{ public Circle(int w){ width = w; } 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 Mar 2022, 5:45 AM
TeraGeek
TeraGeek - avatar
1 Answer
+ 2
Try changing the order of your multiplication for the area of a circle to Math.PI*width*width For whatever reason this module project is picky about that and often leads to this issue, but your code otherwise appears correct.
1st Mar 2022, 6:38 AM
ChaoticDawg
ChaoticDawg - avatar