# diving distance program

• 04-05-2012, 03:09 AM
maximumammo
diving distance program
Ok so I had to write a program that displays increase in pressure per every 100 meters up to X meters based on the density of the water as we go down. X is the diving distance that needs to be read from the keyboard. Pressure increase rate per 100 meters for various water densities are given below
Level 1 : 20 per 100 meters
Level 2 : 30 per 100 meters
Level 3 : 50 per 100 meters

it should look like this :

Please enter the density level : 1
Please enter the diving distance X (in meters): 300

Pressure increase after 100 meters : 20
Pressure increase after 200 meters : 40
Pressure increase after 300 meters : 60

PROBLEM::::: Ok so this is probably a simple question but how do I get pI(pressure increase) to change with the depth? i.e at 100 m pI is 20, at 200 m pI is 40

Code:

``` import java.util.Scanner; public class Lab8 {         public static void main(String[] args) {         Scanner scan = new Scanner(System.in); int densityLevel; double divingDistance, pI = 0; System.out.println("Welcome"); System.out.println(" Please enter the density level :"); densityLevel = scan.nextInt(); System.out.println("Please enter the diving distance X (in meters) : "); divingDistance = scan.nextDouble(); int count = 100; while (count <= divingDistance) {          if ( densityLevel ==1 ) {         pI = 20;    System.out.println(" Density Level : " + densityLevel);  System.out.println(" Diving Distance : " + divingDistance);  System.out.println( " Preassure increase after " + count + " meters is " + pI);  count += 100;           } else if (densityLevel ==2)        {         pI = 40;         System.out.println(" Density Level : " + densityLevel);         System.out.println(" Diving Distance : " + divingDistance);         System.out.println( " Preassure increase after " + count + " meters is " + pI);         count += 100; }         else if (densityLevel == 3) {         pI = 60;         System.out.println(" Density Level : " + densityLevel);         System.out.println(" Diving Distance : " + divingDistance);         System.out.println( " Preassure increase after " + count + " meters is " + pI);         count += 100;         } } } }```
• 04-05-2012, 06:27 AM
Junky
Re: diving distance program
Quote:

Originally Posted by maximumammo
PROBLEM::::: Ok so this is probably a simple question but how do I get pI(pressure increase) to change with the depth? i.e at 100 m pI is 20, at 200 m pI is 40

Are you serious? Even a blind person can see the relationship between depth and pressure. What happens to the pressure every 100 metres?
• 04-05-2012, 06:29 PM
maximumammo
Re: diving distance program
no sh*t sherlock, I understand how it works, im not using this forum because I have trouble with basic math Im using it because I am new to JAVA. My question, is how do you express that in JAVA terms. Thanks for your helpful reply
• 04-05-2012, 08:00 PM
DarrylBurke
Re: diving distance program
Quote:

Originally Posted by maximumammo
My question, is how do you express that in JAVA terms.

First off, the word is Java, not JAVA. It's not an acronym.

Check out the tutorial on Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)

db
• 04-05-2012, 08:09 PM
maximumammo
Re: diving distance program
Quote:

Originally Posted by DarrylBurke
First off, the word is Java, not JAVA. It's not an acronym.

Check out the tutorial on Operators (The Java™ Tutorials > Learning the Java Language > Language Basics)

db

Thank you, and I know it is not "JAVA" I was using that for emphasis on the term and understand it is not an acronym. Thanks again and I will check out the link