Java - Shapes [Learning project] | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

Java - Shapes [Learning project]

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 Use the Math.PI constant for the area calculation of the circle. ________ My code: https://code.sololearn.com/cwU4Fs2BUrF6/?ref=app _______ Code passed all test cases except the third. The input data for 3rd test case is hidden. Please, help me.

21st May 2021, 10:33 AM
Suhayl Qodirov
Suhayl Qodirov - avatar
3 Answers
+ 4
Suhayl Qodirov Just change position of Math.PI Math.PI * width * width
21st May 2021, 11:47 AM
A͢J
A͢J - avatar
+ 5
You can see my code. It works for me https://code.sololearn.com/cFYcXXbLmZmK/?ref=app
22nd May 2021, 6:07 PM
Sasmita Dwi Novitasari
Sasmita Dwi Novitasari - avatar
+ 2
Thank you all :)
23rd May 2021, 2:51 AM
Suhayl Qodirov
Suhayl Qodirov - avatar