55 Code Project Shapes | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

55 Code Project Shapes

I have no idea what I am doing wrong, also I don't know how to use Math.PI so I used the numbers 3.14159 instead import java.util.Scanner; abstract class Shape { int width; abstract void area(); } //your code goes here class Square extends Shape { public void area(){ int Sq_answer = x*x; System.out.println(Sq_answer); } } class Circle extends Shape { public void area(){ Double Cir_answer = 3.14159*y*y; System.out.println(Cir_answer); } } 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(); } }

10th Dec 2022, 4:31 AM
Natanael
2 Answers
+ 2
In Java, you can use the constant Math.PI to get the value of π with more precision than using a hard-coded value like 3.14159. Double Cir_answer = Math.PI*y*y;
10th Dec 2022, 5:12 AM
Calviղ
Calviղ - avatar
0
Thanks so much, but this code is not working yet, I'm getting an error that it can not find the symbol and it's pointing to the y and x variables. Here is the only change I made to the code above: Double Cir_answer = Math.PI*y*y;
14th Dec 2022, 5:04 PM
Natanael