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
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,...
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
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will...
Please write the code in Python. Write a program/function in any Object-Oriented programming language that will implement Queue Abstract Data Type with the following functions/methods.  Any build-in/pre-defined Queue function/library (e.g., java.util.Queue in Java) is NOT allowed to use in your code. push(Element):  insert the input Element (e.g., String or Integer in Java) to the end of the queue. pop(): remove the head element of the queue and print the head element on screen. count():  return the total number of elements in the queue...
Design a class with the following requirements: 1- give the class a name from your choice....
Design a class with the following requirements: 1- give the class a name from your choice. 2- write some code that creates three instance variables, choose a name and type for each one of them. (must have two private and one public variables) 3- Initialize the variables using two different constructors. 4- Use mutator and accessor methods (set and get) for the private data members. 5- Display the value of each member variable using a method. 6- In the main,...
write Java code FAMOUS QUOTES PROGRAM - Write a program that displays the following information in...
write Java code FAMOUS QUOTES PROGRAM - Write a program that displays the following information in the EXACT pattern/formatting shown below. You must use escape sequences to do this - this is not English class and things are written below to test you on escape sequences form class, so no matter what follow the pattern/formatting shown (the dashes and spaces do not have to be perfect but everything else should match, you should try to use tabs for the spacing...
JAVA Learning Objectives: To be able to code a class structure with appropriate attributes and methods....
JAVA Learning Objectives: To be able to code a class structure with appropriate attributes and methods. To demonstrate the concept of inheritance. To be able to create different objects and use both default and overloaded constructors. Practice using encapsulation (setters and getters) and the toString method. Create a set of classes for various types of video content (TvShows, Movies, MiniSeries). Write a super or parent class that contains common attributes and subclasses with unique attributes for each class. Make sure...
Shapes2D Write the following four classes to practice using an abstract class and polymorphism. Submit all...
Shapes2D Write the following four classes to practice using an abstract class and polymorphism. Submit all four classes. Shape2D class For this class, include just an abstract method name get2DArea() that returns a double. Rectangle2D class Make this class inherit from the Shape2D class. Have it store a length and a width as fields. Provide a constructor that takes two double arguments and uses them to set the fields. Note, the area of a rectangle is the length times the...