0

Help with 55 Code Project

Can someone help me figure out what I'm doing wrong? I'm supposed to tell the program to calculate the area of a square and a circle, I did that but my code doesn't seem to be working. Here is the code I have so far: import java.util.Scanner; abstract class Shape { int width; abstract void area(); } //your code goes here class Square extends Shape { public void area() { a.area = int x*int x; return area; } } class Square extends Shape { b.area = Math.PI(3.14*2*2); return area; } 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(); } }

29th Sep 2022, 10:59 PM
Taylor Frye
1 Answer
+ 1
class Square extends Shape{ public Square(int w) { width=w; }; public void area() { System.out.println(width*width); }; } class Circle extends Shape{ public Circle(int w) { width=w; }; public void area() { System.out.println(Math.PI*width*width); }; }
29th Sep 2022, 11:55 PM
SoloProg
SoloProg - avatar