public void commandLETTER( String srcPostOffice, String pickUpPerson, String dstPostOffice, String returnPerson, int systemTime) { int srcOfficeIndex = getOfficeIndex(srcPostOffice); if (srcOfficeIndex != -1) { newLetterEntry("log_" + srcPostOffice + ".txt", srcPostOffice, dstPostOffice); int dstOfficeIndex = getOfficeIndex(dstPostOffice); if (dstOfficeIndex != -1) { if (isNewCriminal(newCriminals, pickUpPerson) == false && isOldCriminal("wanted.txt", pickUpPerson) == false) { if (((Office) offices.get(srcOfficeIndex)).currentItems.size() < ((Office) offices.get(srcOfficeIndex)).maxCap) { Item newItem = new Item(); newItem.fromOffice = new String(srcPostOffice); newItem.recipent = new String(pickUpPerson); newItem.toOffice = new String(dstPostOffice); if (returnPerson.equals("NONE")) { newItem.returnRecipent = ""; } else { newItem.returnRecipent = new String(returnPerson); } newItem.dayGotInSystem = systemTime; newItem.type = new String("letter"); newItem.delivaryTime = ((Office) offices.get(srcOfficeIndex)).transitTime; ((Office) offices.get(srcOfficeIndex)).waitingForSending.add(newItem); acceptedLetterEntry("log_" + srcPostOffice + ".txt", dstPostOffice); } else { rejectedLetterEntry("log_" + srcPostOffice + ".txt", srcPostOffice); rejectedLetterEntry("log_master.txt", srcPostOffice); } } else { rejectedLetterEntry("log_" + srcPostOffice + ".txt", srcPostOffice); rejectedLetterEntry("log_master.txt", srcPostOffice); } } else { rejectedLetterEntry("log_" + srcPostOffice + ".txt", srcPostOffice); rejectedLetterEntry("log_master.txt", srcPostOffice); } } }
public void commandPACKAGE( String srcPostOffice, String pickUpPerson, String dstPostOffice, int funds, int packageLen) { int srcOfficeIndex = getOfficeIndex(srcPostOffice); if (srcOfficeIndex != -1) { newPackageEntry("log_" + srcPostOffice + ".txt", srcPostOffice, dstPostOffice); int dstOfficeIndex = getOfficeIndex(dstPostOffice); if (dstOfficeIndex != -1) { if (isNewCriminal(newCriminals, pickUpPerson) == false && isOldCriminal("wanted.txt", pickUpPerson) == false) { if (((Office) offices.get(srcOfficeIndex)).currentItems.size() < ((Office) offices.get(srcOfficeIndex)).maxCap) { if (funds >= ((Office) offices.get(srcOfficeIndex)).postagePrice) { if (packageLen <= ((Office) offices.get(srcOfficeIndex)).maxPackageSize) { if (packageLen <= ((Office) offices.get(dstOfficeIndex)).maxPackageSize) { // Clean insertion Item newItem = new Item(); newItem.fromOffice = new String(srcPostOffice); newItem.recipent = new String(pickUpPerson); newItem.toOffice = new String(dstPostOffice); newItem.funds = funds; newItem.length = packageLen; newItem.type = new String("package"); newItem.dayGotInSystem = currentDay; newItem.delivaryTime = ((Office) offices.get(srcOfficeIndex)).transitTime; ((Office) offices.get(srcOfficeIndex)).waitingForSending.add(newItem); acceptedPackageEntry("log_" + srcPostOffice + ".txt", dstPostOffice); } else { rejectedPackageEntry("log_" + srcPostOffice + ".txt", srcPostOffice); rejectedPackageEntry("log_master.txt", srcPostOffice); } } else if (funds >= (((Office) offices.get(srcOfficeIndex)).postagePrice + ((Office) offices.get(srcOfficeIndex)).persuationPrice)) { // Illegal insertion Item newItem = new Item(); newItem.fromOffice = new String(srcPostOffice); newItem.recipent = new String(pickUpPerson); newItem.toOffice = new String(dstPostOffice); newItem.funds = funds; newItem.length = packageLen; newItem.type = new String("package"); newItem.dayGotInSystem = currentDay; newItem.delivaryTime = ((Office) offices.get(srcOfficeIndex)).transitTime; ((Office) offices.get(srcOfficeIndex)).waitingForSending.add(newItem); acceptedPackageEntry("log_" + srcPostOffice + ".txt", dstPostOffice); briberyDetectedEntry("log_master.txt", srcPostOffice); } else { rejectedPackageEntry("log_" + srcPostOffice + ".txt", srcPostOffice); rejectedPackageEntry("log_master.txt", srcPostOffice); } } else { rejectedPackageEntry("log_" + srcPostOffice + ".txt", srcPostOffice); rejectedPackageEntry("log_master.txt", srcPostOffice); } } else { rejectedPackageEntry("log_" + srcPostOffice + ".txt", srcPostOffice); rejectedPackageEntry("log_master.txt", srcPostOffice); } } else { rejectedPackageEntry("log_" + srcPostOffice + ".txt", srcPostOffice); rejectedPackageEntry("log_master.txt", srcPostOffice); } } else { rejectedPackageEntry("log_" + srcPostOffice + ".txt", srcPostOffice); rejectedPackageEntry("log_master.txt", srcPostOffice); } } }