+ 5
Hello everyone. I need help. I write a program it can't answer for all inputs and I can't solve the problem
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 And it is my solve 👇 https://code.sololearn.com/cOnWr5xJswhA/?ref=app
7 Respuestas
+ 7
Thanks for your help
I find my problem and now it is working for all number 🤩🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏🙏
+ 7
Benjamin Jürgens thank
+ 5
Abol thanks again
+ 3
The problem is not in your side!
Just reverse order for area of circle to pi*width*width and it passes all tests.
The challenge doesn't do proper comparison of floating point numbers. A different order of operations leads to slightly different rounding. So your numbers are off at the last digit probably.
Differences can also arise from the different type of variables, combined with the order of calculation
+ 3
This article describes the problem in more detail:
https://howtodoinjava.com/java-examples/correctly-compare-float-double/
Also Java has a solution: java.lang.Float.compare()