Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class DotW {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- int day, month, year, total, remainder;
- System.out.println("Enter the day (as a number):");
- day = scan.nextInt();
- System.out.println("Enter the month (as a number):");
- month = scan.nextInt();
- System.out.println("Enter the year (as a number):");
- year = scan.nextInt();
- total = day + getCenturyValue(year) + getYearValue(year) + getMonthValue(month, year);
- remainder = total % 7;
- System.out.print(getCenturyValue(year));
- if (remainder == 0) {
- System.out.println("That day of the week is a Sunday");
- }
- else if (remainder == 1) {
- System.out.println("That day of the week is a Monday");
- }
- else if (remainder == 2) {
- System.out.println("That day of the week is a Tuesday");
- }
- else if (remainder == 3) {
- System.out.println("That day of the week is a Wednesday");
- }
- else if (remainder == 4) {
- System.out.println("That day of the week is a Thursday");
- }
- else if (remainder == 5) {
- System.out.println("That day of the week is a Friday");
- }
- else {
- System.out.println("That day of the week is a Saturday");
- }
- }
- public static boolean isLeapYear(int year) {
- if ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0)) {
- return true;
- }
- else {
- return false;
- }
- }
- public static int getCenturyValue(int year) {
- int remainderCentury, century;
- century = year / 100;
- century = century / 4;
- remainderCentury = century % 4;
- remainderCentury = 3 - remainderCentury;
- remainderCentury = remainderCentury * 2;
- return remainderCentury;
- }
- public static int getYearValue (int year) {
- int yearValue, yearV, getYear;
- yearValue = year % 100;
- yearV = yearValue / 4;
- getYear = yearV + yearValue;
- return getYear;
- }
- public static int getMonthValue (int month, int year) {
- if (month == 1 && isLeapYear(0)) {
- return 0;
- }
- else if (month == 1 && isLeapYear(1)) {
- return 6;
- }
- else if (month == 2 && isLeapYear(0)) {
- return 3;
- }
- else if (month == 2 && isLeapYear(1)) {
- return 2;
- }
- else if (month == 3) {
- return 3;
- }
- else if (month == 4) {
- return 6;
- }
- else if (month == 5) {
- return 1;
- }
- else if (month == 6) {
- return 4;
- }
- else if (month == 7) {
- return 6;
- }
- else if (month == 8) {
- return 2;
- }
- else if (month == 9) {
- return 5;
- }
- else if (month == 10) {
- return 0;
- }
- else if (month == 11) {
- return 3;
- }
- else {
- return 5;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement