+ 1
What is the solution of Shapes project in Java tutorial?
Can anyone debug it, the third case is always coming wrong and hidden
10 Respostas
+ 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();
}
}
+ 2
Thanks đđ it worked
+ 2
Hello
In the problem tells two Shape subclasses
+ 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
+ 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.
+ 1
@Dharmi Sri your variables area1 and area2 don't have their types declared.
+ 1
Thanks, Miss.
+ 1
Had the same problem, mycode worked when I switched the Math.PI and width variable in the area method
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
- 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));
}
}