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 Answerimport 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()); }}
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.
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.
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.
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*
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.
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 😔🥺
sorry but if i used set,get and Variables should be private, the constructor should be public. How does the code become?🥺🥺
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