date - Java: Error with constructors and passing variables -


i trying input date in format dd mm yyyy , have return in format e. g. tuesday, 29th september. i'm new java , not sure if values day, month, year classes being returned main. there error date date1 = new date(day1, month1, year1) saying undefined , make constructor. if make constructor , run program values lab2.day@659e0bfd. not sure go here.

package lab2;  public class calendar {  //assume months have 30 days , 1 january monday;  public static void main(string[] args) { // e.g. input: 29 09 2015      int in1 = integer.parseint(args[0]);     int in2 = integer.parseint(args[1]);     int in3 = integer.parseint(args[2]);      day day1 = new day(in1, in2); // string     month month1 = new month(in2); // string     year year1 = new year(in3); // integer        date date1 = new date(day1, month1, year1); //      date1.printname(); // e.g. "the date tuesday, 29th of september, 2015  } } 

package lab2;  public class day { private int day; private int month; private int code; private string name; //e.g. tuesday   public day(int dy, int mth ){     day = dy;     month = mth;     code = ((day*month) % 7);       // assigning day variable number text //     switch (code) {     case 0: name = "monday";             break;     case 1: name = "tuesday";             break;     case 2: name = "wednesday";             break;     case 3: name = "thursday";             break;     case 4: name = "friday";             break;     case 5: name = "saturday";             break;     case 6: name = "sunday";             break;     default: system.out.println("incorrect day entered");}      }  } 

package lab2;  public class month {  private int month1; private string monthname;     public month(int temp1){     month1=temp1;   switch (month1) { case 1: monthname = "january";         break; case 2: monthname = "february";         break; case 3: monthname = "march";         break; case 4: monthname = "april";         break; case 5: monthname = "may";         break; case 6: monthname = "june";         break; case 7: monthname = "july";         break; case 8: monthname = "august";         break; case 9: monthname = "september";         break; case 10: monthname = "october";         break; case 11: monthname = "november";         break; case 12: monthname = "december";         break; default: system.out.println("incorrect month error");}   }  } 

package lab2;  public class year {  private int yearnumber;  public year(int temp2) {     yearnumber=temp2;   } } 

package lab2;  public class date {  private string day; private string month; private int year;     public date(string temp1, string temp2, int temp3){     day = temp1;     month = temp2;     year = temp3;      }    public void printname() {     system.out.println("the date " +day+ ", " +month+ ", " +year); }  }  

there error "date date1 = new date(day1, month1, year1)" saying undefined , make constructor.

since there no such parameterised constructor in date class date(day d, month m, year y). having constructor date(string temp1, string temp2, int temp3). parameter types different.

instead of

date date1 = new date(day1, month1, year1); 

use

date date1 = new date(day1.name, month1.monthname, year1.yearnumber);  

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -