explain and answer what kind of Design Pattern is the following: public class Date { private String month; private int day; private int year; public Date(String month, int day, int year){ this.setMonth(month); this.day =day; this.setYear(year); } public Date(String month, int year){ this.setMonth(month); this.setYear(year); } public int getYear() { return year; } public void setYear(int year) { this.year = year; } public String getMonth() { return month; } public void setMonth(String month) { this.month = month; } public int getDay() { return day; } public void setDay(int day) { this.day = day; } public String MonthConvert(String month){ String MonthNumber = "-1"; switch(month.toLowerCase()){ case "jan": case "january":case "1":case "01": MonthNumber = "01"; break; case "feb": case "febuary":case "2":case "02": MonthNumber = "02"; break; case "mar": case "march":case "3":case "03": MonthNumber = "03"; break; case "apr": case "april":case "4":case "04": MonthNumber = "04"; break; case "may": case "5":case "05": MonthNumber = "05"; break; case "jun": case "june": case "6":case "06": MonthNumber = "06"; break; case "jul": case "july": case "7":case "07": MonthNumber = "07"; break; case "aug": case "august": case "8":case "08": MonthNumber = "08"; break; case "sep": case "september": case "9":case "09": MonthNumber = "09"; break; case "oct": case "october": case "10": MonthNumber = "10"; break; case "nov": case "november": case "11": MonthNumber = "11"; break; case "dec": case "december": case "12": MonthNumber = "12"; break; } return MonthNumber; } public String DateForSQLEntry(String month, int day, int year){ //YYYY-MM-DD String toReturn = "0"; String MonthNew = MonthConvert(month); if(day>9){ toReturn = year+"-"+MonthNew +"-"+day; } else if(day<10){ toReturn = year+"-"+MonthNew +"-0"+day; } return toReturn; } }
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
explain and answer what kind of Design Pattern is the following:
public class Date {
private String month;
private int day;
private int year;
public Date(String month, int day, int year){
this.setMonth(month);
this.day =day;
this.setYear(year);
}
public Date(String month, int year){
this.setMonth(month);
this.setYear(year);
}
public int getYear() {
return year;
}
public void setYear(int year) {
this.year = year;
}
public String getMonth() {
return month;
}
public void setMonth(String month) {
this.month = month;
}
public int getDay() {
return day;
}
public void setDay(int day) {
this.day = day;
}
public String MonthConvert(String month){
String MonthNumber = "-1";
switch(month.toLowerCase()){
case "jan": case "january":case "1":case "01":
MonthNumber = "01";
break;
case "feb": case "febuary":case "2":case "02":
MonthNumber = "02";
break;
case "mar": case "march":case "3":case "03":
MonthNumber = "03";
break;
case "apr": case "april":case "4":case "04":
MonthNumber = "04";
break;
case "may": case "5":case "05":
MonthNumber = "05";
break;
case "jun": case "june": case "6":case "06":
MonthNumber = "06";
break;
case "jul": case "july": case "7":case "07":
MonthNumber = "07";
break;
case "aug": case "august": case "8":case "08":
MonthNumber = "08";
break;
case "sep": case "september": case "9":case "09":
MonthNumber = "09";
break;
case "oct": case "october": case "10":
MonthNumber = "10";
break;
case "nov": case "november": case "11":
MonthNumber = "11";
break;
case "dec": case "december": case "12":
MonthNumber = "12";
break;
}
return MonthNumber;
}
public String DateForSQLEntry(String month, int day, int year){
//YYYY-MM-DD
String toReturn = "0";
String MonthNew = MonthConvert(month);
if(day>9){
toReturn = year+"-"+MonthNew +"-"+day;
}
else if(day<10){
toReturn = year+"-"+MonthNew +"-0"+day;
}
return toReturn;
}
}
Step by step
Solved in 2 steps