I have another problem in my program.
The problem is in the following parts of the code:
Track track1 = new Track(1111, Date?? , "MesuraX", "Pacient1", 12);
(problem is that I don't know how to put some value so that DATE doesn't give me an error...)
And then in this other part:
System.out.println("Data??");
date = lector.next();
track1.setDataTrack(date);
How do you read a Date by scanner?
FINAL
Cannot read scanner the solution is this:
System.out.println("Data??");
String fechaComoTexto = lector.nextLine();
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
date = sdf.parse(fechaComoTexto);
track1.setDataTrack(date);
You can't read a
Date
through aScanner
. What you can do is read a text stringString
and convert this string to aDate
. You can do this using the classSimpleDateFormat
(exception handling is omitted from the code for ease of reading and understanding):This is one way to do it:
You can also make use of Locale