So for this project, we have to calculate which day of the week a particular date falls. For example, given 11/3/2012, you would need to find out on which day March 11th falls. (It goes dd/mm/year).
the ArrayList named Rob contains all the tokenized values of the inputs, which are imported from a text file. (An example input would be 12/4/1992,19/3/1996)
I have calculated whether or not a certain year is a leap year, and I have calculated on which day of the week January 1st falls. I am stuck at the part where I determine the which day of the week a particular date falls when given the information that I have already found.
How would I determine which day of the week a date (such as 20/7/1966) falls?
What do I need to add to the code to make this happen?
PS - Everything up to this point works properly.
import java.util.*; import java.io.*; public class DayOfTheWeek { private static PrintWriter out; private static Scanner in; private static int integer; private int year; private static int intDay; private static int intMonth; private static int [] temp; private static int numDays; public static void main (String [] args) { int [] monthlength = new int [] {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; boolean leapYear; try{ FileInputStream fstream = new FileInputStream("input.txt"); // Get the object of DataInputStream DataInputStream in = new DataInputStream(fstream); BufferedReader br = new BufferedReader(new InputStreamReader(in)); String strLine; //Read File Line By Line while ((strLine = br.readLine()) != null) { //split it using /and , as the delimiter StringTokenizer st = new StringTokenizer(strLine); st = new StringTokenizer(strLine, "/,"); while (st.hasMoreElements()) { String token = st.nextToken(); integer = Integer.parseInt(token); rob.add(integer); } } for (int i = 2; i < rob.size(); i+=3) { int temp = rob.get(i); int y = (temp-1); int x = (36 + y + (y/4) - (y/100) + (y/400)) % 7; int daysinYear = 365; if (rob.get(i) % 400 == 0) { leapYear = true; daysinYear = (daysinYear + 1); } else if ((rob.get(i) %4 == 0) && (rob.get(i) %100 != 0)) { leapYear = true; daysinYear = (daysinYear + 1); } else { leapYear = false; } if (x == 0) { System.out.println("January first is a Sunday."); System.out.println(temp); } if (x == 1) { System.out.println("January first is a Monday."); System.out.println(temp); } if (x == 2) { System.out.println("January first is a Tuesday."); System.out.println(temp); } if (x == 3) { System.out.println("January first is a Wendsay."); System.out.println(temp); } if (x == 4) { System.out.println("January first is a Thursday."); System.out.println(temp); } if (x == 5) { System.out.println("January first is a Friday."); System.out.println(temp); } if (x == 6) { System.out.println("January first is a Saturday."); System.out.println(temp); } } FileWriter output = new FileWriter(args[0]); PrintWriter out = new PrintWriter(output); // Write text to file out.println("This is line 1"); out.println("This is line 2"); out.println("this is line 3 part 2"); out.close(); //Close the input stream in.close(); } catch (Exception e){ System.err.println("Error: " + e.getMessage()); } } }