0

How solve shapes project in Java

Please help

16th Jun 2021, 5:49 AM
Titanus Gojira
Titanus Gojira - avatar
7 Respuestas
+ 2
By posting your attempt
16th Jun 2021, 5:49 AM
Atul [Inactive]
+ 2
Rostislav Khalilov better if we guide him upto a certain extent and then give the answer if he is. Unable to solve
16th Jun 2021, 6:49 AM
Atul [Inactive]
+ 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(); } }
16th Jun 2021, 6:07 AM
Titanus Gojira
Titanus Gojira - avatar
+ 1
Titanus Gojira You have not used constructors
16th Jun 2021, 6:49 AM
Atul [Inactive]
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(); } }
16th Jun 2021, 6:20 AM
SammE
SammE - avatar
0
Thanks Atul for your guide
16th Jun 2021, 1:08 PM
Titanus Gojira
Titanus Gojira - avatar
0
Titanus Gojira my pleasure
16th Jun 2021, 1:34 PM
Atul [Inactive]