Advertisement
sudoaptinstallname

Untitled

Jan 17th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.util.Scanner;
  4.  
  5.  
  6. /*
  7. Amon Guinan
  8. Thursday, January 2019
  9.  
  10. Program interprets User input temperature.
  11. Outputs predicted season.
  12. */
  13. public class Season_Finder2 {
  14. public static void main(String[] args) {
  15.  
  16. Scanner input = new Scanner(System.in);
  17.  
  18. System.out.print("Input Valid Temperature (-5,110): ");
  19.  
  20. String tempStr = input.nextLine();
  21.  
  22. //Must be declared outside of try block
  23. int tempInt = 0;
  24.  
  25. /*
  26. What if the user inputs a word or sentence?
  27. We need to return a pretty error message and not have the program stop without explaining the issue...
  28. */
  29. int x = 0;
  30. try{ //tries code that may fail without stopping program.
  31. tempInt = Integer.parseInt(tempStr);
  32. //Catches all NumberFormatExceptions but not other errors
  33. } catch(NumberFormatException e) {
  34. //Fix problem
  35. x = 1;
  36. }
  37. if(x == 1) // returns error message.
  38. {
  39. System.out.println("Input a number.");
  40. System.exit(2);
  41. }
  42.  
  43. if((tempInt < (-5))||(tempInt > (110)))
  44. {
  45. System.out.print(tempInt+" degrees is outside valid range.");
  46. }
  47. if((tempInt >= (-5))&&(tempInt < (50)))
  48. {
  49. System.out.print("Winter. "+tempInt+" degrees.");
  50.  
  51. }
  52. if((tempInt >= (50))&&(tempInt < (70)))
  53. {
  54. System.out.print("Fall. "+tempInt+" degrees.");
  55.  
  56. }
  57. if((tempInt >= (70))&&(tempInt < (90)))
  58. {
  59. System.out.print("Spring. "+tempInt+" degrees.");
  60.  
  61. }
  62. if((tempInt >= (90))&&(tempInt <= (110)))
  63. {
  64. System.out.print("Summer. "+tempInt+" degrees.");
  65.  
  66. }
  67.  
  68.  
  69.  
  70.  
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement