0

Problema en el ejercicio de Java “Formas”

Estoy realizando el ejercicio de formas en Java. La verdad que trata de métodos y clases abstractas… El problema es que ejecuto mi código en Eclipse (IDE) y todo correcto. Lo hago en la App , y da error en la compilación… Hay alguien que realizará este ejercicio???

17th Aug 2021, 3:47 PM
Daniel
Daniel - avatar
13 Respuestas
+ 1
After looking at the codes in Sololearn; I saw a colleague build an inner class and a constructor on the abstract class ... that was what I was missing.
19th Aug 2021, 2:08 PM
Daniel
Daniel - avatar
0
what is the error ?
17th Aug 2021, 6:11 PM
zemiak
0
Invalid method declaration; Return type require.
17th Aug 2021, 8:30 PM
Daniel
Daniel - avatar
0
My code: Class Squared extends Shape{ Public Sqared(int x){ Width =x; } abstract void area(){ Int r = width*width; System.out.println(r);
17th Aug 2021, 8:34 PM
Daniel
Daniel - avatar
0
Class Circle extends Shape{ Public Circle(int y){ Width=y; } abstract void area(){ double t = Math.PI * Math.pow(width,2); System.out.println(t); } }
17th Aug 2021, 8:37 PM
Daniel
Daniel - avatar
0
there are some basic bugs, use correct lower and upper case in used statements and names change Class to class add two }} after Squared class rename class Squared to Square (main() uses Square here) also rename constructor Sqared to Square (there is also missing u) change Public to public (in both constructors) rename Width to width (in both constructors) in Square rename Int to int ▪︎you have implemented area() method so now it is not abstract delete abstract in Square and Circle but I can't simulate your error
18th Aug 2021, 4:15 AM
zemiak
0
import java.util.Scanner; abstract class Shape { int width; abstract void area(); } //tu código va aquí class Square extends Shape{ public Square(int x){ width= x; } void area(){ int r = width *width; System.out.println(r); } private int width; } class Circle extends Shape{ public Circle(int y){ width=y; } void area(){ double re= Math.PI *(width *width); System.out.println(re); } private int width; } 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(); } }
18th Aug 2021, 11:06 PM
Daniel
Daniel - avatar
0
When I do the verification test, everything is OK except for case 3. I leave you the code that I have been implementing. I NEED HELP PLEASE!!!
18th Aug 2021, 11:07 PM
Daniel
Daniel - avatar
0
code is ok but Sololearn checks something concrete in code (it is bug in test) - usually problem is here: delete ( ) in double re= Math.PI *(width *width); also you can try - this line can be deleted (2x), because is inherited from Shape private int width; - area() can be public - in constructor width=y; can be with this. this.width=y;
19th Aug 2021, 3:33 AM
zemiak
0
compare your code with others Sololearn tab for codes { } there search shape select java (right up corner) use compare tools like https://www.diffnow.com/compare-clips or post new question perhaps expression In area() is expected direct in System.out.println( here ); or classes are expected as public
19th Aug 2021, 7:58 AM
zemiak
0
Thanks for you help…
19th Aug 2021, 2:09 PM
Daniel
Daniel - avatar
- 1
I have tried everything possible and it keeps giving error in the 3rd test. I do not know what else to do
19th Aug 2021, 4:23 AM
Daniel
Daniel - avatar