java - Spotify: "Best Before" Error -
so i, many others, have tried solve problem. believe have code correct, , have tested many, many, many dates on this. however, when send .java file, .jar file, , .class file guys @ spotify, continually says
we have tested solution, , while doing unfortunately discovered following error:
run time error
linkage error
what have works fine on system. guys have ideas on how can stop getting run time , linkage errors? code below:
package spotifychallenges; import java.text.parseexception; import java.text.simpledateformat; import java.util.date; import java.util.scanner; import java.util.vector; public class spotifychallenges { public static void main(string[] args) throws parseexception { vector approvedyears = new vector(); vector approvedmonths = new vector(); vector zeroesapplied = new vector(); vector approveddates = new vector(); vector earliestdate = new vector(); vector earliestdatecheck = new vector(); scanner scanner = new scanner(system.in); system.out.println("enter date: "); string input = scanner.nextline(); string splitinput[] = input.split("/"); string firstinput = splitinput[0]; string secondinput = splitinput[1]; string thirdinput = splitinput[2]; vector totalpossible = new vector(); totalpossible.add(firstinput + "-" + secondinput + "-" + thirdinput); totalpossible.add(firstinput + "-" + thirdinput + "-" + secondinput); totalpossible.add(secondinput + "-" + firstinput + "-" + thirdinput); totalpossible.add(secondinput + "-" + thirdinput + "-" + firstinput); totalpossible.add(thirdinput + "-" + firstinput + "-" + secondinput); totalpossible.add(thirdinput + "-" + secondinput + "-" + firstinput); (int = 0; < totalpossible.size(); i++) { //gets possible date string datepossible = totalpossible.elementat(i).tostring(); //splits possible date string datepossiblesplit[] = datepossible.split("-"); if (datepossiblesplit[0].length() == 1) { datepossiblesplit[0] = "200" + datepossiblesplit[0]; } if (datepossiblesplit[0].length() == 2) { datepossiblesplit[0] = "20" + datepossiblesplit[0]; } if (datepossiblesplit[0].length() == 4) { } int datepossibleint = integer.parseint(datepossiblesplit[0].tostring()); if (datepossibleint < 2000 || datepossibleint > 2999) { } else { approvedyears.addelement(datepossible); } } (int = 0; < approvedyears.size(); i++) { string datepossible2 = approvedyears.elementat(i).tostring(); string datepossible2split[] = datepossible2.split("-"); if (datepossible2split[1].length() == 1) { datepossible2split[1] = "0" + datepossible2split[0]; } if (datepossible2split[1].length() == 2) { } int datepossible2splitint = integer.parseint(datepossible2split[1].tostring()); if (datepossible2splitint > 12 || datepossible2splitint < 1) { } else { approvedmonths.addelement(datepossible2); } } (int = 0; < approvedmonths.size(); i++) { string datepossiblefinal = approvedmonths.elementat(i).tostring(); string datepossiblefinalsplit[] = datepossiblefinal.split("-"); if (datepossiblefinalsplit[0].length() == 1) { datepossiblefinalsplit[0] = "200" + datepossiblefinalsplit[0]; } if (datepossiblefinalsplit[0].length() == 2) { datepossiblefinalsplit[0] = "20" + datepossiblefinalsplit[0]; } if (datepossiblefinalsplit[0].length() == 4) { } if (datepossiblefinalsplit[1].length() == 1) { datepossiblefinalsplit[1] = 0 + "" + datepossiblefinalsplit[1]; } if (datepossiblefinalsplit[1].length() == 2) { } string zeroesin = datepossiblefinalsplit[0] + "-" + datepossiblefinalsplit[1] + "-" + datepossiblefinalsplit[2]; zeroesapplied.addelement(zeroesin); } (int = 0; < zeroesapplied.size(); i++) { boolean leapyear; string finalpossible = zeroesapplied.elementat(i).tostring(); string finalpossiblesplit[] = finalpossible.split("-"); if (finalpossiblesplit[2].length() == 1) { finalpossiblesplit[2] = 0 + "" + finalpossiblesplit[2]; } string whatweadd = finalpossiblesplit[0] + "-" + finalpossiblesplit[1] + "-" + finalpossiblesplit[2]; int year = integer.parseint(finalpossiblesplit[0]); int month = integer.parseint(finalpossiblesplit[1]); int day = integer.parseint(finalpossiblesplit[2]); if (year % 4 == 0) { if (year % 100 == 0) { if (year % 400 == 0) { leapyear = true; } else { leapyear = false; } } else { leapyear = true; } } else { leapyear = false; } if (leapyear == true) { //31 day months if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { if (day < 1 || day > 31) { } else { approveddates.add(whatweadd); } //30 day months } if (month == 4 || month == 6 || month == 9 || month == 11) { if (day < 1 || day > 30) { } else { approveddates.add(whatweadd); } //february } if (month == 2) { if (day < 1 || day > 29) { } else { approveddates.add(whatweadd); } } } if (leapyear == false) { //31 day months if (month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12) { if (day < 1 || day > 31) { } else { approveddates.add(whatweadd); } //30 day months } if (month == 4 || month == 6 || month == 9 || month == 11) { if (day < 1 || day > 30) { } else { approveddates.add(whatweadd); } //february } if (month == 2) { if (day < 1 || day > 28) { } else { approveddates.add(whatweadd); } } } } int sizecheck = approveddates.size(); if (sizecheck == 0) { earliestdate.add(input + " illegal"); } if (sizecheck == 1) { earliestdate.add( approveddates.elementat(0).tostring().replace("]", "").replace("[", "")); } else { (int = 0; < approveddates.size(); i++) { earliestdatecheck.add(approveddates.elementat(i)); } } if (earliestdatecheck.size() >= 2) { (int = 0; < earliestdatecheck.size() - 1; i++) { simpledateformat form = new simpledateformat("yyyy-mm-dd"); vector setter = new vector(); date datecheck = form.parse(earliestdatecheck.elementat(i).tostring()); date datecheck2 = form.parse( earliestdatecheck.elementat(i + 1).tostring()); if (datecheck.before(datecheck2)) { setter.add(earliestdatecheck.elementat(i)); } if (datecheck.equals(datecheck2)) { setter.add(earliestdatecheck.elementat(i)); }if(datecheck.after(datecheck2)){ setter.add(earliestdatecheck.elementat(i+1)); } earliestdate.add(setter.elementat(0).tostring()); } } system.out.println(earliestdate.elementat(0)); } }
what have caused linkage or runtime error?
Comments
Post a Comment