|
@@ -5,8 +5,8 @@ import java.util.concurrent.ThreadLocalRandom; |
|
|
|
|
|
|
|
|
class runLabs { |
|
|
class runLabs { |
|
|
public static void main(String[] args) { |
|
|
public static void main(String[] args) { |
|
|
new Lab4(); |
|
|
|
|
|
// new Lab5(); |
|
|
|
|
|
|
|
|
// new Lab4(); |
|
|
|
|
|
new Lab5(); |
|
|
// new Lab6(); |
|
|
// new Lab6(); |
|
|
// new Lab7(); |
|
|
// new Lab7(); |
|
|
} |
|
|
} |
|
@@ -368,6 +368,37 @@ class Lab5 extends Lab { |
|
|
class five7 extends Exercise { |
|
|
class five7 extends Exercise { |
|
|
public five7() { |
|
|
public five7() { |
|
|
super(7); |
|
|
super(7); |
|
|
|
|
|
showUserAge(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void showUserAge() { |
|
|
|
|
|
Scanner userInput = new Scanner(System.in); |
|
|
|
|
|
System.out.println(String.format("Please input your DOB")); |
|
|
|
|
|
System.out.println(String.format("input format is YYYY M D")); |
|
|
|
|
|
String inputString = userInput.nextLine(); |
|
|
|
|
|
|
|
|
|
|
|
Scanner processInput = new Scanner(inputString); |
|
|
|
|
|
|
|
|
|
|
|
int dobYear = processInput.nextInt(); |
|
|
|
|
|
int dobMonth = processInput.nextInt(); |
|
|
|
|
|
int dobDay = processInput.nextInt(); |
|
|
|
|
|
// input sanitisation could be nice... |
|
|
|
|
|
|
|
|
|
|
|
Calendar userDOB = Calendar.getInstance(); |
|
|
|
|
|
// recall months are zero-indexed! |
|
|
|
|
|
userDOB.set(dobYear, dobMonth-1, dobDay); |
|
|
|
|
|
|
|
|
|
|
|
Calendar today = Calendar.getInstance(); |
|
|
|
|
|
|
|
|
|
|
|
System.out.println(String.format("Today:\t%s", today.getTime())); |
|
|
|
|
|
System.out.println(String.format( |
|
|
|
|
|
"DOB :\t%s (difference: %d years)", |
|
|
|
|
|
userDOB.getTime(), |
|
|
|
|
|
Lab4.yearsOld(today, userDOB))); |
|
|
|
|
|
|
|
|
|
|
|
userInput.close(); |
|
|
|
|
|
processInput.close(); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|