Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package calculator;
- import java.util.Scanner;
- public class AerospaceCalculator {
- static String height;
- static String temperature;
- static String pressure;
- static String density;
- static String whatToFind;
- public static void main(String[] args) {
- Scanner reader = new Scanner(System.in);
- System.out.println("Thanks for using Andrew's Aerospace Calculator Version 2.0");
- System.out.println("For the following inputs, either give a number or put 'unknown'");
- System.out.println("Also, please round decimals to the nearest hundredth or add zeros so that you have hundredths.");
- System.out.println("What is the height in meters?");
- height = reader.next();
- System.out.println("What is the temperature in degrees celsius?");
- temperature = reader.next();
- System.out.println("What is the pressure in kPa?");
- pressure = reader.next();
- System.out.println("What is the density in kg/m^3?");
- density = reader.next();
- System.out.println("What would you like to find? (Enter a number)");
- System.out.println("1) Temperature");
- System.out.println("2) Pressure");
- System.out.println("3) Density");
- whatToFind = reader.next();
- switch(whatToFind) {
- case "1":
- System.out.println("Calculating Temperature...");
- findTemp();
- System.out.println("Temperature is: " + temperature);
- break;
- case "2":
- System.out.println("Calculating Pressure...");
- findPressure();
- System.out.println("Pressure is: " + pressure);
- break;
- case "3":
- System.out.println("Calculating Density...");
- findDensity();
- System.out.println("Density is: " + density);
- break;
- default:
- System.out.println("That input was not a number or wasn't recognized. Please try again.");
- break;
- }
- }
- public static void findTemp() {
- if(height == "unknown"){
- System.out.println("You cannot find temperature without height.");
- } else {
- double temp = Double.parseDouble(height);
- double hite = Double.parseDouble(temperature);
- temp = 15.04 - (0.00649 * hite);
- temperature = Double.toString(hite);
- }
- }
- public static void findPressure() {
- if(temperature == "unknown"){
- findTemp();
- } else {
- double press = Double.parseDouble(pressure);
- double temp = Double.parseDouble(temperature);
- press = 101.29 * (Math.pow((temp + 273.1) / (288.08), 5.256));
- pressure = Double.toString(press);
- }
- }
- public static void findDensity() {
- if(pressure == "unknown") {
- findPressure();
- } else {
- double dens = Double.parseDouble(density);
- double press = Double.parseDouble(pressure);
- double temp = Double.parseDouble(temperature);
- dens = press / (0.2869 * (temp + 273.1));
- density = Double.toString(dens);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment