I'm reading through some coding books and am learning about classes and I want to increment the name of the class variable for months days and year.
I just want to know how to increment date more than once save its own instance variable then move to date 2.
//Class
public String month;
public int day;
public int year;
public void writer() {
System.out.println(month+"/"+day+"/"+year);}
//Main
Scanner kb = new Scanner(System.in);
practice date1 = new practice();
practice date2 = new practice();
System.out.println("Enter month");
date1.month=kb.nextLine();
System.out.println("Enter day");
date1.day=kb.nextInt();
System.out.println("Enter year");
date1.year=kb.nextInt();
kb.nextLine();
date1.writer();
System.out.println("Enter month");
date2.month=kb.nextLine();
System.out.println("Enter day");
date2.day=kb.nextInt();
System.out.println("Enter year");
date2.year=kb.nextInt();
date2.writer();
The Output is fine, I just don't like how much code is and I was wondering if there was a way to cut it almost in half?