0

# Can somebody help me

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 https://code.sololearn.com/c379tkGDnY4P/?ref=app

15th Dec 2020, 8:24 AM
Alessandro
- 11
Hello. I solved it. Here it is: class Square extends Shape { Square(int x) { this.width = x; } void area() { //return x * x; System.out.println(width * width); } } class Circle extends Shape { Circle(int y){ this.width = y; } public void area(){ System.out.println(Math.PI*width*width); } }
19th Feb 2021, 7:48 AM
Panos
+ 52
import java.util.Scanner; abstract class Shape { int width; abstract void area(); } //your code goes here class Square extends Shape { public Square(int w){ width = w; } public void area(){ width = width*width; System.out.println(width); } } class Circle extends Shape { public Circle(int w){ width = w; } public void area() { double areaCircle = (double)Math.PI*(int)width*(int)width; System.out.println(areaCircle); } } 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 Feb 2021, 11:08 AM
AndrÃ¡s TimÃ¡r
+ 15
class Square extends Shape { Square(int x) { width = x; } 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); } } it's really worked
27th Feb 2021, 12:16 PM
Shohruh Berdikulov
+ 6
//vote me, my code is work import java.util.Scanner; abstract class Shape { int width; abstract void area(); } //your code goes here class Square extends Shape{ Square(int x){ this.width = x; } @Override public void area(){ System.out.println(width * width); } } class Circle extends Shape{ Circle(int y){ this.width = y; } @Override public void area(){ System.out.println(Math.PI * width * width); } } public class Main { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int y = sc.nextInt(); sc.close(); Square a = new Square(x); Circle b = new Circle(y); a.area(); b.area(); } }
1st Feb 2022, 6:38 PM
Avrian Shandy
+ 4
This is working! import java.util.Scanner; abstract class Shape { int width; abstract void area(); } //your code goes here class Square extends Shape { public Square(int w){ width = w; } public void area(){ width = width*width; System.out.println(width); } } class Circle extends Shape { public Circle(int w){ width = w; } public void area() { double areaCircle = (double)Math.PI*(int)width*(int)width; System.out.println(areaCircle); } } 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(); } }
23rd Mar 2021, 5:00 PM
Tejashree Suryawanshi
+ 3
import java.util.Scanner; //Please Subscribe to My Youtube Channel //Channel Name: Fazal Tuts4U abstract class Shape { int width; abstract void area(); } class Square extends Shape{ public Square(int x) { this.width = x; } @Override void area() { width = width*width; System.out.println(width); } } class Circle extends Shape{ public Circle(int y) { this.width = y; } @Override void area() { double areaCircle = (double)Math.PI*(int)width*(int)width; System.out.println(areaCircle); } } 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(); } }
4th Sep 2021, 3:14 PM
Fazal Haroon
+ 2
import java.util.Scanner; abstract class Shape { int width; abstract void area(); } //your code goes here class Square extends Shape { public Square(int w){ width = w; } public void area(){ width = width*width; System.out.println(width); } } class Circle extends Shape { public Circle(int w){ width = w; } public void area() { double areaCircle = (double)Math.PI*(int)width*(int)width; System.out.println(areaCircle); } } 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(); } } Good Luck
25th Dec 2021, 11:31 AM
+ 1
/*w and wi is very important to initialize*/ import java.util.Scanner; abstract class Shape { int wi,w; abstract void area(); } //your code goes here class Circle extends Shape{ Circle(int a){ w = a; } void area(){ System.out.println(Math.PI*w*w); } } class Square extends Shape{ Square(int b){ wi = b; } void area(){ System.out.println(wi*wi); } } 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(); } }
12th Jun 2021, 9:02 AM
Parmar Darshil
+ 1
It's working import java.util.Scanner; public abstract class Shape { abstract void area(int width); } public class Square extends Shape { void area(int width) { System.out.println(width * width); } } public class Circle extends Shape { void area(int width) { System.out.println(Math.PI * width * width); } } public class Program { public static void main(String[] args) { // TODO Auto-generated method stub Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int y = sc.nextInt(); Shape a = new Square(); Shape b = new Circle(); a.area(x); b.area(y); } }
7th Feb 2022, 11:24 AM
0
Adama Diaby im trying to learn java and im at the section "more in classes" and at the end you have to complete a Project, in this case im doing "Shape". When you think you have complete it you can run it and it shows you if you have done well showing some of the possibile solutions. But not all the solutions are shown because you can print them and complete it without learning the lessons. So i dont know were im doing wrong
15th Dec 2020, 7:03 PM
Alessandro
0
This project test cases had given me a migraine
22nd Feb 2021, 5:00 PM
Kiprotich Kincaid
0
Panos thank you so much!
27th Feb 2021, 1:00 PM
Alessandro
0
import java.util.Scanner; abstract class Shape { int width; abstract void area(); } //your code goes here class Square extends Shape{ Square(int x){ this.width = x; } @Override public void area(){ System.out.println(width * width); } } class Circle extends Shape{ Circle(int y){ this.width = y; } @Override public void area(){ System.out.println(Math.PI * width * width); } } public class Main { public static void main(String[ ] args) { Scanner sc = new Scanner(System.in); int x = sc.nextInt(); int y = sc.nextInt(); sc.close(); Square a = new Square(x); Circle b = new Circle(y); a.area(); b.area(); } }
16th Jul 2021, 7:59 PM
Mohammed Hussein Ahmed Farag
0
import java.util.Scanner; abstract class Shape { int width; abstract void area(); } //your code goes here class Square extends Shape { public Square(int w){ width = w; } public void area(){ width = width*width; System.out.println(width); } } class Circle extends Shape { public Circle(int w){ width = w; } public void area() { double areaCircle = (double)Math.PI*(int)width*(int)width; System.out.println(areaCircle); } } 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(); } }
2nd Oct 2021, 9:42 AM
Hariom Kumar
0
import java.util.Scanner; abstract class Shape { int width; abstract void area(); } //your code goes here class Square extends Shape { public Square(int w){ width = w; } public void area(){ width = width*width; System.out.println(width); } } class Circle extends Shape { public Circle(int w){ width = w; } public void area() { double areaCircle = (double)Math.PI*(int)width*(int)width; System.out.println(areaCircle); } } 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(); } } Worked :)
23rd Oct 2021, 6:08 PM
0
class Square extends Shape { Square(int x) { width = x; } 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); } }
15th Nov 2021, 6:11 AM
Nabila Muftia Ma'ruf Kartono
0
#trythis import java.util.Scanner; abstract class Shape { int width; abstract void area(); } //your code goes here class Square extends Shape { public Square(int w){ width = w; } public void area(){ width = width*width; System.out.println(width); } } class Circle extends Shape { public Circle(int w){ width = w; } public void area() { double areaCircle = (double)Math.PI*(int)width*(int)width; System.out.println(areaCircle); } } 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(); } }
17th Dec 2021, 9:38 AM
Mirmahmud Ilyosov
0
import java.util.Scanner; abstract class Shape { int width; abstract void area(); } //your code goes here class Square extends Shape { public Square(int w){ width = w; } public void area(){ width = width*width; System.out.println(width); } } class Circle extends Shape { public Circle(int w){ width = w; } public void area() { double areaCircle = (double)Math.PI*(int)width*(int)width; System.out.println(areaCircle); } } 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(); } }
1st Jan 2022, 8:38 AM
M.I.M.Aqueel
0
#include <iostream> using namespace std; class Number { private: int num; public: Number(int n) { num = n; } //complete the method int square() const{ int n = num; n*=n; return n; }; }; int main() { int x; cin >> x; const Number myNum(x); cout << myNum.square(); } Good Luck
25th Jan 2022, 5:59 PM