Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.61 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class DotW {
  3.  
  4. public static void main(String[] args) {
  5. Scanner scan = new Scanner(System.in);
  6. int day, month, year, total, remainder;
  7.  
  8. System.out.println("Enter the day (as a number):");
  9. day = scan.nextInt();
  10. System.out.println("Enter the month (as a number):");
  11. month = scan.nextInt();
  12. System.out.println("Enter the year (as a number):");
  13. year = scan.nextInt();
  14.  
  15. total = day + getCenturyValue(year) + getYearValue(year) + getMonthValue(month, year);
  16. remainder = total % 7;
  17. System.out.print(getCenturyValue(year));
  18.  
  19. if (remainder == 0) {
  20. System.out.println("That day of the week is a Sunday");
  21. }
  22. else if (remainder == 1) {
  23. System.out.println("That day of the week is a Monday");
  24. }
  25. else if (remainder == 2) {
  26. System.out.println("That day of the week is a Tuesday");
  27. }
  28. else if (remainder == 3) {
  29. System.out.println("That day of the week is a Wednesday");
  30. }
  31. else if (remainder == 4) {
  32. System.out.println("That day of the week is a Thursday");
  33. }
  34. else if (remainder == 5) {
  35. System.out.println("That day of the week is a Friday");
  36. }
  37. else {
  38. System.out.println("That day of the week is a Saturday");
  39. }
  40.  
  41. }
  42.  
  43. public static boolean isLeapYear(int year) {
  44. if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) {
  45. return true;
  46. }
  47. else {
  48. return false;
  49. }
  50. }
  51.  
  52. public static int getCenturyValue(int year) {
  53. int remainderCentury, century;
  54.  
  55. century = year / 100;
  56. century = century / 4;
  57. remainderCentury = century % 4;
  58. remainderCentury = 3 - remainderCentury;
  59. remainderCentury = remainderCentury * 2;
  60. return remainderCentury;
  61. }
  62.  
  63. public static int getYearValue (int year) {
  64. int yearValue, yearV, getYear;
  65.  
  66. yearValue = year % 100;
  67. yearV = yearValue / 4;
  68. getYear = yearV + yearValue;
  69. return getYear;
  70. }
  71.  
  72. public static int getMonthValue (int month, int year) {
  73. if (month == 1 && isLeapYear(0)) {
  74. return 0;
  75. }
  76. else if (month == 1 && isLeapYear(1)) {
  77. return 6;
  78. }
  79. else if (month == 2 && isLeapYear(0)) {
  80. return 3;
  81. }
  82. else if (month == 2 && isLeapYear(1)) {
  83. return 2;
  84. }
  85. else if (month == 3) {
  86. return 3;
  87. }
  88. else if (month == 4) {
  89. return 6;
  90. }
  91. else if (month == 5) {
  92. return 1;
  93. }
  94. else if (month == 6) {
  95. return 4;
  96. }
  97. else if (month == 7) {
  98. return 6;
  99. }
  100. else if (month == 8) {
  101. return 2;
  102. }
  103. else if (month == 9) {
  104. return 5;
  105. }
  106. else if (month == 10) {
  107. return 0;
  108. }
  109. else if (month == 11) {
  110. return 3;
  111. }
  112. else {
  113. return 5;
  114. }
  115.  
  116.  
  117. }
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement