-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYear2012Tester.java
More file actions
63 lines (52 loc) · 1.83 KB
/
Copy pathYear2012Tester.java
File metadata and controls
63 lines (52 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import java.util.Scanner; // Needed for the Scanner class
/**
* This program uses the Year2012 class.
* Tt asks user inputs, month(mm) and day(dd), from keyboar using Scanner class,
* validate input values and displays results: Month, Date, Julian Date and Day of the Week.
*/
public class Year2012Tester
{
public static void main(String[] args)
{
int month;
int numDays;
int totalDays = 0;
String monthString;
String dayOfWeek;
// Create a Scanner object for keyboardeyboard input.
Scanner input = new Scanner(System.in);
// Get month
System.out.print("Enter a month(mm): ");
month = input.nextInt();
input.nextLine();
// a new object takes month
Year2012 mm = new Year2012();
// get mm and assign to monthString
monthString = mm.getMonthName(month);
while (month < 0 || month > 12)
{
System.out.print("Invalid month. Please re-enter a month(mm): ");
month = input.nextInt();
}
// Get date of the month entered
System.out.print("Enter a date of the month(dd): ");
numDays = input.nextInt();
input.nextLine();
while ( numDays <= 0 || numDays > mm.getDaysInMonth(month))
{
System.out.print("Invalid date. Please re-enter a date (dd): ");
numDays = input.nextInt();
}
// a new object takes two (mm and dd)
Year2012 dy = new Year2012();
totalDays = dy.getDayOfYear(month, numDays);
dayOfWeek = dy.getDayOfWeek(totalDays);
System.out.println();
System.out.println("---------------- RESULTS -----------------");
System.out.println("The month you entered is: " + monthString);
System.out.println("The date in the month you entered is: " + numDays);
System.out.println("Result Output: " + monthString + " " + numDays);
System.out.println("The ordinal year date is: " + totalDays);
System.out.println("The day of Week is: " + dayOfWeek);
}//end of main
}