What is the solution of Shapes project in Java tutorial? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the solution of Shapes project in Java tutorial?

Can anyone debug it, the third case is always coming wrong and hidden

4th Mar 2021, 9:25 PM
anamta ali
anamta ali - avatar
10 Answers
+ 7
Hey there, I'm Ashwin. When I tried running your code, it was showing some error(idk what happened). Maybe this could help someone. import java.util.Scanner; abstract class Shape { int width; abstract void area(); } //your code goes here class Square extends Shape { Square (int wdth) { this.width = wdth; } public void area() { System.out.println(this.width*this.width); } } class Circle extends Shape { Circle (int wdth ) { this.width = wdth; } public void area () { System.out.println( Math.PI*this.width*this.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(); } }
26th Sep 2021, 8:55 AM
Ashwin Kumar
Ashwin Kumar - avatar
+ 2
Thanks 😊😊 it worked
5th Mar 2021, 8:12 AM
anamta ali
anamta ali - avatar
+ 2
Hello In the problem tells two Shape subclasses
19th Apr 2021, 8:37 PM
Joel Cabatay Supleo
+ 2
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(); } }//Easy to understand
24th Jun 2021, 3:47 PM
Dharmi Sri
Dharmi Sri - avatar
+ 1
Getting bizarre results. Both of the visible test cases are always correct, however the first and last of the hidden cases are often deemed incorrect. Even when my code was undoubtedly correct and exactly like that of Sandeep Kushwaha's solution at the very top. I believe the hidden test cases are randomized, so I don't understand why I'm not allowed to see them.
7th Mar 2022, 5:13 PM
Ves Sprole
Ves Sprole - avatar
+ 1
@Dharmi Sri your variables area1 and area2 don't have their types declared.
7th Mar 2022, 5:15 PM
Ves Sprole
Ves Sprole - avatar
+ 1
Thanks, Miss.
16th Aug 2022, 2:39 AM
Isidro J Gallardo Navarro
Isidro J Gallardo Navarro - avatar
+ 1
Had the same problem, mycode worked when I switched the Math.PI and width variable in the area method
21st Oct 2022, 7:46 PM
Ahsan Saleem
Ahsan Saleem - avatar
0
You can add here links or paste code links.. Use AreaCircle = Math.PI * y * y ; edit: post your update code if not solved..anamta ali
4th Mar 2021, 9:36 PM
Jayakrishna 🇮🇳
- 1
import java.util.Scanner; //your code goes here public class Program { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); System.out.print(Converter.toBinary(x)); } }
8th Jan 2022, 5:53 AM
Kundariya jay