0

please help me in java

Write a Java class named circle which contains: Instance variables: Radius of type double. Color of type String. Overloaded constructors: Default constructor "no argument". Constrictor which takes two arguments (a double argument for radius, a string argument for color). a public method getArea() which return the area of the circle based on the radius.

16th May 2022, 9:40 AM
SOSO Rr
17 ответов
+ 4
import java.util.Scanner; class Circle{ double radius; String color; Circle(){ radius=0; color="";} Circle(double radius, String color){ this.radius= radius; this.color= color;} double getArea(){ return 3.14 *radius* radius;} class HelloWorld{ public static void main (String[] args) { Scanner scan=new Scanner(System.in); Circle circle=new Circle (5.1,"green"); System.out.println(circle.getArea()); }}
16th May 2022, 9:40 AM
SOSO Rr
+ 4
Make the relevant attributes private. Then write set and get methods. get methods return the attribute value, set methods return void and take the new value as parameter.
16th May 2022, 11:21 AM
Lisa
Lisa - avatar
+ 3
You can link your code if you put it on sololearn playground: Go to Code/Create section, click +, select the programming language, insert your code and save. Come back to this thread, click +, Insert Code, sort for My Code Bits, select your code. You can increase the chance that somebody helps by properly indenting your code.
16th May 2022, 9:48 AM
Lisa
Lisa - avatar
+ 2
Setters and getters and constructors will be explained in the sololearn Java course. You can re-read the lessons as often as you like. If you need help with a code, please link this code as described above.
16th May 2022, 11:11 AM
Lisa
Lisa - avatar
+ 1
what help you need? save code link ny saving it. Is there any problem with code? You are not using scanner object.. Do you don't need? SOSO Rr By the way, your first class Circle is *unclosed*
16th May 2022, 9:52 AM
Jayakrishna 🇮🇳
+ 1
🙁You are missing a } for class Circle Add one } before class HelloWorld{..
16th May 2022, 10:05 AM
Jayakrishna 🇮🇳
+ 1
When printing decimals, you should use "System.out.printf("%.2f, ...) to format numbers to 2 decimal places. It would also be nice to have getters (ones that return instance variables) and setters(changing the variables) for extra security.
17th May 2022, 2:57 AM
HydroShock
HydroShock - avatar
0
yes there is no output
16th May 2022, 9:57 AM
SOSO Rr
0
the output i think should be 81.6713999999
16th May 2022, 9:58 AM
SOSO Rr
0
I really tried to do my homework but it was wrong and I have to send it in tomorrow please i need the correct code 😔🥺
16th May 2022, 10:03 AM
SOSO Rr
0
thank youuuuu♥️♥️♥️♥️♥️♥️♥️
16th May 2022, 10:07 AM
SOSO Rr
0
sorry but if i used set,get and Variables should be private, the constructor should be public. How does the code become?🥺🥺
16th May 2022, 11:08 AM
SOSO Rr
0
I did not understand the lessons, can you write the code here.
16th May 2022, 2:48 PM
SOSO Rr
0
سلام
17th May 2022, 9:02 PM
jojo raeisi
0
hi
17th May 2022, 9:02 PM
jojo raeisi
- 1
You need a program to convert days to seconds. The given code takes the amount of days as input. Complete the code to convert it to seconds and output the result. Sample Input: 12 Sample Output: 1036800
18th May 2022, 1:07 AM
ABHISHEK AJITKUMAR WAYKOS