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


ADVERTISEMENT

Java Time Zone Transition Period From EDT To EST?

Oct 28, 2014

Problem statement: Convert "2014-11-02 01:00:15 EST" to GMT.

This seems easy enough. But why is the below code giving the wrong answer?

Background:

* EDT aka GMT-4

* EST aka GMT-5

* 2014-11-02 01:00:15 EST == 2014-11-02 06:00:15 GMT

* If I user the commented out date string it works!!!

* EDT(until Nov 2, 2014 at 2am) -> at 2am we go to 1am EST

* If I use the below commented out from string it work!!! But these are equal (2014-11-02 01:00:15 GMT-05:00 and "2014-11-02 01:00:15 EST)

Code Example:

ZoneId gmt = ZoneId.of("GMT");
//String from = "2014-11-02 01:00:15 GMT-05:00";
String from = "2014-11-02 01:00:15 EST";
final DateTimeFormatter dateTimeFormatterone = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss z");
ZnedDateTime zonedDateTime = ZonedDateTime.parse(from, dateTimeFormatterone);
ZonedDateTime gmtzonedDateTime = zonedDateTime.withZoneSameInstant(gmt);
String result = gmtzonedDateTime.format(dateTimeFormatterone);

This is what the outcome is.

result == "2014-11-02 05:00:15 GMT"

Shouldn't it be

result == "2014-11-02 06:00:15 GMT"

View Replies View Related

Expire Sending Link To A Mail After Particular Period Of Time

Feb 5, 2011

How to Expire the sending link to a mail after particular period of time

View Replies View Related

Program That Calculates How Much Employees Earn Over A Period Of Time In Months

Oct 5, 2014

i am very new to java programming what i am doing wrong here. Write a program that calculates how much an employee would earn over a period of time (in months), if, every month, the employee’ pay-per-hour rate is one dollar more than the month before (so if his starting perhour rate is 7.25, next month it will be 8.25, next month 9.25, and so on). The employee is going to work 20 hours per week, 4 weeks per month.

The program should input from the user and validate both number of months (which should be a positive integer larger than 0) and the pay-per-hour rate (which should be a floating-point number larger than $7.25 – the minimum federal wage pay-per-hour rate). For each one of these values; if the value is wrong, the program should repetitively ask for that value until the value entered is correct. The program should confirm/output the correct value.

/*
This program calculates how much as employee would earn if every month the employee pay per hour would increase by a dollar
*/
package nick.employee;
import java.util.Scanner;
public class nickemployee {

[Code]...

what i am doing wrong

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

Way To Determine Class Of A Random Anonymous Object?

Jun 20, 2014

Wanted to know Is there any way to determine the class of a random anonymous object?

View Replies View Related

Anonymous Object - Can't Understand One Time Usage Of Object

Aug 18, 2014

Explain anonymous objects with example clearly...i read some where anonymous objects advantage is saving memory...it is benificiable when there is only one time object usage in our program..i can't understand one time usage of object ....i know anonymous objects but i don't know in which context we use them in our programs...i did the anonymous object program with my own example but i can't differentiate this one with normal object..i'm providing my own example below

//anonymous object
public class anonymous {
int x=10;
int y=25;
void display()
{
System.out.println("anomymous");

[code]....

View Replies View Related

Java Convert String Of XML To Document Object Is Null All The Time

Apr 14, 2014

I am trying to parse a XML string into `org.w3c.dom.Document` object.

I have looked at solutions provided [here](xml - How to convert String to DOM Document object in java? - Stack Overflow), [here](How to create a XML object from String in Java? - Stack Overflow) and a few other blogs that give a variation of the same solution. But the `Document` object's #Document variable is always null and nothing gets parsed.

Here is the XML

XMLMappingValidator v = new XMLMappingValidator("<?xml version="1.0" encoding="utf-8"?>
" +
"<mapping>
" +
"<container>
" +
"<source-container>c:stem.csv</source-container>

[Code] ....

When I call
**v.getXML().toString()**
I get
`[#document: null]`

Clearly, the parse is failing. But I don't understand why.

View Replies View Related

How To Create New Customer Object Each Time User Chooses 1 As Option

Feb 17, 2015

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;

public class App {
public static void main(String[] args) throws IOException {
Scanner keyboard = new Scanner(System.in);
System.out.println("Please Select an option > ");

[Code] .....

View Replies View Related

Java Convert String Of XML To Document Object Is Null All The Time

Apr 15, 2014

I am trying to parse a XML string into `org.w3c.dom.Document` object.

I have looked at solutions provided [here](xml - How to convert String to DOM Document object in java? - Stack Overflow), [here](How to create a XML object from String in Java? - Stack Overflow) and a few other blogs that give a variation of the same solution. But the `Document` object's #Document variable is always null and nothing gets parsed.

Here is the XML

Java Code:

XMLMappingValidator v = new XMLMappingValidator("<?xml version="1.0" encoding="utf-8"?>
" +
"<mapping>
" +
"<container>
" +
"<source-container>c:stem.csv</source-container>

[Code] .....

When I call Java Code: **v.getXML().toString()** mh_sh_highlight_all('java');

I get Java Code: `[#document: null]` mh_sh_highlight_all('java');

Clearly, the parse is failing. But I don't understand why.

View Replies View Related

Java Caching System - Set Expire Time For Object Using Predefined Method

Jul 22, 2014

When we are caching an object, how to set expire time for that object by using pre defined methods?

View Replies View Related

Modify Class Time2 To Include Tick Method That Increments Time Stored In Object By One Second

Jul 9, 2014

Modify class Time2 to include a tick method that increments the time stored in a Time2 object by one second. Provide method incrementMinute to increment the minute and method incrementHour to increment the hour. The Time2 object should always remain

a) incrementing into the next minute,

b) incrementing into the next hour and

c) incrementing into the next day (i.e., 11:59:59 PM to 12:00:00 AM).

how to manage case 4 stuff and what's the problem of this CODE.

import java.util.Scanner;
public class Time2Test
{
public static void main( String args[] )
{
Scanner input = new Scanner( System.in );
Time2 time = new Time2();
// input
System.out.println( "Enter the time" );
System.out.print( "Hours: " );
time.setHour( input.nextInt() );

[code]....

View Replies View Related

Servlets :: Can Access Session Object Even Session Is Time Out

Jun 4, 2014

Can I access the session object even session has been expired? I need to check whether session is expired or not for each request.The session invalidation is set null the session object. What I concluded, session time out I can access session object but session invalidation I can not access session object. How can I find the session time out by using session object?

View Replies View Related

Extract Higher-order Bits Of Random Number In Order To Get Longer Period

Mar 1, 2014

One of the random number generators in Java extract the higher-order bits of the random number in order to get a longer period.

I'm not sure if I understand how this is done. Suppose that the random number r = 0000 1100 1000 1101. If we extract the 16 most significant bits from r; is the new number r = 0000 1100 or r = 0000 1100 0000 0000?

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

Military Time - Adding Minutes Displaying Correct Time

Feb 9, 2015

I am working on an assignment that I can't seem to figure out the final part to. The program takes in course data such as the time the class starts and how long it lasts. The time is in military time (0000 - 2400)

I need the output time to be the time the class started, plus the length of the class, and displayed in military time.

for example,

Start Time = 0930
Length = 50 minutes
Endtime = 1020

I can't for the life of me figure out how to do this. I have gotten a program that works for this time and minutes, and displays the correct 1020. But when I change the information to say

Start time: 0700
Length = 90 minutes

I get:

Endtime = 90

90 is technically correct, the way the formula is setup, but I need it to display 0900 not 90.

Here is the code that I have. Be easy, I'm still learning, and this is just the file I created to get the formula to work. Also, the verbose in here is just for my own debugging to make sure values should be what I'm expecting them to be.

public class calc
{
public static void main(String[] args) {
double hours, minutes, length;
double temp;
int time = 2400;
hours = time / 100;
System.out.println("Hours are: " + hours);

[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

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

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

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

Converting Military Time To Standard Time?

Jan 29, 2014

I have two classes. time_runner is used for testing my code.

This is what I'm using to test my code:
 
class time_runner
{
 public static void main(String str[]) throws IOException {
 Time time1 = new Time(14, 56);
System.out.println("time1: " + time1);
System.out.println("convert time1 to standard time: " + time1.convert());
System.out.println("time1: " + time1);
System.out.print("increment time1 five times: ");
time1.increment();

[code]....

The two constructors are "Time()", which is the default constructor that sets the time to 1200, and "Time(int h, int m)" Which says If h is between 1 and 23 inclusive, set the hour to h. Otherwise, set the hour to 0. If m is between 0 and 59 inclusive, set the minutes to m. Otherwise, set the minutes to 0. Those are my two constructors that I pretty much have down. The three methods however I'm having trouble with. The "String toString()" Returns the time as a String of length 4. The "String convert()" Returns the time as a String converted from military time to standard time. The "void increment()" Advances the time by one minute.

public class Time {
private int hour;
private int minute;
  public Time(int h, int m) {
if(h > 1 && h < 23)
hour = h;

[code]....

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







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