Assignment 104, Weekday Calculator w/o methods
Code
///Name: Stella Koliavas
///Period: 5
///Program Name: WeekdayCalc2
///File Name: WeekdayCalc2.java
///Date Finshed: 4/26/16
import java.util.Scanner;
public class WeekdayCalc2
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Welcome to Mr. Davis's fantastic birth-o-meter!");
System.out.println();
System.out.println("All you have to do is enter your birth date, and it will");
System.out.println("tell you the day of the week on which you were born.");
System.out.println();
System.out.println("Some automatic tests....");
System.out.println("12 10 2003 => " + weekday(12,10,2003));
System.out.println(" 2 13 1976 => " + weekday(2,13,1976));
System.out.println(" 2 13 1977 => " + weekday(2,13,1977));
System.out.println(" 7 2 1974 => " + weekday(7,2,1974));
System.out.println(" 1 15 2003 => " + weekday(1,15,2003));
System.out.println("10 13 2000 => " + weekday(10,13,2000));
System.out.println();
System.out.println("Now it's your turn! What's your birthday?");
System.out.print("Birth date (mm dd yyyy): ");
int mm = keyboard.nextInt();
int dd = keyboard.nextInt();
int yyyy = keyboard.nextInt();
System.out.println("You were born on " + WeekdayCalc.weekday_name(mm) +WeekdayCalc.weekday(mm, dd, yyyy));
}
public static String weekday( int mm,int dd,int yyyy )
{
int yy, total, weekday;
String date;
yy = yyyy-1900;
total = (yy/4) + yy + dd + WeekdayCalc.monthOffset( mm );
if (mm ==1 && WeekdayCalc.isLeap(yyyy) == true)
total = total-1;
else if (mm ==2 && WeekdayCalc.isLeap(yyyy) == true )
total = total -1;
weekday = (total % 7);
// bunch of calculations go here
date = (WeekdayCalc.weekday_name(weekday) + ", "+dd+ ", " + yyyy);
return date;
}
}
Picture of the output