0

Shapes problem in java

So this is my code: import java.util.Scanner; abstract class Shape { int width; abstract void area(); double k=Math.PI; double arie; } //your code goes here class Square extends Shape { Square(int x){ this.width=x; } public void area(){ int arie2=width*width; System.out.println(arie2); } } class Circle extends Shape { Circle(int x){ this.width=x; } public void area(){ arie= width*width*k; System.out.println( arie); } } 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(); } } I cant figure out why it doesnt pass all the tests ( it doesnt pass a locked one ,test case 3) Any solutions?

21st Feb 2021, 8:13 PM
Alex Sirbu
Alex Sirbu - avatar
4 Antworten
+ 3
import java.util.Scanner; abstract class Shape { int width; abstract void area(); } 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*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(); } }
24th Jun 2021, 3:45 PM
Dharmi Sri
Dharmi Sri - avatar
+ 1
System.out.println(Math.PI* (double)width*width // * Math.PI // not at the end );
16th Apr 2021, 8:18 AM
Dmitry Lezin
Dmitry Lezin - avatar
21st Feb 2021, 8:26 PM
Avinesh
Avinesh - avatar
22nd Feb 2021, 11:10 PM
❤️😍Prerana😍❤️
❤️😍Prerana😍❤️ - avatar