-2

package assignment2;

import java.util.Scanner;

public class Assignment2 {

public static void main(String[] args) {
    Scanner stdIn = new Scanner(System.in);
    System.out.print("What is today?: ");
    String day = stdIn.nextLine();
    System.out.print("What year is it?: ");
    int year = stdIn.nextInt();

//for when the year IS a leap year

    if (day == "Tuesday" || (year % 400 == 0) || (year % 4 == 0) && (year % 100 != 0)) {
        System.out.println("In 100 years from " + day     " will be a Monday")
    } else if (day == "Wednesday" || (year % 400 == 0) || (year % 4 == 0) && (year % 100 != 0)) {
        System.out.println("In 100 years from " + day " will be a Tuesday")
    } else if (day == "Thursday" || (year % 400 == 0) || (year % 4 == 0) && (year % 100 != 0)) {
        System.out.println("In 100 years from " + day " will be a Wednesday")
    } else if (day == "Friday" || (year % 400 == 0) || (year % 4 == 0) && (year % 100 != 0)) {
        System.out.println("In 100 years from " + day " will be a Thursday")
    } else if (day == "Saturday" || (year % 400 == 0) || (year % 4 == 0) && (year % 100 != 0)) {
        System.out.println("In 100 years from " + day " will be a Friday")
    } else if (day == "Sunday" || (year % 400 == 0) || (year % 4 == 0) && (year % 100 != 0)) {
        System.out.println("In 100 years from " + day " will be a Saturday")
    }else if (day == "Monday" || (year % 400 == 0) || (year % 4 == 0) && (year % 100 != 0)) {
        System.out.println("In 100 years from " + day " will be a Sunday")



//This is for when the year IS NOT a leap year

    } else if (day == "Monday" || (year % 100 = 0)) {
        System.out.println("In 100 years from " + day " will be a Saturday")
    } else if (day == "Tuesday" || (year % 100 = 0)) {
        System.out.println("In 100 years from " + day " will be a Sunday")
    } else if (day == "Wednesday" || (year % 100 = 0)) {
        System.out.println("In 100 years from " + day " will be a Monday")
    } else if (day == "Thursday" || (year % 100 = 0)) {
        System.out.println("In 100 years from " + day " will be a Tuesday")
    } else if (day == "Friday" || (year % 100 = 0))
        System.out.println ("In 100 years from " + day " will be a Wednesday")
    } else if (day == "Saturday" || (year % 100 = 0))
        System.out.println("In 100 years from " + day " will be a Thursday"){
    } else if (day == "Sunday" || (year % 100 = 0))
        System.out.println("In 100 years from " + day " will be a Friday")
} 

}

Edit: Here is my brain logic.. If you can understand it.. It's not java logic. But its to show you what I'm stuck on if you can read it.

Philzeey
  • 55
  • 7
  • Sorry, I'm brand new to this website. But I have searched everywhere to see if I could see some examples to how to figure this out.. My question is how to figure out what day it will be "Monday, Tuesday, Etc..) in 100 years including leap years. I know the second part is kinda irrelevant but it was just simple code that reminded me of the leap year rules. I just don't really know where to begin.. I'm in an introductory class. Thanks. – Philzeey Sep 21 '15 at 23:55
  • 2
    This probably doesn’t help, but… September 21, 2115 [will be a Saturday](https://www.wolframalpha.com/input/?i=September%2021%2C%202115)! More seriously, you’ve asked how to do something and posted some code, but haven’t explained where you’re getting stuck. If we can see your thought process, maybe we could explain where you’re going wrong, or give you some hints in the right direction; while we could provide the right answer and why it’s right, that solves your problem now, but it doesn’t really help you in the long run. – icktoofay Sep 21 '15 at 23:59
  • 2
    Might want to reiterate the question in the body of the text, and smooth out the formatting on your code block. – cryptic_star Sep 22 '15 at 00:04
  • Yeah I don't want the straight answer to it, just where to begin. On the equation part of figuring out what day it will be. So for example. If there were no leap years, in a 100 years it would just be 36500 % 7 = 2. So if you input Monday it'll be Wednesday. So I need a program that will.. do this.. What day is it? - Monday What year is it - 2016 In 100 years it will be Saturday. I just don't know the step after asking the questions to figure it out. Hopefully this clears it up. – Philzeey Sep 22 '15 at 00:24
  • http://stackoverflow.com/questions/478694/what-is-the-easiest-algorithm-to-find-the-day-of-week-of-day-zero-of-a-given-yea – sinclair Sep 22 '15 at 00:58
  • `day == "Tuesday"`: [How do I compare strings in Java?](http://stackoverflow.com/q/513832) – Tom Sep 22 '15 at 01:34

2 Answers2

0

I think that the answer to your question depends a lot on what your instructor expects you to get out of the exercise.

If the goal is simply to get the job done as efficiently as possible, then you would use either the date-related classes in the Java class library, or a third-party date library.

Which ones you would use would depend on the version of Java that you are using. For Java 6 or 7, you would use java.util.Date and related classes. For Java 8, you would use the new java.time classes.

In Java 6 or 7, you could also use the third-party library Joda-Time library. The author of that library was also the major contributor to the Java 8 java.time library, so they are similar.

Or, perhaps, your instructor expects you do the math yourself?

In any case, I'm not in favor of simply giving someone the answer to what is clearly a homework question, so I leave the rest to you.

GreyBeardedGeek
  • 29,460
  • 2
  • 47
  • 67
-1

Ok i add few line of code to get after 100 date from input date code is as below :

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Scanner;

public class Assignment2 {

    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        System.out.print("What is today in format (yyyy/MM/dd) eg. 2015/08/03 ?: ");
        String day = stdIn.nextLine();
        System.out.print("What year is it?: ");
        int year = stdIn.nextInt();
        System.out.println("100 years from " + day + " will be a ");

        //getting calendar instance
        Calendar after100Year = Calendar.getInstance();

        //date time format for conversion or parsing
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
        try {
            //Prasing string input date to date object
            Date inputDate = dateFormat.parse(day);
            //set time to calendar instance
            after100Year.setTime(inputDate);

            //add 100 year in input date
            after100Year.add(Calendar.YEAR, 100);
            System.out.println("After 100 year date will be : " + dateFormat.format(after100Year.getTime()));

        } catch (ParseException ex) {
            ex.printStackTrace();
        }

        if (year % 400 == 0) {
            System.out.println("This is a leap year");
        } else if ((year % 4 == 0) && (year % 100 != 0)) {
            System.out.println("This is a leap year");
        } else {
            System.out.println("This is not a leap year.");
        }

    }
}
Bhuwan Prasad Upadhyay
  • 2,916
  • 1
  • 29
  • 33
  • Simply giving someone the full code for what is clearly a homework assignment doesn't help the OP learn anything. OP clearly asked for direction as opposed to the full answer. – GreyBeardedGeek Sep 22 '15 at 00:35
  • Yeah all I have to go off is if, else if, else statements and string names and ints. I'm only in the beginning part of the class so basically that's all I have to go off of. He says it's really not that hard but yeah I only know Scanner/Random too haha. So I have no idea what that code by developerbhuwan even is. I won't be able to replicate that anyways. – Philzeey Sep 22 '15 at 00:46