arrays - Input and Output date class Java -


i'm doing class date project user input date , output date 3 difference formats. a) mm/dd/yyyy b) monthname dd, yyyy c) ddd, yyyy (date of year).

i got stuck @ 1 point, output result part a. here got far

import java.util.scanner; public class implementation {     private static int month;     private static int day;     private static int year;     private static final int[] dayspermonth = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };     public static void date(string args[])     {         scanner input = new scanner(system.in);         while(year != -1)         {             system.out.print("enter month: ");         month = input.nextint();         system.out.print("enter day: ");         day = input.nextint();         system.out.print("enter year: ");         year = input.nextint();          system.out.printf("\nmm/dd/yyyy: %d/%d/%d");         system.out.printf("\nmonth dd/yyyy: ");         system.out.println("\nddd yyyy: \n");         }         }         public implementation(int month, int day, int year)         {         if (month <= 0 || month > 12)             throw new illegalargumentexception(             "month (" + month + ") must 1-12");         if (day <= 0 | (day > dayspermonth[month] && !(month == 2 && day == 29)))             throw new illegalargumentexception             ("day (" + day + ") out-of-range specified month , year");         if (month == 2 && day == 29 && !(year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)))             throw new illegalargumentexception             ("day (" + day + ") out-of-range specified month , year");          this.month = month;         this.day = day;         this.year = year;         }     public string tostring()     {         return string.format("%d/%d/%d", month, day, year);     } } 

what should put right after system.out.printf("\nmm/dd/yyyy: %d/%d/%d"); show result (with valid month,day,and year). haven't done others 2 options yet. i'm beginner , frustrated in project. please help?

probably forget using simpledateformat. using string.format. it's better avoid while formatting date. may try -

simpledateformat formatter = new simpledateformat("mm/dd/yyyy"); //for (a) date datestring = formatter.parse(strdate);    

thanks


Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -