0
How solve shapes project in Java
Please help
7 ответов
+ 2
By posting your attempt
+ 2
Rostislav Khalilov better if we guide him upto a certain extent and then give the answer if he is. Unable to solve
+ 1
import java.util.Scanner;
abstract class Shape {
int width;
abstract void area();
class Square{
System.out.println(width*width);
}
class Circle{
System.out.println(Math.PI*width*width);
}
}
//your code goes here
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();
}
}
+ 1
Titanus Gojira You have not used constructors
0
import java.util.Scanner;
abstract class Shape {
int width;
abstract void area();
}
//your code goes here
class Square extends Shape {
Square (int x) {
width = x;
}
public void area() {
System.out.println(width*width);
}
}
class Circle extends Shape {
Circle (int y) {
width = y;
}
public void area() {
System.out.println(Math.PI*width*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
Thanks Atul for your guide
0
Titanus Gojira my pleasure