So i have a program due on Mon. My teacher REQUIRES a flowchart, so i spent an hour doing the flowchart, all check and done, after that i start to program and now i have the program running but having the wrong output. Can anyone help me?
This is the lab description:
Create a new file named Birthday.java.
Write a program to determine the day of the week that a person was born given his or her birth date. Following are the steps you should use to find the day of the week corresponding to any date in the 20th century.
a. Divide the last two digits of the birth year by 4. Put the quotient (ignoring the remainder) in total. (For example, if the person was born in 1983, divide 83 by 4 and store 20 in total.)
b. Add the last two digits of the birth year to total.
c. Add the last two digits of the birth date to total.
d. Use the following table, find the “month number” and add it to total.
Jan = 1 Feb = 4 Mar = 4 Apr = 0 May = 2 Jun = 5
July = 0 Aug = 3 Sept = 6 Oct = 1 Nov = 4 Dec = 6
e. If the year is a leap year and if the month you are working with is either Jan or Feb, then subtract 1 from total.
f. Find the remainder when total is divided by 7. Look up the remainder in the following table to determine the day of the week the person was born. Note that you cannot use this procedure if a person was born before 1900;
1 = Sunday 2 = Monday 3 = Tuesday 4 = Wednesday
5 = Thursday 6 = Friday 0 = Saturday
The user should be prompted to enter the birth month by number( 1 for Jan, 2 for Feb...) then the birth date and last the year in the format 1983. Make sure to give an error message if the birth year is before 1900.
And here's the code that i've written so far. Also i have no clue on why certain varibles cannot be used out side of the "{}" in the if else statements, also i have no clue on how to do dates for year 2000 and above, i used my birth date 11/05/1992 as a reference and is ONE day off. I'm totally bummed cause i spend 3 hours trying to fix all these problems. Help would be very nice and turns out my friends suck even more than i do, they can't even get a output!! And admin sry if this in the wrong place!! this is first post ever. Thanks for helping.
//Roger Zhang
//AP CompSci 2
//Freed
import java.util.Scanner;
public class Birthday
{
public static void main (String [] args)
{
Scanner in = new Scanner(System.in);
System.out.println("Please input birthdate in mm/dd/yyyy");
int month = in.nextInt();
int date = in.nextInt();
int year = in.nextInt();
//End of Block A, user inputs
if (year > 2100)
{
System.out.println("Please input a year in the 20th century!");
}
else
{
if (year < 1900)
{
System.out.println("Please input a year in the 20th century!");
}
else
{
if (year >= 2000)
{
int yearOne = year - 2000;
//System.out.println(yearOne);
}
else
{
if (year >= 1900)
{
int yearOne = year - 1900;
//System.out.println(yearOne);
//End of Block B, to determine the last two digits of the year
int total = (yearOne/4)+yearOne+date;
//System.out.println(total);
if (month == 01||month == 10)
{
int total2 = total + 1;
}
else
{
if (month == 05)
{
int total2 = total + 2;
}
else
{
if (month == 8)
{
int total2 = 3;
}
else
{
if (month == 02||month==03||month==11)
{
int total2 = total + 4;
//System.out.println(total2);
}
else
{
if (month == 9||month==12)
{
int total2 = total + 6;
}
else
{
if (month == 06)
{
int total2 = total + 5;
}
else
{
if (month == 07||month == 04)
{
int total2 = total + 0;
//End of Block C, to add a corresponding number to the month
}
}
}
}
}
}
}
}
}
}
}
int leapYear = year%4;
//System.out.println(leapYear);
if (leapYear == 0)
{
if (month ==01||month==02)
{
int month2 = month -1;
//System.out.println (month2);
}
}
int yearTwo = total2%7;
if (yearTwo == 1)
{
System.out.println("This person was born on a Sunday");
}
else
{
if (yearTwo == 2)
{
System.out.println("This person was born on a Monday");
}
else
{
if (yearTwo==3)
{
System.out.println("This person was born on a Tuesday");
}
else
{
if (yearTwo == 4)
{
System.out.println("This person was born on a Wednesday");
}
else
{
if (yearTwo == 5)
{
System.out.println("This person was born on a Thursday");
}
else
{
if (yearTwo==6)
{
System.out.println("This person was born on a Friday");
}
else
{
if (yearTwo==0)
{
System.out.println("This person was born on a Saturday");
}
}
}
}
}
}
}
}
}