-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSc2310_MyAdvanceTicket.java
More file actions
76 lines (47 loc) · 1.61 KB
/
CSc2310_MyAdvanceTicket.java
File metadata and controls
76 lines (47 loc) · 1.61 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
70
71
72
73
74
75
import java.util.Scanner;
public class MyAdvanceTicket extends MyTicket{
public MyAdvanceTicket(){
super();
}
public double getPrice(){
if(dayCount() >= 10){
return super.getPrice() + 30.0;
}
return super.getPrice() + 40.0;
}
public int dayCount(){
Scanner input = new Scanner(System.in);
Scanner input1 = new Scanner(System.in);
System.out.print("What is todays date? yyyy/mm/dd \n");
String date1 = input.nextLine();
int year = findYear(date1);
int month = findMonth(date1);
int day = findDay(date1);
System.out.print("What is the date of the event? yyyy/mm/dd \n");
String date2 = input1.nextLine();
int eYear = findYear(date2);
int eMonth = findMonth(date2);
int eDay = findDay(date2);
Date today = new Date(year, month, day);
Date eventDay = new Date(eYear, eMonth, eDay);
return today.daysTo(eventDay);
}
public static int findYear(String input){
int dash = input.indexOf('/');
String temp = input.substring(0, dash);
return Integer.parseInt(temp); //Returns string converted to int
}
public static int findMonth(String input){
int dash = input.indexOf('/');
String temp = input.substring(dash + 1, dash + 3);
return Integer.parseInt(temp); //Returns string converted to int
}
public static int findDay(String input){
int dash = input.indexOf('/');
String temp = input.substring(dash + 4, input.length());
return Integer.parseInt(temp); //Returns string converted to int
}
//public String toString(){
// return "Number " + ticketNum + " , Price: " + this.getPrice() +"\n"; //Number: 17, Price: 50.0
//}
}