Two Circles Overlap If Distance Between Their Center Points Is Less Than Sum Of Their Radius
May 1, 2015
Write a program that draws 20 circles, with the radius and location of each circle determined at random...... Two circles overlap if the distance between their center points is less than the sum of their radii...
There may be many problems with the code in general but what I'm struggling with is the distance and the totalradius portion. Visually, its inaccurate.
import java.awt.*;
import javax.swing.*;
public class CircleTest extends JPanel {
Circle []circles;
Circle []circleCenter;
Circle []all;
private int distance, totalradius, dx, dy;
private int radius,x,y;
[Code] ....
View Replies
ADVERTISEMENT
Oct 24, 2014
I have to print points on a circle in increments of -0.1, but when I use a number larger than 1.3, the list stops at 0.1 larger than negRadius, and I don't know why. (Assume the center is (0,0))
public class PointsOnACircleV1
{
public static void main(String[] args)
{
double radius = 1;
[code]...
View Replies
View Related
Mar 14, 2009
hey just having some trouble with a homework question:
For this question you will use the Point class from the Java API, which represents points in 2-dimensional space, each of which has an x and y coordinate. You must write a program called Distance, which does the following:
1. Reads in the coordinates (separated by spaces) of two points
2. Creates two Point objects with the values entered by the user
3. Uses the distance method of the Point class to calculate the distance between the two points
4. Prints out the distance
Details on how to create Point classes can be found in the Java API documentation. However, for this question the only two methods you need to know about it are the following:
- Point(int x, int y) - Constructor; creates a new point
- double distance(Point other) - Calculates the distance between this point and another point
I think what i have so far will work, im jsut having problems creating 2 new objects . it points at new and says incompatible types. And also points at +distance and says cannot be de reference from a static context.
import java.awt.Point;
import java.util.Scanner;
public class Distance{
private int pointX;
private int pointY;
private double distance;
public Distance(int x,int y)
[Code] .....
View Replies
View Related
May 29, 2014
(Corner point coordinates) Suppose a pentagon is centered at (0, 0) with one point at the 0 o’clock position. Write a program that prompts the user to enter the radius of the bounding circle of a pentagon and displays the coordinates of the five corner points on the pentagon. Here is a sample run:
Enter the radius of the bounding circle: 100
The coordinates of five points on the pentagon are
(95.1057, 30.9017)
(0.000132679, 100)
(-95.1056, 30.9019)
(-58.7788, -80.9015)
(58.7782, -80.902)
What we know , we know both the radius of the circle(user inputted) and the side of the pentagon from formula (double side = 2 * radius * Math.sin(Math.PI/5)) .We also know that one point is (0 .100) Also i know that the distance between 2 points is Math.sqrt(Math.pow(x1 - x2 ,2) - Math.pow(y1 -y2 ,2)) .
There might be other ways to solve it but this is my best bet trough i dont remember how to solve linear equations of the form x^2 + y^2 = - radius and radius ^2 = x^2 + (y - 100) ^ 2..
The solution i found is using the radius from the center to the point we want to find out and using the radius to the point we already know ( 0 .100) but i have to solve that damn equation first ...
View Replies
View Related
Jul 8, 2014
Write method distance to calculate the distance between two points (x1, y1) and (x2, y2). All numbers and return values should be of type double. Incorporate this method into an application that enables the user to enter the coordinates of the points.
Hints:
- The distance between two points can be calculated by taking the square root of
( x2 - x1 )2 + ( y2 - y1 )2
- Use Math class methods to compute the distance.
- Your output should appear as follows:
Type the end-of-file indicator to terminate
On UNIX/Linux/Mac OS X type <ctrl> d then press Enter
On Windows type <ctrl> z then press Enter
Or Enter X1: 1
Enter Y1: 1
Enter X2: 4
Enter Y2: 5
Distance is 5.000000
Type the end-of-file indicator to terminate
On UNIX/Linux/Mac OS X type <ctrl> d then press Enter
On Windows type <ctrl> z then press Enter
Or Enter X1: ^Z
View Replies
View Related
Nov 6, 2013
This is what he wants: He wants us to prompt the user to input x values and y values (that will be entered into an array when clicking one of the two buttons (this one will say: Add point)). When they click the second button (draw lines), it should take all the points and draw a line that connects all the points together using a method that we write. In the method we have to call the paint method up which the lines will be drawn. The lines drawn should be touching every point added. It shouldn't have parameters. It will also use Graphics painter = getGraphics(); We can't use frames either.
I have everything up until the method understood.
How to write a method that will draw a line from points inputted that is called up in the action listener when the second button (draw lines) is pressed.
View Replies
View Related
Oct 27, 2014
the thing with this program is that instead of it having preset variables, I want to prompt the user to enter values of the two rectangles. I don't know how to use the scanner in this case, or even if I should use the scanner.
class MyRectangle2D {
//declare the variables
private double x, y;
private double width, height;
[code]...
View Replies
View Related
Feb 10, 2014
I have 4 small applets on a page that simply prints out the quadratic equation for values passed in. There are 4 applets on a page that have different values assigned. They display fine.... sometimes.... if I refresh or generate new numbers sometimes one applet looks as though it has numbers overlapping the new values. If I resize or drag the browser everything displays fine again - no need to refresh the browser or anything. It's as though old values or something are being overwritten by the new or something similar is happening. What should I include in the paint method of the JPanel that might clear the applet before initial painting happens..... if anything?
View Replies
View Related
Apr 26, 2015
Circle class:
public class Circle extends GeometricObject implements Comparable<Circle>
{
private int radius;
public Circle(int newRadius)
{
radius=newRadius;
[Code] ....
When I run the driver class it tells me that all tests have passed(as it should be) except for Test 0. I have tried to play around with the code, but I cant figure it out and it is driving me crazy because in my head my code makes sense.
View Replies
View Related
Nov 17, 2014
I am working on a random circles program. Basically it is supposed to draw as many random circles as you tell it to, 1-20. I have it drawing circles but it only draws twenty no matter what I type in. Here is my code for the component:
import javax.swing.JComponent;
import javax.swing.JPanel;
import java.awt.Graphics;
[Code]....
i should be the number the user types in, it gets sent to n and that should tell the program how many circles to draw.
View Replies
View Related
Feb 22, 2014
I have created two classes. The FrameViewer is my driver class, and Circle is my constructor.
The first problem is, the program seems to be creating both circles, but it only displays displaying the last added circle (in this case, circle2).
The second problem is, I want to pass the color I wish to use to the constructor, but I'm having problems figuring out the proper method to do so. In the constructor, I have assigned Color.BLUE as a default. On circle two, I want to override this color choice and assign Color.Orange. I am not having any luck setting this to work either.
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Color;
public class FrameViewer {
public static void main(String[] args) {
JFrame frame = new JFrame();
[code]....
View Replies
View Related
Oct 29, 2014
You should write a class that represents a circle object and includes the following:
1. Private class variables that store the radius and centre coordinates of the object.
2. Constructors to create circle objects with nothing supplied, with just a radius value supplied and with a radius and centre coordinates supplied.
3. Public instance methods that allow the radius and centre coordinates to be set and retrieved (often known as set/get methods).
4. Public instance methods that return the circumference and area of the circle.
5. A public class method that tests if two circle objects overlap or not
Here is my code:
import java.lang.Math;
public class Circle {
private double xCentre, yCentre, Radius;
// constructors
public Circle() {
xCentre = 0.0;
yCentre = 0.0;
Radius = 1.0;
[Code] ....
The second program just has to demonstrate each aspect addressed in the brief I pasted at the top.s of what else I can do.
This is as far as I got during the 3 hour lab session I had and both compiled fine but when running just displayed all the text eg. "Circumference of first circle is ", but didn't display any numeric values. I don't have the facilities to actually run the program unless I'm in the computer lab, I have a short opportunity to go in tomorrow but that will be the last so I'm doubtful that I'll get it fully working in time.
The problem is that when this code runs it doesn't display any numerical values, ie nothing is being passed between the two programs.
View Replies
View Related
Jul 8, 2015
I am trying to create a user defined Exception. I am using a hard-coded value in the constructor of circle class at the time of object creation.But in the constructor this value becomes 0.
import java.lang.Exception;
import javax.swing.*;
class InvalidRadiusException extends Exception{
private double r;
public InvalidRadiusException(double radius){
r = radius;
[Code] ....
Due to this its always generating InvalidRadiusException even if i am supplying a non-zero non-negative value.
View Replies
View Related
May 31, 2014
This is the code
public class PondRadius {
public static void main (string[] args) {
//Calculate the radius of a pond
//which can hold 20 fish averaging 10 inches long
int fishCount = 20;//number of fish in pond
int fishLength = 10;// Average fish length
int inchesPerFoot = 12;//number of inches in one foot
[Code] ....
And here is the error or exceptions i received
C:javaLesson1>javac PondRadius.java
PondRadius.java:23: error: ')' expected
System.out.println("To hold" + fishCount + fish averaging " + fishLength +" inch
es long you need a pond with an area of
" +
[Code] .....
View Replies
View Related
Apr 7, 2014
I am trying to create a game in java for my final project for schhol but am having problems with my jframe. I want my 3 Jbuttons to be in the center of the jframe and be vertical but can not seem to get the 3 buttons in the center of the jframe ....
import javax.swing.*;
import java.awt.Container;
import java.awt.*;
public class SnakeObject extends JFrame
{
public SnakeObject()
{
createframe();
[Code] ....
View Replies
View Related
Feb 10, 2014
I'm using the Spring Layout Manager to put a form in a JPanel and I'm trying to center the lines horizontally so they will stay centered when the window is resized. Nothing I've tried has worked, I can't find anything on the web, and even my fallback of seeing how Netbeans does it fails as Netbeans doesn't seem to support the Spring Layout.
View Replies
View Related
Jun 17, 2014
So here's my code as it is right now:
Java Code:
public class PrintHoledRectangle
{
public static void main(String[] args)
{
int width = Integer.parseInt(args[0]) / 2 * 2 + 1;
int height = Integer.parseInt(args[1]) / 2 * 2 + 1;
int centre = width * height / 2 + 1;
int index = 0;
[Code] ....
The width of the rectangle to be printed is given by the first argument, the height by the second
The centre tile ("[_]") of the rectangle (to be printed as " ") is given by the formula: ((width*height)/2)+1, assuming you count each tile left-to-right, top-to-bottom
My thinking is that the programme keeps a running count (seen as 'index') so that, when the centre tile is to be printed, it outputs " ", otherwise "[_]", hence the if-else statement
Currently, it prints "[_]" to infinity
View Replies
View Related
May 5, 2014
Normally, the height of the CENTER component (or position) is greater than that of the NORTH and SOUTH components in a BorderLayout.
Is it possible to increase the size of the SOUTH component and decrease the size of the CENTER position because the jcomponents I want to add in the SOUTH component are bigger? or shall I have to change the layout and use some other layout?
View Replies
View Related
Dec 8, 2014
In the documentation of StackPane i read: "The stackpane will attempt to resize each child to fill its content area. If the child could not be sized to fill the stackpane (either because it was not resizable or its max size prevented it) then it will be aligned within the area using the alignment property, which defaults to Pos.CENTER."
But as I add another Pane (Anchor- or BorderPane) this added Pane is shows always in left upper corner of the StackPane. How could I force my StackPane to center another AnchorPane?
View Replies
View Related
Sep 18, 2014
You have been given the job of writing a program to assist pilots who fly the Beechcraft Starship-‐‑1 executive aircraft.As with any airplane, it is essential that the pilot know the total weight of the loaded plane at takeoff and its center of gravity. If the plane weighs too much, it won'ʹt be able to lift off. If the center of gravity is outside the limits established for the plane, it might be impossible to control. Your task is to write a program that will determine the total weight and center of gravity of this plane
Inputs: The number of crew members, number of passengers, weight of the forward baggage compartment contents, aft baggage compartment contents weight, and the amount of fuel in gallons are to be accepted as INTEGER values in the order stated. Be sure the input values are within acceptable ranges
Outputs:You must echo the input values, annotated with their appropriate names,calculate and display the total weight, and the center of gravity.
View Replies
View Related
May 6, 2014
The goal is to desplays circles (max of 30) of fixed radius = 20, with the rightmost circle drawn in blue and left most circle in red and the rest are in white. The center is determined by the location of the point where the mouse is pressed. the number of circles is equivalent to number of mouse has been pressed_ the circles will be drawn only when you push the "draw" button.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.JPanel;
public class CirclePanel extends JPanel {
private final int WIDTH = 500, HEIGHT = 300;
private final int RDIUS = 20;
private final int MAX = 30;
[code]...
View Replies
View Related
Oct 8, 2014
I am supposed to write a Tester to get the current volume of a balloon that starts with a radius of 0 after it is inflated.This is the balloon:
public class Balloon
{
private double savedRadius;//instance variable
/**constructor!!
Constructs a balloon with a radius
*/
}
[code]....
View Replies
View Related
Mar 5, 2014
I am doing an assignment that is asking for the user to put in the radius of a circle and the program figures out the area, diameter and circumference. It is using 2 different java programs to accomplish this. One with the info on how to get area, diameter and circumference and one is the demo that runs the program. I keep getting errors on my demo.
// Circle Class
public class Circle {
private double rad;
private double Pie;
private double area;
private double diameter;
[Code] .....
View Replies
View Related
Jan 29, 2015
How do you use power of math. I'm trying to write a calculator to calculate the volume of a cylinder by asking the user to enter the height and radius but when I use pow(2) it doesn't work. I imported java.lang.math class so i dont have to keep using math. for now my code runs just fine since I'm using radius * radius but I would really luv to use the power instead times each other when i have to use higher powers.
import java.util.Scanner;
import static java.lang.Math.*;
public class Lab2 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
[Code] .....
View Replies
View Related
Mar 17, 2015
I am working on this new project where we are using the great distance formula but every time I run my ending result is NaN. I was researching, and people say its because you divide by 0. I think I have my formula correct.
Java Code:
public class testingFormula {
public static void main(String[] args) {
double lat = 34.01858902;
double lon = -118.2817688;
double lat2 =33.94530869;
double lon2 = -118.3994904;
[Code] ....
View Replies
View Related
Nov 25, 2014
I'm trying to write a program that will takes as input a sub-sequence/set/query eg; P = <1,3,0>)
int [][] S = {{1, 3, 0}};
and a list of series. eg;
int [][] T = {{1, 2, 3, 0, 1, 5},{9,9,9,9,9,9}};
The idea is to iterate through the series and find the lowest distance, using euclidean distance, between a subseries and the query.Example: d=distance d(P,T[1..3]=√(1-1)^2 + (3 - 2)^2 + (0 - 3)^2 = sqrt10 => 3.16...Then go through the first subseries again but starting at [1] in the array instead of [0], so d(P,T[2..4]=√(1-2)^2 + (3-3)^2 + (3-0)^2. keep repeating this process, then start searching the next subseries for the lowest distance, save the position of index(row#) and the start of the subseries(column#) that has the lowest distance.Here is the code i have written to do this without using nested for-loops to do it:
//Works out euclidean difference, long way need for loops
int [][] T = new int [][] {{1,2,3,0,1,5}};
int [][] S = new int [][] {{1, 3, 0}};
int s1 = S[0][0]; int s2 = S[0][1]; int s3 = S[0][2];
int t1 = T[0][0]; int t2 = T[0][1]; int t3 = T[0][2];
double sum;
sum = Math.pow((s1 - t1), 2);
sum += Math.pow((s2 - t2), 2);
sum += Math.pow ((s3 - t3), 2);
Double diff = Math.sqrt(sum);
System.out.println(diff);
}
However i want to use for-loops to iterate through as subseries could be of any length. The way i did it above isn't applicable.This is what i have so far...
int [][] S = {{1, 3, 0}};
int [][] T = {{1, 2, 3, 0, 1, 5},{9,9,9,9,9,9}};
int
[code]...
View Replies
View Related