+ 3

Problem with code : Shapes in Java lesson

I can resolve the problem. I got the output expected but it says that the hidden test case 3 is not the same as my result. Help

28th Jan 2021, 1:27 PM
Zovelosoa Jph
Zovelosoa Jph - avatar
8 Respostas
+ 5
Post your code here so that we can help ...
28th Jan 2021, 1:31 PM
Alphin K Sajan
Alphin K Sajan - avatar
+ 5
May be u missing something read instructions properly and mention your code here so it will be easy for community to debug your code
28th Jan 2021, 1:38 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 2
I fixed it. For some reason just writing: this.width * Math.PI * this.width Instead of : this.width*this.width * Math.PI And adding @Override before the area method fixed it lol
15th Mar 2021, 3:11 PM
Abdelmoumene Dhia Deroueche
Abdelmoumene Dhia Deroueche - avatar
+ 1
import java.util.Scanner; abstract class Shape { int width; abstract void area(); } //your code goes here public class Program { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt();//almacena datos para Square int y = sc.nextInt();// almacena datos para circle Square a = new Square(x); //debe generar el area del cuadrado (de la anchura) Circle b = new Circle(y);//area del circulo dado a.area(); b.area(); } } public class Square extends Shape{ public Square(int width){ this.width=width; } @Override public void area(){ System.out.println(this.width = this.width* this.width); } } public class Circle extends Shape{ public Circle(int a){ this.width=a; } @Override public void area(){ System.out.println(Math.PI*(double) width*width); } }
20th Jun 2021, 1:05 AM
Margarito
Margarito - avatar
28th Jan 2021, 7:45 PM
Zovelosoa Jph
Zovelosoa Jph - avatar
0
Same here. Did you solve it?
15th Mar 2021, 3:00 PM
Abdelmoumene Dhia Deroueche
Abdelmoumene Dhia Deroueche - avatar
0
System.out.println(Math.PI* (double)width*width // * Math.PI // not at the end );
16th Apr 2021, 8:20 AM
Dmitry Lezin
Dmitry Lezin - avatar
0
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:47 PM
Dharmi Sri
Dharmi Sri - avatar