I have seen that it exists in java 8 Year class but how should I implement its value? if I give it 1903 it tells me that it is int not Year if I put it in quotes it tells me that it is a String
public class Cuadros {
private String titulo;
private String autor;
private String estilo;
private int precio;
private Year añoCreacion;
public Cuadros(String titulo, String autor, String estilo, int precio, Year añoCreacion) {
this.titulo = titulo;
this.autor = autor;
this.estilo = estilo;
this.precio = precio;
this.añoCreacion = añoCreacion;
}
public Cuadros() {
}
private ArrayList<Cuadros> datos = new ArrayList();
datos.add(new Cuadros("La Mona Lisa", "Leonardo da Vinci", "Renacentista", 713000000, 1503));
datos.add(new Cuadros("El grito", "Munch", "Expresionismo", 119900000, "1893)"));
datos.add(new Cuadros("La persistencia de la memoria", "Dalí ", "Surrealismo", 400000000, "1931"));
datos.add(new Cuadros("El nacimiento de Venus", "Sandro Botticelli", "Gotico", 10000000, "1482"));
datos.add(new Cuadros("Guernica", "Pablo Picasso", "Cubismo", 300000000, "1937"));
datos.add(new Cuadros("Los jugadores de cartas", "Paul Cézanne", "Posimpresionismo", 191000000, "1890"));
this.adaptador = new AdaptadorCuadros(this, this.datos);
java.time.Year
You can instantiate the class like this:or also:
You have to keep in mind that the integer you pass to it is interpreted like this:
So you can do something like:
And of course this class implements the method
toString()
, soIt will show the current year:
"2020"