I'm writing code to determine the state of water with if statements

1.8k Views Asked by At

I'm writing code to determine the state of water depending on the temperature in celsius and altitude, how can I make it so at the end, if the altitude is more than 300, it takes 1 less degree celsius for the water to boil and the outcome can be determined depending on the input?

import java.util.Scanner;

public class WaterState
{       
    public static void main(String[] args)
    {
        boolean run = true;
        while(run)
        {
            Scanner scan = new Scanner(System.in);

            System.out.println("What is the temperature in degrees Celsius?");
            double temp = scan.nextDouble();
            System.out.println("What is the height above Sea level? in exact meters");
            double altitude = scan.nextDouble(); 

            int freezingPoint = 0;
            double alternateAltitude = temp - (altitude * 0.001);
            double boilingPoint = 100;
            int baseAltitude = 300;

            if ((temp <= freezingPoint) && (altitude <= baseAltitude))
            {
                System.out.println("Water is frozen");
            }
            else if ((temp > freezingPoint) && (altitude <= baseAltitude))
            {
                System.out.println("Water is liquid");
            }
            else if ((temp >= boilingPoint) && (altitude <= baseAltitude))
            {
                System.out.println("Water is gaseus");
            }

            else if ((altitudeChange > )
            {  

                System.out.println("Water is boiling, but at a lower temperature because of the altitude");

        }
    }
}
}
1

There are 1 best solutions below

0
On

Here is what is relative to your question:

        else if ((altitudeChange > ){ 
            System.out.println("Water is boiling, but at a lower temperature because of the altitude");
        }

And according to your input:

if the altitude is more than 300, it takes 1 less degree celsius for the water to boil and the outcome can be determined depending on the input

Is this is what you want:

if(altitude >=baseAltitude  && temp>(boilingPoint -(altitude/baseAltitude *1)) ){//1.altitude is more than 300,2.temp is higher than the new degree celsius to boil 
 System.out.println("Water is boiling, but at a lower temperature because of the altitude");
}