Reputation: 11
I have to create a Cinema project in Java using BlueJ. I have a Class named Movie and a Class named Show. In the Show constructor I want to insert some parameters and I want one to be the date and time of the show using "Date". It should be something like this:
public Show(int ID, Movie movie, Date date, int seats)
But I am not able to insert the date. Is there a way to enter it or is it impossible to do it this way?
Thank you for any help.
Upvotes: 1
Views: 31717
Reputation: 5048
The main issue that you need to use java.util.Date
as your object.
There is another Date object which is used for SQL.
So just add import java.util.Date;
in each file you want to use this certain object.
Upvotes: 1
Reputation: 43
That should be possible if you structure your class like this:
public class Show {
private int id;
private Movie movie;
private Date date;
private int seats;
public Show(int ID, Movie movie, Date date, int seats) {
this.id = ID;
this.movie = movie;
this.date = date;
this.seats = seats;
}
}
Then you should be able to call this constructor:
Show show = new Show(5, new Movie(), new java.util.Date(System.currentTimeMillis()), 24);
If you want to specify a specific date, you should use the SimpleDateFormat
class.
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
java.util.Date yourDate = sdf.parse("1992-07-26");
Upvotes: 3