In: Computer Science
For each problem below, write a java program to solve it, name your programs as PA2_1.java and PA2_2.java.
1. We have a steam heating boiler whose bursting pressure is known, but we of course want to use it only at pressures well below this limit. Our engineers recommend a safety factor of 3; that is, we should never exceed a pressure that is one-third of the rated bursting pressure. Write a java program that reads in the rated bursting pressure and the current pressure, and determines if the boiler is operating at a safe pressure.
For example: Enter the rated bursting pressure of the boiler (psi): 625 Enter the current pressure (psi): 137.8 The maximum safe pressure is 208.3 psi. The current pressure is safe.
or Enter the rated bursting pressure of the boiler (psi): 625 Enter the current pressure (psi): 250 The maximum safe pressure is 208.3 psi. WARNING! The current pressure is not safe.
Hint: Use three variables: burst_psi current_psi, and max_safe_psi
/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is
public. */
class Boiler
{
public static void main (String[] args) throws
java.lang.Exception
{
Scanner sc = new Scanner(System.in); // method of
scanner class to take input and give output
System.out.println("Enter the rated bursting pressure
of the boiler (psi):");
double burst_psi = sc.nextDouble(); // input value for
burst_psi
System.out.println("Enter the current pressure
(psi):");
double current_psi = sc.nextDouble(); // input value
for current pressure
double max_safe_psi = burst_psi/3; // as given in
question calculated max safe burst psi
if(current_psi<= max_safe_psi){
// if current pressure is less or equal to max safe burst then
giving output pressure is safe
System.out.println("The current
pressure is safe");
}
else {
// if current pressure is greater than max safe burst then
giving output pressure is not safe
System.out.println("WARNING! The
current pressure is not safe.")
}
}
}