Question

In: Computer Science

For each problem below, write a java program to solve it, name your programs as PA2_1.java...

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

Solutions

Expert Solution

/* 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.")
   }
   }
}


Related Solutions

Java Palindrome (Timelimit: 10seconds) Problem Description Write a Java program to solve the following problem. A...
Java Palindrome (Timelimit: 10seconds) Problem Description Write a Java program to solve the following problem. A palindromic number is an integer that is the same when the digits are reversed. For example, 121 and 625526 are palindromic, but 625 is not a palindromic number. Input: The input is in ‘palindrome.txt’. The first line of the input contains the line count m (1 ≤ m ≤ 1,000), which is the number of lines that follows the first line. Each of the...
Java Recursion (Timelimit: 3 seconds) Problem Description Write a Java program to solve the following problem....
Java Recursion (Timelimit: 3 seconds) Problem Description Write a Java program to solve the following problem. Recursion may appear in various contexts and in different forms. For fast implementation, we should always aim at transforming recursions into a simpler form of computation. In this assignment, the task is to evaluate X(·), which is defined as follows:               |0,if m = 0 or n = 0               | X(m,n−1),if n is odd and m is even X(m,n) = | X(m−1,n),if m...
Using jGRASP, write a Java program named LastnameFirstname10.java, using your last name and your first name,...
Using jGRASP, write a Java program named LastnameFirstname10.java, using your last name and your first name, that does the following: Create two arrays that will hold related information. You can choose any information to store, but here are some examples: an array that holds a person's name and an array that hold's their phone number an array that holds a pet's name and an array that holds what type of animal that pet is an array that holds a student's...
Using jGRASP, write a Java program named LastnameFirstname09.java, using your last name and your first name,...
Using jGRASP, write a Java program named LastnameFirstname09.java, using your last name and your first name, that does the following: Declare an array reference variable called myFavoriteSnacks for an array of String type. Create the array so that it is able to hold 10 elements - no more, no less. Fill the array by having each array element contain a string stating one of your favorite foods/snacks. Note: Only write the name of the snack, NO numbers (i.e. Do not...
Java Collatz Conjecture (Timelimit: 3 seconds) Problem Description Write a Java program to solve the following...
Java Collatz Conjecture (Timelimit: 3 seconds) Problem Description Write a Java program to solve the following problem. The Collatz conjecture is about a sequence: start with any positive integer n. Then each term is obtained from the previous term as follows: if the previous term is even, the next term is one half the previous term. If the previous term is odd, the next term is 3 times the previous term plus 1. The conjecture is that no matter what...
Write a program ( Java) to solve the 8-puzzle problem (and its natural generalizations) using the...
Write a program ( Java) to solve the 8-puzzle problem (and its natural generalizations) using the A* search algorithm. The problem. The 8-puzzle problem is played on a 3-by-3 grid with 8 square blocks labeled 1 through 8 and a blank square. Your goal is to rearrange the blocks so that they are in order. You are permitted to slide blocks horizontally or vertically into the blank square. The following shows a sequence of legal moves from an initial board...
Write a complete Java Program to solve the following problem. February 18 is a special date...
Write a complete Java Program to solve the following problem. February 18 is a special date as this is the date that can be divisible by both 9 and 18 Write a program that asks the user for a numerical month and numerical day of the month and then determines whether that date occurs before, after, or on February 18. If the date occurs before February 18, output the word Before. If the date occurs after February 18, output the...
In JAVA Write a brief program that writes your name to a file in text format...
In JAVA Write a brief program that writes your name to a file in text format and then reads it back. Use the PrintWriter and Scanner classes.
In Java language. Write a brief program that writes your name to a file in text...
In Java language. Write a brief program that writes your name to a file in text format and then reads it back. Use the PrintWriter and Scanner classes.
Write a complete Java program to solve the following problem. Read two positive integers from the...
Write a complete Java program to solve the following problem. Read two positive integers from the user and print all the multiple of five in between them. You can assume the second number is bigger than the first. For example if the first number is 1 and the second number is 10, then your program should output 5 10 Java must be grade 11 work easy to understand and not complicated code
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT