Question

write this code to define the circle class and we will in 30 minutes to continue...

write this code to define the circle class and we will in 30 minutes to continue practice how to use the circle class and define more class

language java

Homework Answers

Answer #1

class Circle{
double radius;
double area;
Circle(double r)
{
radius=r;
}
double getRadius(){ return radius; }
double computeArea()
{
return 3.14*radius*radius;
}
public String toString()
{
return "Radius : "+this.getRadius()+"\nArea ="+this.computeArea();
}
}
public class Main
{
   public static void main(String[] args) {
       Circle obj=new Circle(5.6);
       System.out.println(obj);
   }
}


Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Write Python code to define a class called Student. The Student class should have the following...
Write Python code to define a class called Student. The Student class should have the following private fields: name – to store the name of a student attend – to store how many times a student attend the class grades – a list of all student’s grades The Student class should have the following methods: a constructor getter method for the name field attendClass method: that increments the attend field (should be called every time a student attends the class)....
Write code for a JAVA class for a "Car". The Car class has 2 properties: modelType...
Write code for a JAVA class for a "Car". The Car class has 2 properties: modelType and currentSpeed. Make sure to write code for instance variables (the properties), getters/setters and a default constructor, overloaded constructor. ALSO, include one method called "accelerate" that increases the speed by "1.0" miles per hour
Module 4 Code L Write a short code snippet creating a class with three class variables...
Module 4 Code L Write a short code snippet creating a class with three class variables and one method setting all three variables. The class is called Person and the variables should be name, birth, and address. You should supply a method called setAll() that will be used to set the values of the class variables. // This is a JAVA program! I am a little confused any help would be great :)
Part 1 Given the following code: public class MyClass { private double score; private String studentID;...
Part 1 Given the following code: public class MyClass { private double score; private String studentID; //code of the class ..... } //end of MyClass Code a default constructor and an overloaded constructor of MyClass that will assign values to its two instance fields: Please write in JAVA Part 2 Continue from question about, code an mutator of instance field called studentID:
Define fixed heap-dynamic arrays. (b) Write a code snippet (in your favourite language) that creates a...
Define fixed heap-dynamic arrays. (b) Write a code snippet (in your favourite language) that creates a fixed heap-dynamic array?
Write a Java code to complete the following operations: (1) Define a double variable var1, initialize...
Write a Java code to complete the following operations: (1) Define a double variable var1, initialize it with value 9.99 (2) Given two integer variables var2 and var3, write a statement that gives var3 a value that is 4 more than the value of var2. (3) Define a double variable var4, initialize it with value 1234.56. Write a statement to change var4 so it will just hold one third (1/3) of the original value (4) Given four double variables var5,...
Language: JAVA(Netbeans) Write a generic class MyMathClass with at type parameter T where T is a...
Language: JAVA(Netbeans) Write a generic class MyMathClass with at type parameter T where T is a numeric object (Integer, Double or any class that extends java.lang.number) Add a method standardDeviation (stdev) that takes an ArrayList of type T and returns a standard deviation as type double. Use a for each loop where appropriate. Hard code a couple of test arrays into your Demo file. You must use at least 2 different types such as Double and Integer. Your call will...
(Please use java to write these questions) Q1. Create a class on an object Computer with...
(Please use java to write these questions) Q1. Create a class on an object Computer with two fields and two methods as follows: (5 points) field: cpu and memory, method: compile( ) and execute( ) Q2. Write a source code to activate a class created in Q1. (5 points)
Pleas code in Java Write a generic class named PairImpl that implements the interface below.write a...
Pleas code in Java Write a generic class named PairImpl that implements the interface below.write a program that creates list of 3 pairs where each pair represents the name of a fruit and the quantity.    Once the list is populated three pairs of fruits and quantities, it then prints each pair shown in the sample run using a for loop.
write a java code. Write a program using loops to compute the sum of the 30...
write a java code. Write a program using loops to compute the sum of the 30 terms of the series below. 91/(3 + 2 + 2) + 92/(4 - 4 + 5) + 93/(5 + 6 - 8) + 94/(6 - 8 + 11) + 95/(7 + 10 + 14) + 96/(8 - 12 - 17) + . . . . Output: Term Ratio Sum 1 13 13 2 18.4 31.4 etc etc