Well first follow below the exercise:
Create a class named
Date
that includes three pieces of information as instance variables: amês (tipo int)
, adia (tipo int)
and aano (tipo int)
.Provide a method
set
andget
for each instance variable. Please provide onedisplayDate
method that displays the month, day, and year separated by normal bars (/).Write an application named
DateTest
demonstrates the capabilities of the Date class.
I am doing something wrong but as I am learning I can not know what it is. Can you help me please?
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() );
}
}