Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners even more circles
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


dylan
even more circles
1 Answer(s)      4 years and 2 months ago
Posted in : Java Beginners


Write an application that compares two circle objects.
? You need to include a new method equals(Circle c) in Circle class. The method compares the radiuses.
? The program reads two radiuses from the user
? The program then creates two circle objects
? and compares them by using equals() method.
Hint. if (circle1.equals(circle2)) ...
? The comparison result is printed.

Advertisement
View Answers

August 17, 2010 at 3:35 PM


Hi Friend,

Try the following code:

import java.util.*;
class Circle{

double radius;
Circle(){
}
Circle(double radius){
this.radius=radius;
}
public double getRadius(){
return radius;
}
public boolean equals(Circle c) {
if (c.getRadius() == this.getRadius()){
return true;
}
else{
return false;
}
}

}
public class CircleApplication
{
public static void main(String[] args)
{
Scanner input=new Scanner(System.in);
System.out.print("Enter Radius1: ");
double r1=input.nextDouble();
Circle c1=new Circle(r1);
System.out.print("Enter Radius2: ");
double r2=input.nextDouble();
Circle c2=new Circle(r2);
boolean result=c1.equals(c2);
System.out.println(result);
}
}

Thanks


Related Tutorials/Questions & Answers:
even more circles - Java Beginners
even more circles  Write an application that compares two circle objects. ? You need to include a new method equals(Circle c) in Circle class. The method compares the radiuses. ? The program reads two radiuses from the user
more circles - Java Beginners
more circles  Write an application that uses Circle class you created in the previous assignment. ? The program includes a static method createCircle() that o reads a radius of a circle from the user o creates a circle object
Advertisements
Attaching circles
Attaching circles  How to attach circles with a distance joints
Circles and Triangles
Circles and Triangles  How can I draw the triangle inside the ellipse with 3 mouse clicked(or how can i do an outside triangle circle with 3 mouse clicked)?? This is my code for triangle with 3 mouse Clicked but I don't know how
how to draw lines,circles, rectangles on JSP.
how to draw lines,circles, rectangles on JSP.  how to draw lines,circles, rectangles on JSP. Kindly provide solutions asap
odd and even
odd and even  how can i make a program of even and odd using case statement?   Hi Friend, Try the following code: import java.util....{ System.out.println(); System.out.println("1 Display Even"); System.out.println("2
Check even or odd number.
Check even or odd number.  How to check given number is even or odd?   Simple if it is devided by 2 it is even and if not if is Odd  ...){ System.out.println("Number is Even"); } else
Even and odd functions in java
Even and odd functions in java  Even and odd functions in java  ...); int number; System.out.println("Input any number to check even...) { if (n % 2 == 0){ System.out.println("Your number " + n + " is even
how to draw lines,circles, rectangles on JSP (using Java Graphics)
how to draw lines,circles, rectangles on JSP (using Java Graphics)  how to draw lines,circles, rectangles on JSP (using Java Graphics)   Hello Anuj Try the Following Code : image.jsp <%@ page contentType="image
EVEN NUMBERS - Java Interview Questions
EVEN NUMBERS  i want program of even numbers?i want source code plz reply?  Hi Friend, Try the following code: class EvenNumbers... counter = 0; System.out.println("Even Numbers are:" ); for (int i
how to draw multilple circles in a circular form and connect them with lines - Java Beginners
how to draw multilple circles in a circular form and connect them with lines  Hi, Can anyone explains me , how to draw multiple circles using a single applet or swings in a circular form and connect them with lines. It should
JSTL - check odd/even number - JSP-Servlet
JSTL - check odd/even number  How do i create a JSTL program to generate random numbers and to check whether they are odd/even and print "this is an even (odd) number and it is in between so and so number? e.g. the random number
print the sum of even number from 1 to 100
print the sum of even number from 1 to 100  how to print the sum of even number from 1 to 100 using for loops? Thanks
Listing all even numbers between two numbers
Listing all even numbers between two numbers  Hi, How to write code to list all the even numbers between two given numbers? Thanks   Hi, You function will take 2 numbers and the find the even numbers between
log4j is not logging even under src path
log4j is not logging even under src path  We are working with struts application and using log4j.properties file , it is placed under WEB-INF/classes and we have referenced log4j-1.2.8.jar in classpath file even after
print the even numbers between the range 100-200
print the even numbers between the range 100-200  Q ?write an application that print out the even numbers between the range 100-200 ? 1- which aer... prints out the even numbers between the range of 100 and 200 and then determine
Odd Even Transposition Sort In Java
Odd Even Transposition Sort In Java   ... In this example we are going to sort integer values of an array using odd even transposition sort. Odd even transposition sort is a parallel sorting algorithm. Odd Even
Java write even numbers to file
Java write even numbers to file In this section, you will learn how to write the even numbers to file. By using the PrintWriter class, you can write any type... leaving 0 remainder, then it should be an even number and stored in the file. We
PRIME AND EVEN AND ODD - Java Interview Questions
PRIME AND EVEN AND ODD  how to write prime numbers?i want source code? how to write even numbers? i want source code? how to write odd numbers ?i... + " "; } } } System.out.println(primeNo); } } 2) Following code displays Even and Odd numbers
NoSuchMethodException even if method defined - Java Beginners
NoSuchMethodException even if method defined  Hi I am loading a class (Student) dynamically from a jar (samplejar.jar) file using URLClassLoader. Next thing when I want to access method or constructor of the previously loaded
UITableview show more
UITableview show more  How to fetch more records from the sql database in UITableview using show more option when there is a large amount of data? Thanks
Display Hello even before main get executed??
Display Hello even before main get executed??  I have a class (main method) as follow.....As I know this can be done using static method, but Q is how? **class Hello{ public static void main(String[] args
SEND + MORE = MONEY
SEND + MORE = MONEY  Problem Description Write a program to solve... of magic formula is no more than 3, the number of digits of every number is no more... by exactly one space. Example Sample Input: 1 SEND + MORE = MONEY Sample Output
more code help
more code help  Instructions: Write a program to translate a message from English to Morse code. Using a simple text editor like Windows Notepad, create a text file with all of the Morse code combinations for the letters
Which method is more efficient?
Which method is more efficient?  I'm faced with initializing a bunch of text fields in java. The problem is that the number of text fields is quite large, so i thought of putting them into an array and using a loop to initialize
load more with jquery
load more with jquery  i am using jquery to loadmore "posts" from my... box its is going to display php posts and after that when i click on load more...); $('#loadmorebutton').html('Load More
Check whether highest number is even or odd
Check whether highest number is even or odd In this section, you will learn... it is odd or even. For this, we have taken two integer variables num1 and num2... that if the highest number is totally divided by 2,then it is even, otherwise
write an application that print out the even numbers between the range 100-200
write an application that print out the even numbers between the range 100-200   write an application that print out the even numbers between... and determine the even numbers between them. class EvenNumbers { public static
more Submit buttons in the same form
more Submit buttons in the same form  Can I have two or more Submit buttons in the same form
Two or more actions in the same form
Two or more actions in the same form  Can I have two or more actions in the same form
Advertisements
 

 

 

DMCA.com