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.
17 Respostas
+ 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
I did not understand the lessons, can you write the code here.
0
Ų³ŁŲ§Ł
0
hi
- 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