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???
13 Antworten
+ 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.
0
what is the error ?
0
Invalid method declaration;
Return type require.
0
My code:
Class Squared extends Shape{
Public Sqared(int x){
Width =x;
}
abstract void area(){
Int r = width*width;
System.out.println(r);
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);
}
}
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
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();
}
}
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!!!
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;
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
0
Thanks for you help…
- 1
I have tried everything possible and it keeps giving error in the 3rd test. I do not know what else to do