please help me in java | Sololearn: Learn to code for FREE!

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.

5/16/2022 9:40:47 AM

SOSO Rr

17 Answers

New Answer

+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()); }}

+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.

+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.

+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.

+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*

+1

🙁You are missing a } for class Circle Add one } before class HelloWorld{..

+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.

0

yes there is no output

0

the output i think should be 81.6713999999

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 😔🥺

0

thank youuuuu♥️♥️♥️♥️♥️♥️♥️

0

sorry but if i used set,get and Variables should be private, the constructor should be public. How does the code become?🥺🥺

0

https://code.sololearn.com/ck0ZE8GZ7XKn/?ref=app

0

I did not understand the lessons, can you write the code here.

0

سلام

0

-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