Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. // -------------------------------------------------------
  2. // Assignment 2
  3. // Written by: Kewen Liang - 40129628
  4. // For COMP 248 Section EC – Fall 2019
  5. // -------------------------------------------------------
  6.  
  7. //Question 1. Converting an integer (1-12) to the appropriate Persian month using if/else statements.
  8.  
  9. import java.util.Scanner;
  10. public class Assign2Q1ifelse {
  11.  
  12. public static void main(String[] args) {
  13. //Store months into arrays for easy use.
  14. String[] months = {"Farvardin", "Ordibehesht", "Khordad", "Tir", "Mordad", "Shahrivar", "Mehr", "Aban", "Azar", "Dey", "Bahman", "Esfand"};
  15. //String[] seasons = {"Keep warm Yourself in Winter", "Happy Spring", "Have Fun in Summer", "Ready For Fall"};
  16. String season = "";
  17. int monthnumber;
  18. Scanner input = new Scanner(System.in);
  19. System.out.print("Please enter the Month as a number 1-12: ");
  20. monthnumber = input.nextInt();
  21.  
  22. //exits if month is < 1 or > 12
  23. if (monthnumber < 1 || monthnumber > 12)
  24. {
  25. System.out.println("Sorry, " + monthnumber + " is not a valid month.");
  26. input.close();
  27. return;
  28. }
  29.  
  30. //determine season with if/ else :)
  31. if (monthnumber >= 1 && monthnumber < 4)
  32. season = ", Happy Spring";
  33. else if (monthnumber >= 4 && monthnumber < 7)
  34. season = ", Have Fun in Summer";
  35. else if (monthnumber >= 7 && monthnumber < 10)
  36. season = ", Ready For Fall";
  37. else if (monthnumber >= 10 && monthnumber <= 12)
  38. season = ", Keep warm Yourself in Winter";
  39.  
  40. //find month by applying -1 to input
  41. System.out.println("We are in " + months[monthnumber-1] + season);
  42. input.close();
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement