Array Of Points

Dec 3, 2014

In one part of my small code, I want to make a sky which will have area of 200 * 200 pixels, and inside I want to have 100 randomly placed stars (I tried to make an array of 100 elements - of class "Point").Each star should have its x and y coordinate, and I don't know how to do it. I tried many things.

import java.util.Random;
import java.awt.Point;
public class Sky {
private Point[] stars = new Point[100];
public Sky() {
for(int i = 0; i< stars.length; i++){
Random r = new Random();
int u = r.nextInt(199);
int v = r.nextInt(199);
//x[0].setLocation(u,v);
21stars[0].x = 5;

[code]...

View Replies


ADVERTISEMENT

Applets :: JApplet That Ask User For Points And Draw A Line From Said Points

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

How To Fill Array Of Points

Oct 10, 2014

I need to write a program but I am having hard time filling an array of triangles...we are suppose to have 3 different classes..1 class of points..1 class of triangles and 1 main method which apply all those..here what I have been come up so far for the point class which I believe is good..

public class Point {
private float x;
private float y;
//Making x equal to the x coordinate and y equal to the y coordinate like on a graph
public Point(float xCoordinate, float yCoordinate) {
x = xCoordinate;
y = yCoordinate;

[Code] ....

Now here is my question how I am suppose in the main method fill an array of triangles for 100 triangles or less?

View Replies View Related

Adding Points Objects Into Array

Oct 24, 2014

I am trying to add Point objects into an Array.This is my code to read in data

Java Code:

public void readRoadMap(File road) {
try{
String line;
BufferedReader br = new BufferedReader(new FileReader(road));
while((line = br.readLine()) !=null){
this.points.add(new Point(line));

[code]....

View Replies View Related

Insertion Points In Array Using Binary Search Using Comparable

Feb 24, 2014

Operator is undefined for argument type. Error is located at the end of the binary search method array[position] < key

import java.util.Arrays;
public class binarySearch {
public static <T extends Comparable<T>> int binarysearch(T key, T[] array) {
int start = 0;
int end = array.length - 1;
int position =-1;
while (start <= end && position == -1) {

[Code]....

View Replies View Related

Algorithm To Find Shortest Route Between Two Points In 2D Grid Array

Mar 24, 2014

What would be a good and simple algorithm to find the shortest route between two points in a 2D array[grid] ? There can be certain obstacles in the grid i.e. some of the cells may be inaccessible. I tried googling for it and found that A* is the best for this but I am just a beginner and would like to start with something much simpler.

View Replies View Related

How To Get All Points In X And Y Coordinates Of Arc

Jul 4, 2014

I am planning a race simulator car and I have a problem to get the x and y coordinates from the graph (or circuit). I explain the problem better. If I for example, drawing an arc using the library DRAW2D how do I get all the points in x and y coordinates of that arc?

View Replies View Related

Distance Between 2 Points

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

Displaying Sets Of Points

Jan 20, 2014

Here is my code

Java Code: //Points Display
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.awt.Graphics;
import java.awt.Color;
import java.awt.Dimension;
import java.util.Random;

[code]...

1. Why, when I press "New" rapidly, will it skip painting shapes sometimes/adding to totcount.

2. How can I make it so that The box in the background(which is currently connected in the wrong way as I was getting an error when I connected it correctly) can be modifiably large. AKA, I want to draw a grid in the background that can be different sizes, depending on the values of a variable xsize and ysize.

3. What can I do to clean this up? All I want it to do is display the convex hull of the four points given in the int[][] displaypoints.

View Replies View Related

Reading Number Of Points

Oct 24, 2014

I am trying to receive an input file which has either 6 or 8 points and whether it is 6 or 8 points, I do ask the program to save it into an array and then print it. However my program crash after printing few lines. I do know what is wrong with the program my line.split(",").length print 1 at the first and then start printing the numebrs in teh rest of lines which makes it skip a line which means the lines that has for example 8 points will go to a loop that only 6 points and a line that has 6 points will go to a loop that has 8 points and then obviously crashes.

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.LineNumberReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Scanner;

[code]....

View Replies View Related

How To Use Break Points In Netbeans 8

Aug 19, 2014

I want to know that how can i use break points in net beans 8. I'm able to put break point by clicking at the line but don't know how to use it..Actually i'm getting wrong output of my code and i want to know my line by line execution of the code so i can get better idea of where is my code going from one line to other. I have used break point in micro soft visual studio2010 and that was easy after puting break point run the project then f11 to get line by line execution...I want to know any method exist in java net beans (i'm doing GUI swing controls)...

View Replies View Related

Calculating Points On A Circle Using Radius

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

How To Calculate Sinus / Angle Between Two Points

Dec 11, 2013

I need to know the sinus or angle between two points (x1,y1) and (x2,y2).

Any formula to calculate this?

View Replies View Related

How To Draw Points With Coordinates From Database

Jul 23, 2014

I extracted columns from database and made calculations inside while loop. I know i need to make array to get from it coordinates for points. I want to draw them in interface created in another class but i have black hole and don't know how to get datas from while loop to array which is below.

View Replies View Related

Remove Question Marks And Exclamation Points

Jan 24, 2015

I wrote code to remove question marks and exclamation points from some text. However, one can find those in my output file. Interesting enough, the periods (full stops) were removed.

import java.util.Scanner;
public class TextTokenizer {
private Scanner scanner;
private String[] removableCharacters = { ".", "?", "!", ":", ";", """, "'" };
public TextTokenizer(char[] texts) {
scanner = new Scanner(new String(texts));

[Code] ....

View Replies View Related

How To Make Answer To 2 Decimal Points In Java

Jan 18, 2015

I am having trouble figuring out where to put %.2f in my code. I need it to get my answers for surfaceArea and Volume to be rounded to two decimal points. I have everything completed but wherever i put it, it seems to not work.

System.out.println("This program will compute the volume and surface area of a rectangular prism.");
String output;
double length;
double width;
double height;
double volume = 0;
double surfaceArea = 0;
System.out.printf("%.2f", surfaceArea);

[code]....

View Replies View Related

Servlets :: If URL Already Points To A Resource - Can Servlet Still Be Mapped By This URL?

May 5, 2014

I have a link with URL say "/atom/filename.link" on one webpage on my server. On clicking it, a response will return in XML format.

In the XML there is information like:

<library id = "123" path =""/>
<document id = "1234" path =""/>

With this information I can generate a URL to another link, say /libray?id=123/document?id=1234

Now I would like to realize a function so that on clicking this link, it will be automatically redirected to that new link, which is generated from the XML file.

At first I try to use a servlet/filter in a web-app and then deploy it on the server, inside this servlet/filter I make a new URL connection with the same request URL and retrieve the response and the parse the XML data. But now the request URL points to the servlet now, not the actual XML file.

For example, if I set the set the servlet-mapping to /atom, If I try to connect to the URL /atom/filename.link inside the servlet, will it still be directed to this servlet? It's like a loop, and the real content can never be reached because now the servlet occupies its path.

View Replies View Related

Print A Blank Line After Certain Specific Points In Iterator

Feb 17, 2015

I have the following HashMap:

// 2009
nobelPrizeWinners.put("2009 Physics",
new PrizeWinner[] {new PrizeWinner("Charles K.", "Kao"),
new PrizeWinner("Willard S.", "Boyle"), new PrizeWinner("George S.", "Smith")});
nobelPrizeWinners.put("2009 Chemistry",
new PrizeWinner[] {new PrizeWinner("Venkatraman", "Ramakrishnan"),

[Code] .....

At the moment, my output is:

2008: Chemistry: Osamu Shimomura, Martin Chalfie, Roger Y. Tsien
2008: Economics: Paul Krugman
2008: Literature: Jean-Marie Gustave Le Clézio
2008: Medicine: Harald zur Hausen, Françoise Barré-Sinoussi, Luc Montagnier
2008: Peace: Martti Ahtisaari

[Code] .....

However, I need a blank line between the final entry of 2008 and the first entry of 2009.

View Replies View Related

Points To Ponder For Java Null Pointer Exceptions

Dec 12, 2014

This is what I wrote and I get this eror : Points to Ponder for Java Null Pointer Exceptions

public class Line{ 
private Punkt2d pStart;
private Punkt2d pEnde;
public Line(Punkt2d pStart, Punkt2d pEnde) {
this.pStart = pStart;
this.pEnde= pEnde;

[Code] ....

Erorr:

Exception in thread "main" java.lang.NullPointerException
at Line.getLength(Line.java:38)
at Aufgabe_6_1.main(Aufgabe_6_1.java:7)

View Replies View Related

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 View Related

JavaFX 2.0 :: How To Recover From Too Many Touch Points Reported Exceptions

Sep 17, 2014

I'm trying to stress test JavaFX and I'm on Window 8.1 using 1.8.0_20-b26. I have an application that has many objects on the scene with animation timers and overall it purposefully runs very slow. I have listeners on the root AnchorPane for touch input and if I generate many touch point events after a few minutes I get "Too many touch points reported" exceptions (posted below) and the app of course no longer responds to touch input. Is it possible to catch the exception and then reset the scene touch input so it goes back to normal without restarting the application? If it lost any current touch input that's fine.
 
Exception in thread "JavaFX Application Thread" java.lang.RuntimeException: Too many touch points reported
  at javafx.scene.Scene$ScenePeerListener.touchEventNext(Scene.java:2686)
  at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleNextTouchEvent$346(GlassViewEventHandler.java:1090)

[Code]....

View Replies View Related

Calculate Distance Between Two Points - All Numbers And Return Values Should Be Of Type Double

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

Enter Radius Of Bounding Circle And Display Coordinates Of Five Corner Points On Pentagon

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

JavaFX 2.0 :: 3D Sphere To Represent Each Single Point - Rotation Lagging With Large Number Of Points

May 22, 2014

We are doing a visualisation tool for point cloud research project. We use 3d sphere to represent each single point and when we have large number of points to display (~40,000), the rotation becomes very lagging.
 
What we have tried:

set JVM flag -Djavafx.animation.fullspeed=true, this worked a bit, but not significant.set JVM flag -Djavafx.autoproxy.disable=true, this did not work.

set Cache to true and CacheHint to Cache.SPEED, this did not make much difference.create another thread to do the rotation, and sync back after calculation, this did not work neither.

View Replies View Related

Generate 10 Random Integers / Store In Array And Then Calling A Method To Display Array

Nov 8, 2014

So I need to generate 10 random integers in the range 1-20 but i have to store them in an array called numbers. Then I have to call a method called displayArray which displays the contents of the array and for the assignment i have to use a for loop to traverse the array. The method header for the displayArray method is:

public static void displayArray(int[] array)

This is what I have done
 
public class RandomIntegers {
 static int numbers = 0;
public static void displayArray(int[] array) {
System.out.println(numbers + "Numbers Generated");

[Code] .....

View Replies View Related

Create 2D Array Out Of CSV File And Find Number Of Elements To Determine Array Size

Mar 24, 2015

I am taking the Class Algorithms and Datastructures and got an assignment for Lab that really throws me off. The goal is to create an Array out of a given CSV file, implement several Methods that get the size of array, etc.

I am still stuck in the first part where the CSV has to be imported into the Array. My problem is that I need a mechanism that figures out the needed size for the Array, creates the array, and only then transfers the data from the CSV.

The list consists of the following wifi related values:

MAC-Adress, SSID, Timestamp, Signalstrength.

These are on the list, separated by comma. The Columns are each of these, and the rows are the four types of values making up the information on a certain wifi network.

The catch is, we are not allowed to use any of the following:

java.util.ArrayList
java.util.Arrays
and any class out of java.util.Collection.

So far I used the BufferedReader to read in the file and tried to implement the array, but I get an arrayindexoutofboundsexception.

Below is my Code (Its still an active construction zone):

public class WhatsThere {
public WhatsThere(String wifiscan) throws IOException {
}
public static void main(String[] args) throws IOException {
// WhatsThere Liste = new WhatsThere(String wifiscan);
String[][] arrayListe = new String[0][0];

[Code] ....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved