Guest User

AerospaceCalculator

a guest
Sep 8th, 2014
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.78 KB | None | 0 0
  1. package calculator;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class AerospaceCalculator {
  6.  
  7. static String height;
  8. static String temperature;
  9. static String pressure;
  10. static String density;
  11. static String whatToFind;
  12.  
  13. public static void main(String[] args) {
  14.  
  15. Scanner reader = new Scanner(System.in);
  16.  
  17. System.out.println("Thanks for using Andrew's Aerospace Calculator Version 2.0");
  18.  
  19. System.out.println("For the following inputs, either give a number or put 'unknown'");
  20. System.out.println("Also, please round decimals to the nearest hundredth or add zeros so that you have hundredths.");
  21.  
  22. System.out.println("What is the height in meters?");
  23. height = reader.next();
  24.  
  25. System.out.println("What is the temperature in degrees celsius?");
  26. temperature = reader.next();
  27.  
  28. System.out.println("What is the pressure in kPa?");
  29. pressure = reader.next();
  30.  
  31. System.out.println("What is the density in kg/m^3?");
  32. density = reader.next();
  33.  
  34. System.out.println("What would you like to find? (Enter a number)");
  35. System.out.println("1) Temperature");
  36. System.out.println("2) Pressure");
  37. System.out.println("3) Density");
  38. whatToFind = reader.next();
  39.  
  40. switch(whatToFind) {
  41.  
  42. case "1":
  43. System.out.println("Calculating Temperature...");
  44. findTemp();
  45. System.out.println("Temperature is: " + temperature);
  46. break;
  47. case "2":
  48. System.out.println("Calculating Pressure...");
  49. findPressure();
  50. System.out.println("Pressure is: " + pressure);
  51. break;
  52. case "3":
  53. System.out.println("Calculating Density...");
  54. findDensity();
  55. System.out.println("Density is: " + density);
  56. break;
  57. default:
  58. System.out.println("That input was not a number or wasn't recognized. Please try again.");
  59. break;
  60.  
  61. }
  62.  
  63.  
  64.  
  65. }
  66.  
  67. public static void findTemp() {
  68.  
  69. if(height == "unknown"){
  70. System.out.println("You cannot find temperature without height.");
  71. } else {
  72. double temp = Double.parseDouble(height);
  73. double hite = Double.parseDouble(temperature);
  74. temp = 15.04 - (0.00649 * hite);
  75. temperature = Double.toString(hite);
  76. }
  77.  
  78. }
  79.  
  80. public static void findPressure() {
  81.  
  82. if(temperature == "unknown"){
  83. findTemp();
  84. } else {
  85. double press = Double.parseDouble(pressure);
  86. double temp = Double.parseDouble(temperature);
  87. press = 101.29 * (Math.pow((temp + 273.1) / (288.08), 5.256));
  88. pressure = Double.toString(press);
  89. }
  90.  
  91. }
  92.  
  93. public static void findDensity() {
  94.  
  95. if(pressure == "unknown") {
  96. findPressure();
  97. } else {
  98. double dens = Double.parseDouble(density);
  99. double press = Double.parseDouble(pressure);
  100. double temp = Double.parseDouble(temperature);
  101. dens = press / (0.2869 * (temp + 273.1));
  102. density = Double.toString(dens);
  103. }
  104.  
  105. }
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment