Advertisement
Guest User

Simple Date "Calculator"

a guest
Feb 7th, 2016
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.41 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static void main(String[] args) {
  6.  
  7.         Scanner dateInput = new Scanner(System.in);
  8.  
  9.         String date;
  10.         System.out.print("What is the date? ");
  11.         date = dateInput.next();
  12.  
  13.  
  14.  
  15.         String[] daysOfWeek = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
  16.         String[] dayNumber = { "0", "1", "2", "3", "4", "5", "6"};
  17.  
  18.         int i = Integer.parseInt(date);
  19.         if(Integer.parseInt(date) < 7) {
  20.             i = Integer.parseInt(date);
  21.         }
  22.         else if (Integer.parseInt(date) >= 28 && Integer.parseInt(date) <= 31){
  23.             i = i - 28;
  24.         }
  25.         else if (Integer.parseInt(date) >= 21 && Integer.parseInt(date) <= 27){
  26.             i = i - 21;
  27.         }
  28.         else if (Integer.parseInt(date) >= 14 && Integer.parseInt(date) <= 20){
  29.             i = i - 14;
  30.         }
  31.         else if (Integer.parseInt(date) >= 7 && Integer.parseInt(date) <= 13){
  32.             i = i - 7;
  33.         }
  34.  
  35.         else {
  36.             System.out.println("Error with i");
  37.         }
  38.  
  39.  
  40.         int d = Integer.parseInt(dayNumber[i]);
  41.  
  42.         // Replies with date and day.
  43.  
  44.         if(Integer.parseInt(dayNumber[d]) <= 6 ) {
  45.             System.out.println("The " + date + " is a " + daysOfWeek[d]);
  46.         }
  47.  
  48.         else {
  49.            System.out.println("Error with reply");
  50.         }
  51.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement