I'm working on a program that calculates the day of the week for dates in history or the future. I have the calculation part correctly but there are 4 errors left that I do not know how to fix. Any help will be greatly appreciated!

Thanks

``````import java.util.Scanner;

public class DayOfWeek
{
public static int Month(String Month)
{
int Monthnum;
if(Month.equals("January") || Month.equals("October"))
{
Monthnum = 3;
}
if(Month.equals("February") || Month.equals("March") || Month.equals("November"))
{
Monthnum = 6;
}
if(Month.equals("April") || Month.equals("July"))
{
Monthnum = 2;
}
if(Month.equals("May"))
{
Monthnum = 4;
}
if(Month.equals("June"))
{
Monthnum = 0;
}
if(Month.equals("August"))
{
Monthnum = 5;
}
if(Month.equals("September") || Month.equals("December"))
{
Monthnum = 1;
}
return Monthnum;
}

public static int Century (int Century)
{
int Centurynum;
if(Century > 1752 && Century < 1799)
{
Centurynum = 2;
}
if(Century > 1800 && Century < 1899)
{
Centurynum = 0;
}
if(Century > 1900 && Century < 1999)
{
Centurynum = 5;
}
if(Century > 2000 && Century < 2099)
{
Centurynum = 4;
}
if(Century > 2100 && Century < 2200)
{
Centurynum = 2;
}
return Centurynum;
}

public static int DOWnum (int DOWnum)
{
String DOW;
if(DOWnum== 1)
{
DOW = ("Sunday");
}
if(DOWnum== 2)
{
DOW = ("Monday");
}
if(DOWnum== 3)
{
DOW = ("Tuesday");
}
if(DOWnum== 4)
{
DOW = ("Wednesday");
}
if(DOWnum== 5)
{
DOW = ("Thursday");
}
if(DOWnum== 6)
{
DOW = ("Friday");
}
if(DOWnum = 0)
{
DOW = ("Saturday");
}
return DOW;
}

public static void main (String [] args)
{
Scanner input=new Scanner(System.in);
System.out.println("This Program will find what day of the week any date was prier to September 14th, 1752");
System.out.println(" ");
int Century, Centurynum, Monthnum, date, Century1, dividedfour, total, DOWnum;
System.out.print("Please enter the month(Full name ex: January): ");
String Month = input.nextLine();
System.out.print("Please enter the day of the month: ");
date = input.nextInt();
System.out.print("Please enter the year(ex: 1900): ");
Century = input.nextInt();
Monthnum = Month(Month);
Centurynum = Century(Century);
Century1 = (Century%1000)%100;
dividedfour = Math.floor(Century1/4);
total = Century1+dividedfour+Centurynum+Monthnum+date;
DOWnum = total%7;
String DOW = DOWnum(DOWnum);
System.out.print(DOW);
}
}``````

You are getting simple compilation errors.
In

``public static int DOWnum (int DOWnum)``

you are trying to return a String. So change the return type of the method to String.

Also in

``````if(DOWnum = 0)
{
DOW = ("Saturday");
}``````

you are assigning '0' to DOWnum. Change it to

``````if(DOWnum == 0)
{
DOW = ("Saturday");
}``````

Also

``Math.floor(Century1/4);``

returns a double. So when assigning double to int compiler complains about the data truncation. So do a explicit cast
dividedfour = (int)Math.floor(Century1/4);

And finally, initialize the variables that you define inside methods to its default value.

Didn't initialize Monthnum:

``int Monthnum = 0;``

Didn't initialize Centurynum:

``int Centurynum = 0;``

Forgot your ==, an int can't be a boolean:

``````if(DOWnum == 0)
{
DOW = ("Saturday");
}``````

You're trying to return a string, but your method is declared as type int, also must initialize DOW:

``````public static String DOWnum (int DOWnum)
{
String DOW = null;``````

dividedfour was declared as an int, yet it was equaled to a double, just add a cast to int:

``dividedfour = (int) Math.floor(Century1/4);``

Also, assuming this should be after September 14, 1752:

``System.out.println("This Program will find what day of the week any date was after September 14th, 1752");``
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.