N-body Simulation - Forces For Body Not Calculating In Some Instances?

Mar 13, 2015

I am making a n-body simulation. For some reason, when I have two bodies orbiting each other and I add a third body, the two initial bodies stop orbiting each other.

EXAMPLE:

[URL]- earth is orbiting the sun, when I add mars,[URL] earth AND mars does not orbit the sun and both travel in a straight line. Almost as the forces are not being computed at all on the body. How can this be?

Here is the relevant code:
 
public void update(float deltaTime){
for(int i=0; i<bodies.size();i++){
resetForces(); 
bodies.get(i).update((float)(deltaTime / Math.pow(10,9))*timeScale);
lastTime = System.nanoTime();
//sets the forces for all bodies
for(int n=0; n<bodies.size();n++){

[code]....

View Replies


ADVERTISEMENT

JSF :: Page Content In OUTLOOK Body Not Getting Breaks

Jun 3, 2014

I have a requirement. I got a JSF page(parent page). When a button(say SEND EMAIL) is pressed, an email window (OUTLOOK) will be displayed as a popup. I have to populate whatever the text data of parent page as the body of the mail.

I am using mailto method : eg :

Here is my code:
==============
FacesContext context = FacesContext.getCurrentInstance();
HttpServletRequest origRequest = (HttpServletRequest) context.getExternalContext().getRequest();
context.getExternalContext().redirect(String.format("mailto:"+mailTo+"?subject=" + subject +"&body=" + body + "&cc="+mailCc+""));

till here it is fine..

My problem is body part is not getting breaks. I have tried
, ,
, <br>, <br></br> etc.. what ever stuff i found in google..

E.g. my email body looks like below.. it consists of url link also.

====================================================
Hi,

This is to inform you etc... ,

Please follow this Hyperlink link to navigate to your page.. etc.

regards..

======================================================

View Replies View Related

Calculate And Display Person Body Mass Index

Feb 12, 2015

I have to write a program that calculates and displays a person's body mass index (BMI). The BMI is often used to determine whether a person with sedentary lifestyle is overweight or underweight for his or her height. A person's BMI is calaculated with the following formula:

BMI = Weight X 703/Height^2

where weight is measured in pounds and height is measured in inches. The program should display a message indicating whether the person has optimal weight, is underweight, or is overweight. A sedentary person's weight is considered optimal if his or her BMI is between 18.5 and 25. If the BMI is less than 18.5, the person is considered underweight. If the BMI value is greater than 25, the person is considered overweight.However I can't seem to get rid of these errors:

----jGRASP exec: javac BMI.java
BMI.java:28: error: cannot find symbol
Scanner keyboard = new Scanner(System.in);
^
symbol: class Scanner
location: class BMI
BMI.java:28: error: cannot find symbol

[code]....

View Replies View Related

Servlets :: HTML Body Onload Not Working In Chrome

Mar 12, 2015

I have written sample web application with servlets and jsp. As per the below code the action url should be executed automatically according to the "onload". I have written this below code in one of my servlet, The below "onload" form hits the path in action only in Firefox and IE but not in Chrome(41.0.2272.74 beta-m (64-bit)).I have seen the link [Chrome - <body onload=“”> is not working ][1] , I have my below code in the end of servelt. there is nothing to execute after this code in the servlet.

out.write("<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
");
out.write("<html><body onload="alert('alert has been fired');document.forms[0].submit()">
");
out.write("<form method="POST" action="" + actionUrl + "">

[Code] ....

Is there any reserved key words of chrome in the above action url? If I execute this code in the html format, it is working in chrome. but if it is from servlet, alert() is not running.

View Replies View Related

Servlets :: GET HTTP Request Contain A Request Body?

Feb 25, 2014

I have the following questions:

1. Does a GET HTTP request contain a request body? If yes what is contained in it? Are the request headers also part of the request body?
2. Is it possible to send a byte array as part of the GET request in its body?
3. Is there a size limitation on the data that can be sent via a GET request?

View Replies View Related

Java Simulation Library

Mar 12, 2014

I am trying to work on a project that involves Java Simulation Library, the imported library jslCode.jar cant be found ...

package jslx.forecasting.demandgeneration;
import jsl.utilities.random.distributions.Binomial;
import jsl.utilities.random.distributions.Constant;
import jsl.utilities.random.distributions.Exponential;
import jsl.utilities.random.GetValueIfc;

[Code] ....

View Replies View Related

JTabbedPane Tab Click Simulation

Mar 31, 2015

Is it possible to programmatically simulate a click event on a tab (JTabbedPane) to trigger its changeListener once a button is clicked ?

View Replies View Related

Simulation - Two Cars Are Going To Race Against Each Other

Oct 22, 2014

I was thinking to make a game where two cars are going to race against each other. I already have two gif pictures which are the cars. I do now have a background and a racer track. So we can start from here.

I have made a object with construction which I called Racers. Inside that, i wrote a PaintWindow (Where the window and much more is inside), -car1, -car2. All these is private. So I made something like this now:

package p2;
public class Race {
private Object window;
private Car car1;
private Car car2;
public Race(PaintWindow window, Car c1, Car c2) {

[Code] .....

But the problem is now that im kinda lost and I dont really know what to write anymore. How can I get a for example a green background on the whole PaintWindow with two Racers tracks and inside the racers tracks (Each car have each track) does it have to be cars. So I need to somehow import the cars inside it too. But thats the problem I need. that I dont really know what more to do. To make it easier, I have a Main-method in another class.

public static void main(String[] args) {
PaintWindow window = new PaintWindow();
Car c1 = new Car(new ImageIcon("C:/Users/Sarah/Desktop/CarBlue.GIF"));
Car c2 = new Car(new ImageIcon("C:Users/Sarah/Desktop/CarRed.GIF"));
Race race = new Race(window,c1,c2);
race.action();
if(args.length>0) {
Paintwindow.pause(2000);
window.dispose();

View Replies View Related

SSO Kerberos Simulation In Java

Apr 20, 2014

I'd like to learn more in Java security, namly Kerberos and SSO. The question is weather I have too weak laptop. I have 8 GB ram. How many virtualbox instances od I have to run in order to JAAS, SSO kerberos demo to simulate. For instance VM with Windows 2008 Server -> 3 GB RAM, Centos VM -> 1GB. Is 8 GB RAM in my laptop not too little?

BTW

I do not have yet experience in SSO/Kreberos but I want to know what to do in order to simulate and exercise.

View Replies View Related

Print Queue Using Priority Q Simulation?

Nov 28, 2014

I have a class "ExecuteJob" which has Print Q in the form of Priority Q.

You can keep adding job to the Q by calling one of the method in the class. However, and object cant do things simultaneity can it? While im adding a new job to the print queue, can it be executing and existing job in the print Q.

To achieve that, I would need to implement process and threads? I believe am I right? So that adding a job is independent to being removed?

View Replies View Related

Front End For Air Traffic Control Simulation?

Apr 1, 2014

I'm a student designing and developing an Air Traffic Control (ATC) system for incoming aircraft, mainly implementing the part which handles the queuing system for approaching aircraft.

View Replies View Related

CallNumber Method For Bingo Simulation

May 26, 2014

As you may have known, I'm creating a Bingo simulator from scratch.

Precondition: an n amount of randomly generated cards are created.

Postcondition: After a number is called, cards that has that number will have its value be true.

For example:

Precondition

Java Code:

Card 1 //Name of card

1 24 32 48 63
2 22 41 51 64
3 16 37 52 61
4 19 33 57 72
5 20 34 54 71 //Card with numbers

false false false false false
false false false false false
false false false false false
false false false false false
false false false false false //Card with boolean values to indicate marked values

[Code] .....

So what I want to do is have a method that allows me to use the callRandomNumber method so that the matrix location with that random value is marked true for all of the boards.

View Replies View Related

Traffic Light Simulation Using Multithreading

Feb 2, 2015

I am writing a simple program to simulate a traffic light. What I want is to make them glow after each 1 second, one by one. For example: Firstly Red, then after 10 seconds, red will be put to off and yellow will start glowing and then accordingly green. This process shall continue incessantly (Just for experimental purpose). I have some arrangement done but could not figure out how to put them together in run() method of Runnable interface. I know how interthread communication works. But could not find any logic in this case when three threads will run together.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TrafficLight extends JFrame implements Runnable
{
JButton red, green, yellow ;
TrafficLight()

[Code] .....

View Replies View Related

Simple 2D Optics Simulation Program

Sep 13, 2014

I'm very new to Java (I literally started learning it yesterday) and I've been working on a simple program that's meant to simulate interactions between optics objects and light rays.

Everything has been going really well, except that my mirrors only reflect the first ray that comes in contact with them.

Here's a screenshot : 2014-09-13 at 7.39.23 PM.jpg

I wrote 7 classes:

Main class to create the optics objectOptics class. the most important class that uses a recursive function to detect the nearest intersection point of a ray with the nearest optics object. It then calculates a reflected ray and inputs it back into the function until no intersections are found or the max recursion depth is met.Ray. creates a rays (in parametric form O + tD where O is the origin, D is the direction and t is a non-negative scalar)Object. empty abstract class used for polymorphism (so when i add more optics objects like prisms and lenses they'll share the object type)Mirror. Basically a line segment created with the Line classLine. Creates a line segmentDraw. JComponent with paintComponent function that loops through an array of shapes and draws them to the screen.

What I know so far is that the problem boils down to the checkRay() function in the Optics class. When a mirror has already reflected a ray, the line:

Intersection sec = new Intersection(ray,(Mirror)obj);

creates an intersection with a null point.

I debugged it line by line and found the problem was that my variable 't' (that is the parameter for the parametric line which represents the mirror) in the Intersection class got big values when it's meant to be between 0 and 1 (since it's a line segment), which resulted in the function returning null (as it should when 't' is not between 0 and 1).

I've confirmed with tests that this has nothing to do with the specific mirror or angle of incidence. It only occurs when a mirror has already been intersected with by a ray.

I've found out that my function:

public PVector getNormal(PVector D){
D.normalize();
return new PVector(D.y,-D.x);
}

Changes the value of the 'D' PVector of the mirror inside my 'objects' ArrayList. How can it access the private PVector 'D' from outside the Mirror class? This normalization to the direction vector is what causes the Intersection class to return null the second time around!

The problem was that in the getNormal function, the input vector argument was a reference to the 'D' vector for the mirror in my 'objects' ArrayList so the .normalize() function acted upon the original vector, changing it's value and screwing things up. The two classes I talked about:

Optics: (note line 64. this line returns a null intersection when it shouldn't)

package ofer.davidson;
 import java.util.ArrayList;
 public class Optics {
 //Arrays to store all the optics objects and rays that are created
ArrayList<Object> objects;
ArrayList<Ray> rays;
 
[Code] .....

Also why doesn't my background turn white??

View Replies View Related

Elevator Simulation In Event Time Not Clock

Apr 10, 2014

I am making a elevator simulator for my class. It needs to be "event time". I am having trouble understanding how I can make an "event time" simulator. Initially I was using a while loop to run a clock time simulation of x seconds for each event, until I ran into a concrete wall and had to call another method which took X seconds, while still needing to execute code.

An example of what I did is:

Spawn person -> person.goToElevator (Takes x seconds) - > person.waitForElevator (Until elevator arrives, x seconds). While this is happening, I needed to create another person and do the same thing, this will add another to the queue if the first person is still waiting. Etc etc, you get the point.

We have not learnt about multi threading, that is the next assignment.

Here is a quote from my lecturer:

"That's right, it requires multi-threading which we're not doing in this paper. Here's a solution that can work:

The person waiting for the lift and then doing lots of other things should do all that in a fraction of a second. So, you don't let the person really wait. Instead, you will set a timestamp in the future in the person object that "he's busy till that time". In all other steps in your simulation you will first check if a person is "busy" (i.e. has a timestamp in the future). If so, you can't use this object, otherwise, you can.

How does it create a bigger queue? Outputs I would have in my final simulation would be, averageQueueLength, numOfPeopleInBuilding etc.

View Replies View Related

Create 2D Game That Has Realistic Space Simulation

Jul 31, 2014

I am attempting to create a 2d game that has a realistic space simulation. The map is supposed to be set so that you are looking from the top down. The problem I am having exists in my interaction between the sun and a planet. Simply put, the planet will only move in a single diagonal direction without ever changing direction. The formulas I am using are F=(G*M1*M2)/D^2 and A=F/M. The code below is simplified.

(inside planet Class)
double x;
double y;
double mass;
double xForce;
double yForce;
double xAccel;
double yAccel;

[Code] ....

Things I have already tried:
1. Setting G to negative
2. changing the order of the subtraction in determining D
3. some weird pythagorean theorem thing someone suggested

View Replies View Related

FIFO Queue - Waiting Line Simulation

Jan 22, 2015

how to setup a program that simulates the progression of a line over time.The scenario involves a bank and 5 tellers. There is one line of customers that starts off with an initial length of 20. Every minute, 10 more customers are added to the line. As this is meant to be a FIFO queue the first 11 customers in the line will be distrusted among the 5 bank tellers as follows: Teller #1 will process 1 customer per minute, Teller #2 and #3 can each process 2 customers per minute, and Teller #4 and #5 can each process 3 customers per minute. Therefore, the first 11 customers in line will be processed within the first minute of the programs execution.

Unfortunately, I am not sure how to attack this thing. I am thinking that I need to setup a queue for the initial 20 customers and an array for the 10 customers that will be joining the line every minute. However, I am not sure how I can set this up to work automatically.

View Replies View Related

Instantiate 3 Instances Of Retail Item

Apr 5, 2014

I need instantiating 3 instances of the RetailItem

//Instantiate 3 RetailItems
RetailItem jacket = new RetailItem(); ITS TELLING ME: constructor RetailItem in class RetailItem cannot be applied to given types
jacket= jacket.setDescription("Jacket"); <------- ITS TEllING ME: cannot find symbol
jacket = jacket.setUnitsOnHand(12);
jacket = jacket.setPrice(59.95);

[Code] ....

View Replies View Related

Bank Account Simulation - ResultsModel Cannot Resolve To A Type

Mar 12, 2015

I have serious errors. I am trying to design a Bank Account Simulation. My various codes are as below.

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import java.io.*;
public class Display2 extends JFrame //implements ActionListener

[Code] ....

ERROR: ResultsModel cannot be resolved to a type

View Replies View Related

Swing/AWT/SWT :: Traffic Simulation - Applet Not Initialized Error

Mar 25, 2006

I have a traffic simulation code that is producing a start:applet not initialized error each time i run it. This is the code

import java.io.InputStream;
import java.net.URL;
import java.util.*;
import java.awt.*;
import java.applet.Applet;
import java.lang.Thread;
class Node {

[Code] ....

View Replies View Related

All Instances Of Same Class Change Each Other Private Variable

May 2, 2015

I have a class named Base and a private variable named _hopcount i have 10 instances of class base i use _hopcount as creteria to some if but other instances edit _hopcount so i want to prevent _hopcount edit by other instances; I want to have private variable which other instances of same class can't modify it.

public class Base extends TypedAtomicActor {
private int _hopcount = 0;
if(_hopcount <= 3) {
some code;
}
public function() {
_hopCount += 1;
}
}

View Replies View Related

Static Methods Preventing Usage Of Instances?

Jun 17, 2014

Declaring the method as static precludes one from using any sort of object oriented programming, thus the method cannot access instance fields of the object if it needs to.

I created two short classes to sort of find out what this meant, but I feel I do not understand it well enough.

Test class (main):

package votek; 
public class Test {
 public static void main(String[] args) {
SomeMethod();
}
 public static void SomeMethod() {
Character character = new Character();
character.totalLevel = 50;
 System.out.println(character.totalLevel);

}

Character class:

package votek; 
public class Character {
private int level = 0;
 public Character() {
level = 50;
}
 }

OR

Does it mean that making a static method in the class with private instances will prevent the method from using the private instances?

View Replies View Related

Instances Of Objects In Java Versus Other Languages

May 22, 2015

I am learning JAVA and understanding some of its specific oddities. For example I notice that JAVA loves instances but not variables.

In Python:
x = 1
y = 2
print(x,y)
yields (1,2)

then I do y = x and print
getting (1,1)

This makes sense to me since x and y are variables and thats how variables work. In JAVA I notice this script:

public class TESTRUN {
public static void main(String[] args) {
int x = 0;
int y = x;
System.out.printf("x = %d, y = %d %n", x, y);
x = 9;
System.out.printf("x = %d, y = %d", x, y);
}
}

This yields:
x = 0, y = 0
x = 9, y = 0

So I get that JAVA doesn't understand variables? Or only takes instances of variables? Is there any way to yield a true variable or you always have to update variable relationships?

View Replies View Related

Use Data Read From File To Create Instances?

Sep 10, 2014

"Write a program (save the program as ProductInventory.java) that will read data about 5 products from a text file (Products.txt. The program should use the data read from the file to create instances (objects) of Product.java(Use Product class as a Reference Type)."

I'm yet to discover how I will get the info from the textfile using scanners but I don't know how to "create instances of a reference type".

This is the code of Product.java that came with the exercise.

public class Product {
private String productCode = "";
private String productName = "";
private int quantity;
private String supplierName = "";
private String supplierAddress = "";
private double price;

[Code] .....

By the way, the exercise also required me to use the abstract class ProductLister. To be clearer, the text file is kinda like this:

54643
Rizer Mouse
Mark5s Merchandising
Marquee Mall
4
205.50
23412
Acer Ultrabook
JohnJade Merchandise
Cornal City
2
62200.00
93112
Dell Ultrabook
Octagon Marketing
Cornal City
3
68900.00
22126
Macbook Air Pro
Computerware Services
San Beda, Chad
2
93500.00

View Replies View Related

Driver Program That Creates 2 Instances Of A Class?

May 10, 2014

public class Car
{
//instance variables ----------------------
private String make;
private String model;
private int year;
private double vehiclePrice;
private double downPayment;
private double milesPerGallon;

[code]....

I created this class "Car" (also not sure if it's correct) and need to write a driver program that creates two instances of the class Car. One must use the default constructor, and the other must use the non-default constructor. It must demonstrate the methods used in the Car class using those instances.

public class DriverCar
{
public static void main(String[] args) {
Car car1 = new Car("Toyota", "Corolla", 2013, 20000, 3000, 35);
Car car2 = new Car("Ford", "Taurus", 2005, 14000, 1500, 25);
System.out.println(car1);

[Code] ....

View Replies View Related

Use Applet To Create Two Instances Of Employee Class

Jan 9, 2014

What I have to do: Use Applet to create two instances of the Employee class. Display the data on the Graphics object. Display in the applet the names and values of all of the instance variables in each instance of the class. Also display the value of any static variables.

What I'm doing:

import java.applet.Applet;
import java.awt.*;
public class EmployeeApplet extends Applet {
public static int topSalary = 195000;
int hoursPerWeek;
public static void setTopSalary (int s) {
if (s > topSalary)

[Code]...

I'm not able to display hours per week for e1 and e2.

View Replies View Related







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