0

Java shape class not mark passed

My programme all test cases passed. But its not marking as a passed the test. Showing try again. Please any suggestions import java.util.Scanner; abstract class Shape { int width; public abstract void area(); } //your code goes here class Circle extends Shape{ Circle (int width ){this.width =width;} public void area (){ double area = width * width * Math.PI; System.out.println(area ); } } class Square extends Shape{ Square (int width){ this.width =width; } public void area(){ int area = width * width; System .out.println(area); } } 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(); } }

20th Dec 2020, 1:33 PM
Gayan Suranga
Gayan Suranga - avatar
4 Respostas
+ 2
Gayan Suranga , maybe it is accuracy problem. I tried your code and changed the order for calculation of the circle's area this way => double area = Math.PI * width * width. All tests passed.
20th Dec 2020, 2:06 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
+ 1
Yes you are correct problem is an order of the Math.PI function
20th Dec 2020, 2:11 PM
Gayan Suranga
Gayan Suranga - avatar
+ 1
Hey but why the order of writing terms for multiplication matters?
20th Dec 2020, 5:36 PM
Shubham Bawner
Shubham Bawner - avatar
0
Shubham Bawner i think java first priority is for package if not problrm is sololearn compiler
21st Dec 2020, 2:01 AM
Gayan Suranga
Gayan Suranga - avatar