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


ADVERTISEMENT

User Input In Miles And It Is Supposed To Multiply With Feet

Sep 21, 2014

I have a program where the user enters in the miles and then it is supposed to get multiplied by feet but I keep getting this error.

GetUserInfo.java:12: error: bad operand types for binary operator '*'
int total = name * feet;
^
first type: String
second type: int

1 error

This is my code so far :

import java.util.Scanner;
public class GetUserInfo
{
public static void main(String[] args) {
String name;
int miles;

[Code] ....

View Replies View Related

Calculate Shipping Charges Based On Product Weight In Pounds And Distance In Miles

Mar 26, 2014

I want to write a Utility to calculate the shipping charges based on the product weight in pounds and distance in miles. How we can go about it.

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

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

Method Parameters - Two Fields Of Type Double / Calculate Distance To Another Point

Oct 18, 2014

I've just been having a go at an exercise where I have to create and use a class called Point, with two fields of type double. I have to create some methods for it, one of which is a distanceTo(Point) method, that calculates the distance to another point. I've tried to keep the distanceTo(Point) method short so have created some other methods to use within the method. My question is about the getDistance() method that I've made. As you can see below, I've given it two parameters, which are references to values within two Point objects (this.x and otherPoint.x).

double distanceTo(Point otherPoint) {
double distanceX = getDistance(this.x, otherPoint.x);
double distanceY = getDistance(this.y, otherPoint.y);
return calculateLength(distanceX, distanceY);
}

View Replies View Related

Program To Find Miles Per Gallon

Jan 23, 2015

I have to write a program the calculates the MPG and display's the result on the screen. However, I have three errors I just can't seem to figure out. jGrasp points to the following error, but doesn't tell me what it is:

Programming Challenge #9.java:34: error: cannot find symbol
gallons = keyboard.nextInt();
^
symbol: variable keyboard
location: class MPG
3 errors
 
----jGRASP wedge2: exit code for process is 1.
----jGRASP: operation complete.

My code is as follows:

import java.util.Scanner;
 /*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
 
// This program has variable of several of the integer types.
 public class MPG {
public static void main(String[] args) {

[Code] ....

View Replies View Related

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

Print Out Two Different Tables One For Feet To Meters And Other From Meters To Feet

Feb 19, 2015

I can get this program to run and compile, however, upon printing, I have the lastnumber from each table printing on the next line under their respective tables.

public class Lab6 {
public static void main(String[] args) {
double foot = 0;
double meter = 0;
System.out.println(" Feet Meters");
System.out.println(footToMeter(foot));

[Code]...

and what it prints is this:

Feet Meters
1.0 0.31
2.0 0.61
3.0 0.92
4.0 1.22
5.0 1.53
6.0 1.83
7.0 2.14
8.0 2.44
9.0 2.75
10.0 3.05
3.05

Meters Feet
20.0 65.57
25.0 81.97
30.0 98.36
35.0 114.75
40.0 131.15
45.0 147.54
50.0 163.93
55.0 180.33
60.0 196.72
65.0 213.11
213.11475409836066

how do i get rid of the last 3.05 and 213.114754...?

View Replies View Related

Constructs And Initializes A Point With Same Location As Specified Point Object

Jun 5, 2014

I was reading the oracle java tutorial under: URL....Here's the code for the Point class:

public class Point {
public int x = 0;
public int y = 0;
//constructor
public Point(int a, int b) {
x = a;
y = b;
}
}

and in the Rectangle class you have the following constructor:

public Rectangle(Point p, int w, int h) {
origin = p;
width = w;
height = h;

If we create a new Point object like this:

Point originOne = new Point(23, 94);

and then a new Rectangle object like this:

Rectangle rectOne = new Rectangle(originOne, 100, 200);

Will that set originOne to point to the object Point at (23, 94). just want to make that this is the meaning of this statement: Point(Point p)Constructs and initializes a point with the same location as the specified Point object.

View Replies View Related

Output Error About Converter (Miles / Kilometer)

Nov 28, 2014

I'm doing to create miles/kilometers converter. If I put the mile, converting to kilometer is right. However, if I put the kilometer, converting to mile comes out wrong value. Which part is wrong?

import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;

[Code] .....

View Replies View Related

Write A Program That Display Miles And Kilo

Apr 21, 2014

1. Write a program that displays the following table (note that 1 mile is 1.609 kilometer):

Miles Kilometers
1 1.609
2 3.218
3 4.827
...
...
9 14.481
10 16.090

Note: use for loop and printf() to format your output

public class MilesandKilometers {
public static void main(String[] args) {
System.out.println("Miles Kilometers");
int miles = 1
;
for (int i = 1; i <= 10; miles++, i++) {
System.out.println(miles + " " + miles * 1.609);
}
}
}

how to make it like the instruction said " use for loop and printf() to format your output".

View Replies View Related

Feet To Meters And Display Result

Dec 3, 2014

I have to do feet to meters code. here is the question. Write a Java program that reads a number in feet, converts the number to meters and displays the result. One foot is 0.305 meters.

here is my code :

import java.io.*;
class FeetToMeters
{
public static void main (String[] args) throws IOException
{
InputStreamReader inStream = new InputStreamReader (System.in);
BufferedReader stdin = new BufferedReader (inStream);

[Code] ....

I have seen alot of people use the scanner tool for the start of it but we never learned it as it is an online course but we may end up learning it farther on in our java programming. we have just started with the input and output stuff.

View Replies View Related

Converting Meters To Feet - How To Print Decimals

Oct 1, 2014

I am making a small program that converts meters to feet. I want my answer to be printed with 2 decimals, but I am struggle. This is my current code, any takes on what needs to be changed and why?

import java.util.Scanner;
import java.text.DecimalFormat;
public class Chapter2PE3 {
public static void main (String[]args){
Scanner input = new Scanner (System.in);

[Code] ....

View Replies View Related

Calculate Number Of Square Feet In A Tract Of Land With 3.5 Acres

Jan 27, 2014

1. Land Calculation

One acre of land is equivalent to 43,560 square feet. Write a program that calculates the number of square feet in a tract of land with 3.5 acres. Hint: Multiply the size of the tract of land (in acres) by the number of square feet in an acre to get the number of square feet in the tract.

a) You must have a variable called nrAcres where you will store the number of acres in the track.

b) Output must look as follows:

Size of land in acres: 3.5
Size of land in square feet: 152460

c) if the value of the variable nrAcres is changed the output should change accordingly. In other words: it would be wrong to have the following statement:

System.out.println("Size of land in square feet: 152460");

previous statement will print the correct output but will not change if you change the value of nrAcres.

View Replies View Related

Calculate Number Of Square Feet In A Tract Of Land With 3.5 Acres

Jan 27, 2014

Land Calculation

One acre of land is equivalent to 43,560 square feet. Write a program that calculates the number of square feet in a tract of land with 3.5 acres. Hint: Multiply the size of the tract of land (in acres) by the number of square feet in an acre to get the number of square feet in the tract.

a) You must have a variable called nrAcres where you will store the number of acres in the track.
b) Output must look as follows:

Size of land in acres: 3.5 Size of land in square feet: 152460

c) if the value of the variable nrAcres is changed the output should change accordingly. In other words: it would be wrong to have the following statement:

System.out.println("Size of land in square feet: 152460");

previous statement will print the correct output but will not change if you change the value of nrAcres.

this is what i got so far

public class Land
{
public static void main(String[] args){
double nrAcres = 3.5;
int feetInAcre = 43560;
double feetInTract = nrAcres * feetInAcre;
System.out.println("Size of land in acres: " + nrAcres + "
Size of land in square feet: " + feetInTract);
}
}

i tried to compile it but it says

error: class names, Land, are only accepted if annotation is explicitly requested 1 error

what is wrong with my code

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

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

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







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