-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDateReaderImpl.java
More file actions
33 lines (25 loc) · 896 Bytes
/
Copy pathDateReaderImpl.java
File metadata and controls
33 lines (25 loc) · 896 Bytes
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
package com.yurii.salimov.lesson06.task01;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;
public final class DateReaderImpl implements DateReader {
private final static String DATE_FORMAT = "dd MM yyyy";
private final Scanner scanner;
public DateReaderImpl() {
this.scanner = new Scanner(System.in);
}
@Override
public Date read() throws ParseException {
final String dateLine = readDate();
return parse(dateLine);
}
private String readDate() {
System.out.println("Enter your date use format " + DATE_FORMAT + ":");
return this.scanner.nextLine();
}
private Date parse(final String line) throws ParseException {
final SimpleDateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT);
return dateFormat.parse(line);
}
}