Find Out Distance Between Two Trains Using Only Two Commands

May 14, 2014

you need to find out the distance between two trains using only two commands

mf - move forward
mc - move backward

the trains are dropped using helicopter by parachutes . both doesn't know where they are; no gps in the train they are in the same track

write a code to find the trains using the given commands

View Replies


ADVERTISEMENT

Find Distance Between One Point To Another Using Miles And Feet?

Sep 19, 2014

Pretty much what im trying to accomplish, i need to write a program that figures out the distance between one point to another, using miles and feet..

Heres how it has to look: "The distance from my uncles house is ___ miles, or ____ feet."

I can get it to run if i add only whole miles..but when i try to add 8.5 miles, and compile, the program flips out..I know i need to use a double somewhere, but cant figure it out, here is my code..

import java.util.Scanner; //required for input
public class feetToMiles {
public static void main (String[] args){
//Create new scanner object called input
Scanner input = new Scanner (System.in); //allows for input

[Code] ....

View Replies View Related

Dijkstra's Algorithm With Priority Queue - Method To Find Minimum Distance Is Nonfunctional

May 14, 2014

I was given some code by a professor to add some features to as part of an assignment. However, the code itself doesn't seem to work.

import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.Set;
public class DijkstraPriorityQueue

[Code] ....

The method to find minimum distance is nonfunctional...I receive an error that the types are incompatible. I can't do the assignment if the base code doesn't work to begin with...

View Replies View Related

Run Cmd Commands Through Java?

Sep 17, 2014

I would like my application to execute a command in cmd. The command looks like

start "" /D "C:Riot GamesLeague of LegendsRADSsolutionslol_game_client_sln
elease s.0.1.55deploy"
"League of Legends.exe" "8394" "LoLLauncher.exe" ""
"spectator 95.172.65.26:8088 P3hNrXYZlaM3iJ9ximtzJWHbwLhvbimJ 953089676 EUN1"

So my question is how do I do this?

I tried this, (just copy paste the command):

package MyProject;
 import java.io.IOException;
import java.io.InputStream;
 public class Cmd {
 public static void main(String[] args) {
try {
final Process process = Runtime.getRuntime().exec("start "" /D "C:Riot GamesLeague of

[code]....

View Replies View Related

Unix Commands From Windows

Feb 13, 2014

I'm using windows.. and our server is UNIX.. I knew that it's possible to create DOS commands in java programs, I have tried it already..

What I want to know is, is it possible to create a java program (from windows) that can execute UNIX command?

Something like: I have a java program in my windows, and it will create a directory in UNIX server /home/dir..

Based on my research, I can connect to our server in command prompt of my windows using ftp <domain> but the commands there is limited.

View Replies View Related

Sending SMS Through GSM Modem Using AT Commands

Sep 3, 2014

Java code to send sms through gsm modem using AT commands..

View Replies View Related

Website Send Commands Application

May 8, 2014

I have a Java application this application sits on a Dedicated server and gets information about the machine and run commands on the machine.

I need it so that i can run these commands from pressing buttons on a website. For example i press a button to retrieve CPU info, it goes to the app, and the app sends the CPU info back.

I'm fine with the website and app its just the middle bit. How do i get the app to run commands sent from a webpage. Been ratting my brains for a couple weeks now.

View Replies View Related

Inputting Integers For Basic Commands

Jan 27, 2015

I am new to the java computer programming world. i am having basic trouble making the statement full and complete. i am trying to get it to say "The speed of the car is <answer> ft/sec" i have tried reading in the my programming book from school but it doesn't tell me how to fix it. the errors I am getting :

cannot find symbol

I have this error twice ....

View Replies View Related

Create A Java Irc Client Which Responds To Commands

Apr 9, 2015

For a shool assignment i have to create a java irc client. which responds to commands. the !SENDMSG command has two parameters !SENDMSG <username> <the message>.

i can get the username and the message seperated, but i would like to create a check in case someone gives a bad command like: !SENDMSG" " <-- note te extra spaces, or if someone gives only 1 parameter.

else if (line.contains("!SENDMSG")) {
String str = line.split("!SENDMSG")[1]; //gives: <username> <the message>

String[] parts = line.split("s+");

if (parts.length >= 2) {
String user = parts[4]; //gives the <username>

[code]....

View Replies View Related

Run Sudo Linux Commands From Java Program

Apr 6, 2014

I want to find information about running sudo commands from java, but without gksudo/kdesudo.

This is my code. It works, but after removal "sudo" element.

Java Code:

String array[]={"sudo", "dolphin"};
Process proc = null;
try {
proc = Runtime.getRuntime().exec(array);
}
catch (IOException e) {
e.printStackTrace();
} mh_sh_highlight_all('java');

How I can insert password in this terminal? I tried write pass after array with commands and in, and even in outputstream.

View Replies View Related

I/O / Streams :: Not Receiving Correctly SMS Over Length Of More Than A Page Using AT Commands?

May 10, 2014

i m working on the SMS receiving using AT Commands using JAVA. i m getting the message of one page correctly using AT commands, but as i increase the size of SMS as 2, 3 or bigger pages the alphabets are converted to some thing like this

+CMGL: 0,"REC UNREAD","+923028910082",,"14/05/10,19:32:40+20"
4469616C202A3334352A393333232061757220536972662052732E3230206D65696E2
0332064696E206B6120696E7465726E65742028333030204D422920686173696C206B
6172656E21207777772E776170747269636B2E636F6D2070657220736F6E6773206175
722067616D657320656E6A6F79206B6172656E212042616C616E636520636865636B2
06B206C7965202A39393923206D69

Whats the problem i m not getting the right text which i have sent through my mobile phone.

My function of receiving SMS is as follows :

public void send(String cmd) {
try {
outputStream.write(cmd.getBytes());
} catch (IOException e) {
e.printStackTrace();

[Code] .....

View Replies View Related

Program Can Accept Multiple Filter And Sort Commands At One Time

Mar 9, 2014

What I'm supposed to be doing is making it so the program can accept multiple filter and sort commands at one time, and each should be separated by a whitespace.I was thinking about parsing the input again, using whitespace as the delimiter, then normally progressing with each token, as though there was only one command.

However, coding this the way I'm doing it will firstly probably take hours, and secondly, it's likely not even right. I don't have any real way to determine which token contains which data from the Song objects.These are the specific requirements for this portion:A sort/filter command consists of one or more of the following options:

-year:<year(s)>

-rank:<rank(s)>

-artist:<artist>

-title:<title>

-sortBy:<field>

Any number of these options may be given, and they may be given in any order. If multiple options are specified, they will be separated by whitespace.

GazillionSongs Class (the main)
Java Code:
import java.util.*;
import java.io.*;

[code]....

View Replies View Related

Create A Code With Case Commands / Public Is Illegal Start Of Statement

Jul 17, 2014

I'm trying to create a code with case commands but it says that public is an illegal start of statement, What do i do?

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

Distance Formula - Return Value NaN

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

Euclidean Distance In 2D Array

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

Make Distance In Positive Number

Aug 22, 2014

I've been programming for years in a basic programming language, so doing something a bit more advance like this is quite challenging but I love it. where I've gone wrong here? I've been following a tutorial but I've decided to take what I've learned and make my own program but something seems to be wrong.

class Function{
public double abs(int num)
{
if (num > -1)
{
return num;
}
else
{
return -num;

[code]...

Basically trying to get the distance between to numbers but in a positive not negative number.

View Replies View Related

Java Program Method To Calculate Distance

Feb 20, 2015

Write method distance, which calculates the distance between two points (x1, y1) and (x2, y2). All numbers and returned values should be of type double. Incorporate this method into an program that enable the user to enter the coordinates of the points, then calculate and display the distance by calling the method –distance.

I've tried numerous times to make it work and I'm on the right path, however I'm missing some things in the code to make my results look like this later on, which I've attached onto this post.

View Replies View Related

Calculate Distance From Starting Point Of Any Shape

Mar 13, 2015

I need to modify the drawShape method to calculate the distance from the starting point (the diameter) of any shape regardless of how many sides I give it, but I have absolutely no clue where to begin with this. The ultimate goal of the program is to calculate the value of pi using the shape that is drawn.

Here is the code:

public class PiTurtle extends Turtle
{
private double mySize;
private int mySides;
private double diameter = 0; 
final static double startX = 590.0;
final double startY;
public PiTurtle(int nSides)

[Code] .....

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

Determine Distance The Object Falls In Specified Time Period

Apr 3, 2014

When an object is falling because of gravity, the following formula can be used to determine the distance the object falls in a specified time period:

d = 1/2 gt^2

The variables in the formula are as follows: d is the distance in meters, g is 9.8, and t is the amount of time, in seconds, that the object has been falling.

Write a method named FallingDistance that accepts an object's falling time (in seconds) as an argument. The method should return the distance, in meters, that the object has fallen during the time interval. Demonstrate the method by calling it in a loop that passes the values 1 through 10 as arguments, and displays the return value.

import java.util.Scanner;
import java.text.DecimalFormat;
 public class FallingDistance
{
public static void main(String[] args) {
DecimalFormat num = new DecimalFormat("#,###.00");
Scanner keyboard = new Scanner(System.in);
double fallingTime;

[Code] ....

My program runs, but no matter what falling time I enter, I get the same numbers. What am I doing wrong?

View Replies View Related

Java Program - Distance Traveled (Formatting And Decimal Place)

Apr 10, 2014

I'm having trouble formatting my output and issues with the decimal places. Here's my code:

import java.util.Scanner;
import java.text.DecimalFormat; // Imports DecimalFormat class for one way to round
 public class lab3 {
public static void main(String[] args) {
String heading1 = "Hour", heading2 = "Distance Traveled";
int timeElapsed, hour, speed;

[Code] ....

And here's my output (Click on the image since it's pretty small):

javaIssues.png

Issue:
1) The Hours 2 and 3 aren't aligned to 1.
2) The 80 and 120 in Distance Traveled have 6 decimal places when it should not have decimals.

View Replies View Related

Modify DrawShape Method To Calculate Distance From Starting Point

Mar 13, 2015

I need to modify the drawShape method to calculate the distance from the starting point (the diameter) of any shape regardless of how many sides I give it, but I have absolutely no clue where to begin with this. The ultimate goal of the program is to calculate the value of pi using the shape that is drawn.

Java Code:

public class PiTurtle extends Turtle
{
private double mySize;
private int mySides;
private double diameter = 0;

[code]....

View Replies View Related

Pair Of Two Numbers - Return Average / Distance / Maximum And Minimum Value

Sep 27, 2013

I have been having difficulty with the weeks concepts in my online Java class, the program is to be as followed:

For this exercise you will implement a class called Pair, that represents a pair of two numbers.The Pair class should include the following constructor and methods:

CONSTRUCTORS
public Pair(double num1, double num2) -- Creates an object that represents a pair of double values

METHODS

public double getAverage() -- Returns the average value of the two numbers
public double getDistance() -- Returns the absolute vale of the distance between the two numbers
public double getMaximum() -- Returns the maximum value of the two numbers
public double getMinimum() -- Returns the minimum vale of the two numbers

Write a class called PairTest that tests your Pair implementation. The PairTest should prompt the user for the two values, create a Pair object with the values and then print the average, distance, maximum, and minimum of the pair. The input / output should look like the following:

Enter the first number: 5.5
Enter the second number: 3.0

Average: 4.25
Distance: 2.5
Maximum: 5.5
Minimum: 3.0

NOTE: For this exercise, your solution should not use any conditional statements. Instead you should use the methods provided by thejava.util.Math.

So far I have:

import java.lang.Math;
import java.util.Scanner;
public class Main
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
{
System.out.println("Please enter a value for the first number");

[Code] ....

View Replies View Related

Calculate Distance Between Two Coordinates And Determine How Much Of Which Axis To Increment / Decrement

Feb 1, 2015

Basically I'm looking for a way to make one object follow another. For example, if I move object A to one area of the screen I want object B to to move to object A's location but I also want object B to move at a fixed speed (movement variable). How do I go about doing this?

Both the x and y coordinates of object B would need to know the coordinates of object A to calculate the distance between the two and to determine how much of which axis to increment/decrement (if that makes sense?) with the inclusion of the speed variable. In other words I'm just trying to create a homing object.

View Replies View Related

Loop That Calculate Distance Traveled - Why Java Not Printing Method Results

Apr 13, 2014

I am trying to write a loop that calculates the distance traveled (distance = speed * time). It should use the loop to calc how far the vehicle traveled for each hour of time. My program asks for hours and then mph but its not calculating time * speed. Here is my code.

public static void main(String[] args) {
 Scanner input = new Scanner(System.in);
System.out.println("Enter Hours Traveled ");
int hoursTraveled = input.nextInt();
System.out.println("Enter MPH ");
int mph = input.nextInt();
 
[Code] .....

View Replies View Related







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