Assignemnt #104 and Calling Methods from Other Files
Code
/// Name: Marco Correa
/// Period: 5
/// Program Name: Calling Methods from Other Files
/// File Name: Calling Methods from Other Files.java
/// Date Finished: 3/19/2016
import java.util.Scanner;
public class CallingFunctionsFromOtherFiles
{
public static void main( String[] args )
{
Scanner keyboard = new Scanner(System.in);
System.out.println("Welcome to Mr. Mitchell'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();
String day;
day = weekday(mm, dd, yyyy);
System.out.println("You were born on " + day );
}
public static String weekday( int mm, int dd, int yyyy )
{
int yy, total, remainder;
String date = "";
yy = yyyy - 1900;
total = yy / 4;
total += yy;
total += dd;
total += MonthOffset.month_offset(mm);
if ( WeekdayCalculator.is_leap(yyyy) )
{
if ( MonthName.month_name(mm).equals("January") || MonthName.month_name(mm).equals("February") ) // yes I could do this with just mm == 1 or mm ==2 but thats not what it asks
total -= 1;
}
remainder = total % 7;
date = WeekdayName.weekday_name(remainder) + ", " + MonthName.month_name(mm) + " " + dd + ", " + yyyy;
return date;
}
}
Picture of the output