-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshowreview.java
More file actions
185 lines (145 loc) · 4.8 KB
/
Copy pathshowreview.java
File metadata and controls
185 lines (145 loc) · 4.8 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import java.sql.Connection;
import java.sql.Date;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.time.LocalDate;
import java.util.Scanner;
public class showreview extends FilmReview implements ifilmdatabase {
public Date date;
public String showName;
public int releaseDate;
public String rating;
public String review;
private Scanner myObj;
private String showName1;
private int releaseDate1;
private String rating1;
private String review1;
// Constructors
// Default Constructor
public showreview() throws SQLException {
this.showName = "Naruto";
this.releaseDate = 2002;
this.rating = "9/10";
this.review = "This show is the pinnacle of what a shonen anime is. You grow with the characters through adolescence and feel the weight of increasingly heavy topics from the point of view of innocence. It masterfully shows off how characters can change and breaks down and throws out the black and white character tropes so commonly found throughout shows now.";
this.date = calculateDate();
}
// Partial Constructor
public showreview(String review) throws SQLException {
super();
this.showName = "Naruto";
this.releaseDate = 2002;
this.rating = "9/10";
this.review = review;
this.date = calculateDate();
}
// Full Constructor
public showreview(String showName, int releaseDate, String rating, String review, Date date) throws SQLException {
super();
this.showName = showName;
this.releaseDate = releaseDate;
this.rating = rating;
this.review = review;
this.date = date;
}
// Inherits the method from its parent class FilmReview
@Override
public Date calculateDate() {
LocalDate date1 = java.time.LocalDate.now();
Date date = Date.valueOf(date1);
return date;
}
// Method to print the date to have a reference of when you are getting paid
public void displayDate() {
System.out.println("Todays Date: " + this.date);
System.out.println();
}
// Inherits the method from the interface
@Override
public void userinput() {
myObj = new Scanner(System.in);
System.out.println("Enter Show Title :");
showName1 = myObj.nextLine();
myObj = new Scanner(System.in);
System.out.println("Enter Release Date :");
releaseDate1 = myObj.nextInt();
myObj = new Scanner(System.in);
System.out.println("Enter Your Rating :");
rating1 = myObj.nextLine();
myObj = new Scanner(System.in);
System.out.println("Enter Your Review :");
review1 = myObj.nextLine();
}
public void addToDatabase() {
// Try Catch statement to check the code for errors as it executes
try {
// Makes a connection to the database using the Driver and Login credentials for
// the admin of the database
Connection myConn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:8889/MovieCrtique", "root", "root");
// A prepared statement rather than a statement to execute input parameters
// Determines the table in the database and selects the columns to input values
// into
PreparedStatement pstmt = myConn.prepareStatement(
"INSERT INTO Shows (Date, ShowName, ReleaseDate, Rating, Review) VALUES (?,?,?,?,?)");
pstmt.setDate(1, date);
pstmt.setString(2, showName1);
pstmt.setInt(3, releaseDate1);
pstmt.setString(4, rating1);
pstmt.setString(5, review1);
pstmt.executeUpdate();
} catch (Exception exc) {
exc.printStackTrace();
}
System.out.println();
}
public void display() {
System.out.println("Your show name is :" + showName1);
System.out.println();
System.out.println("The release date for that show was :" + releaseDate1);
System.out.println();
System.out.println("Your rating for this show is : " + rating1);
System.out.println();
System.out.println("Your review for this show is :" + review1);
System.out.println();
System.out.println("Your review has been placed into our database. Thank you for your insight.");
}
// Getters and Setters
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
public String getShowName() {
return showName;
}
public void setShowName(String showName) {
this.showName = showName;
}
public int getReleaseDate() {
return releaseDate;
}
public void setReleaseDate(int releaseDate) {
this.releaseDate = releaseDate;
}
public String getRating() {
return rating;
}
public void setRating(String rating) {
this.rating = rating;
}
public String getReview() {
return review;
}
public void setReview(String review) {
this.review = review;
}
// Main
public static void main(String[] args) throws SQLException {
showreview s = new showreview();
s.userinput();
s.addToDatabase();
s.display();
}
}