So I'm trying to figure out why my IDE is not accepting this piece of code. The error it's giving me is that the return statement is missing. But after doing some digging I found out that when I already have a return statement I don't really need a break. Heres me code.
The month, day, and year are private variables that have already been initialized in the private constructor. Each of the switch cases is supposed to take the date inputs and out the date in a specific format.
public String toString(int format) {
switch (format) {
case 1:
return month + "/" + day + "/" + year;
case 2:
String pattern = "00";
DecimalFormat decimalFormat = new DecimalFormat(pattern);
return decimalFormat.format(month) + "/" +
decimalFormat.format(day) + "/" +
year;
case 3:
String abbrev = "JanFebMarAprMayJunJulAugSepOctNovDec";
return abbrev.substring(month * 3 - 3, month * 3 - 1) +
"/" + day + "/" + year;
case 4:
switch (month) {
case 1:
return "January" + " " + day + ", " + year;
case 2:
return "February" + " " + day + ", " + year;
case 3:
return "March" + " " + day + ", " + year;
case 4:
return "April" + " " + day + ", " + year;
case 5:
return "May" + " " + day + ", " + year;
case 6:
return "June" + " " + day + ", " + year;
case 7:
return "July" + " " + day + ", " + year;
case 8:
return "August" + " " + day + ", " + year;
case 9:
return "September" + " " + day + ", " + year;
case 10:
return "October" + " " + day + ", " + year;
case 11:
return "November" + " " + day + ", " + year;
case 12:
return "December" + " " + day + ", " + year;
default:
System.out.println("Error please try again");
break;
}
default:
System.out.println("Error please try again");
}
}