-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathChallengeThree.java
More file actions
69 lines (55 loc) · 2.14 KB
/
Copy pathChallengeThree.java
File metadata and controls
69 lines (55 loc) · 2.14 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
64
65
66
67
68
69
import java.time.LocalDate;
public class ChallengeThree {
public static String dayOfWeek(String date) {
/**
* Returns a String storing the day of the week in all capital letters of the
* given date String
* Complete the implementation of the DateUtil class and use it in this function
* Arguments
* date - a String storing a local date, such as "2000-01-01"
* Examples
* dayOfWeek("2000-01-01") returns "SATURDAY"
*/
// ====================================
// Do not change the code before this
// CODE1: Write code to return the day of the week of the String date
// using the DateUtil class at the bottom of this file
return new DateUtil(date).dayOfWeek();
// ====================================
// Do not change the code after this
}
public static void main(String[] args) {
String theDayOfWeek = dayOfWeek("2000-01-01");
String expected = "SATURDAY";
// Expected output is
// true
System.out.println(theDayOfWeek == expected);
}
}
class DateUtil {
LocalDate theDate;
public DateUtil(String date) {
/**
* Initialize the theDate field using the String date argument
* Arguments
* date - a String storing a local date, such as "2000-01-01"
*/
// ====================================
// Do not change the code before this
// CODE2: Write code to initialize the date field of the class
theDate = LocalDate.parse(date);
// ====================================
// Do not change the code after this
}
public String dayOfWeek() {
/**
* Return a String the day of the week represented by theDate
*/
// ====================================
// Do not change the code before this
// CODE3: Write code to return the String day of the week of theDate
return theDate.getDayOfWeek().toString();
// ====================================
// Do not change the code after this
}
}