+ 2

Any one done?

Can any one please help me in shapes project in java

9th Jan 2023, 10:13 AM
GANJIKUNTA SHAMITHA
GANJIKUNTA SHAMITHA - avatar
9 Answers
+ 2
Can you please share your code? Copy and paste it into the code playground, then attach it here. Also, post what the task is.
9th Jan 2023, 10:15 AM
Ausgrindtube
Ausgrindtube - avatar
+ 2
Sure
9th Jan 2023, 10:16 AM
GANJIKUNTA SHAMITHA
GANJIKUNTA SHAMITHA - avatar
+ 2
import java.util.Scanner; import java.lang.Math.*; abstract class Shape { int width; abstract void area(); } //your code goes here 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(); } } ..... Above one that is my code but what's wrong with that can you please tell me once...
9th Jan 2023, 10:20 AM
GANJIKUNTA SHAMITHA
GANJIKUNTA SHAMITHA - avatar
+ 2
GANJIKUNTA SHAMITHA Declaration is important Square and Circle you haven't declared
11th Jan 2023, 8:59 AM
RšŸšŸ‡®šŸ‡³
RšŸšŸ‡®šŸ‡³ - avatar
+ 1
import java.util.Scanner; abstract class Shape { int width; abstract void area(); } //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(); } }
9th Jan 2023, 10:19 AM
GANJIKUNTA SHAMITHA
GANJIKUNTA SHAMITHA - avatar
+ 1
I have done this code but it's showing cannot find symbol
9th Jan 2023, 10:19 AM
GANJIKUNTA SHAMITHA
GANJIKUNTA SHAMITHA - avatar
+ 1
Try adding "this" to your constructor variables.
9th Jan 2023, 12:04 PM
Ausgrindtube
Ausgrindtube - avatar
+ 1
GANJIKUNTA SHAMITHA Try again testing the code. I think it works fine.. *There is no need to Math class import
9th Jan 2023, 12:21 PM
Jayakrishna šŸ‡®šŸ‡³
0
You are working on a graphical app, which includes multiple different shapes. The given code declares a base Shape class with an abstract area() method and a width attribute. You need to create two Shape subclasses, Square and Circle, which initialize the width attribute using their constructor, and define their area() methods. The area() for the Square class should output the area of the square (the square of the width), while for the Circle, it should output the area of the given circle (PI*width*width). The code in main creates two objects with the given user input and calls the area() methods. Sample Input: 5 2 Sample Output: 25 12.566370614359172 The area of the square is 5*5=25, while the area of the circle is PI*2*2=12.566370614359172
9th Jan 2023, 10:18 AM
GANJIKUNTA SHAMITHA
GANJIKUNTA SHAMITHA - avatar