1
Good first follows down the exercise:
Create a class called
Date
including three parts of information as instance variables: onemês (tipo int)
, onedia (tipo int)
and aano (tipo int)
.Provide a method
set
and aget
for each instance variable. Provide a methoddisplayDate
showing the month, day and year separated by normal bars ( / ).Write an app called
DateTest
that demonstrates the capabilities of the Date class.
I’m doing something wrong but as I’m learning I can’t know what it is.Can you please help me
public class Date {
private int dia;
private int mes;
private int ano;
public Date(int d, int m, int a)
{
int dia=d;
int mes=m;
int ano=a;
}
public void setDia(int d)
{
dia = d;
}
public int getDia()
{
return dia;
}
public void setMes(int m)
{
mes = m;
}
public int getMes()
{
return mes;
}
public void setAno(int a)
{
ano = a;
}
public int getAno()
{
return ano;
}
public void displayDate()
{
System.out.printf("%d/%d/%d", getDia(), getMes(), getAno());
}
public static void main( String[] args ) {
int dia = 0;
int mes = 0;
int ano = 0;
Scanner s = new Scanner( System.in );
System.out.println( "Digite o dia: " );
dia = s.nextInt();
System.out.println( "Digite o mês: " );
mes = s.nextInt();
System.out.println( "Digite o ano: " );
ano = s.nextInt();
Date d = new date(dia,mes,ano);
System.out.println( "A data é: " + d.displayDate() );
}
}
In the constructor do not use
int dia = d
onlydia = d
– ramaral