private void updateNumCars() { String totalNumber = Integer.toString(CarManager.instance().getNumEntries()); if (showAllCars) { numCars.setText(totalNumber); return; } String showNumber = Integer.toString(getSortByList().size()); numCars.setText(showNumber + "/" + totalNumber); }
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // ================================!!!!!!!!!!!!!!!!!!!!!!!!!!!================================ // Hey guys. There is this bug where if you go from the start page to the Lifestyles page, then // press submit we get a 500. // This results because some attributes have not been set from previous pages. See this // application assumes that // The client went through the sequential order correctly you guys should fix that. // Also you may have to just re-write this whole servlet, for we have no guarantee that our // implementations of the algorithms for this project work. // We were not given test data so we only followed instructions as best we could. // ================================!!!!!!!!!!!!!!!!!!!!!!!!!!!================================ // Model Calculate: // return results list <String nameType, int dollarValue> // Set to attribute : allResults // Get QuarterExtra default=0; HttpSession session = request.getSession(); String degree = (String) session.getAttribute("school_program"); String region = (String) session.getAttribute("aspirations_region"); double salary = salaryManager.getSalaryByDegreeAndRegion(degree, region).getSalary(); int salaryPerMonth = (int) (salary / 12); // ===== Savings double savingsAmount = (Double) session.getAttribute("lifestyle_savings"); int savings = (int) savingsAmount; // ===== Student loan double studentLoanPercent = (Double) session.getAttribute("school_loanPercent"); int extraQuarters = (Integer) session.getAttribute("school_extraQuarters"); if (request.getParameter("additionalQuarter") != null) { extraQuarters++; session.setAttribute("school_extraQuarters", extraQuarters); } int quarters = (degreeManager.getQuarters(degree).getQuarters()) + extraQuarters; double grants = (Double) session.getAttribute("school_grants"); double schoolInterest = (Double) session.getAttribute("school_interest"); double initialSchoolPay = (quarters * 7200) - grants - savings; double studentLoanPayment = (((initialSchoolPay) + (initialSchoolPay * (schoolInterest / 100))) / 120) * (studentLoanPercent / 100); double studentHousingPayment = getStudentHousingRent(session); int totalLoanPayment = (int) (studentLoanPayment + studentHousingPayment); // ===== Income tax double taxPercent = salaryManager.getSalaryByDegreeAndRegion(degree, region).getTaxBracket(); double incomeTax = salary * taxPercent; int incomeTaxPerMonth = (int) (incomeTax / 12); // ===== Miscellaneous double foodBudgetWeekly = (Double) session.getAttribute("weekly_food_budget"); double monthlyFoodExpense = (foodBudgetWeekly * 52) / 12; double gameSpending = (Double) session.getAttribute("lifestyle_gameSpending"); double otherSpending = (Double) session.getAttribute("other_spending"); int miscellaneous = (int) (foodBudgetWeekly + monthlyFoodExpense + gameSpending + otherSpending); // ===== Car String carCondition = (String) session.getAttribute("aspirations_carCondition"); String carQuality = (String) session.getAttribute("aspirations_carQuality"); int carCost; if (carCondition.contains("No")) { carCost = 0; } else if (carQuality.contains("Above")) { carCost = carManager.getCarByQuality(carCondition).getHigh(); } else if (carQuality.contains("Below")) { carCost = carManager.getCarByQuality(carCondition).getLow(); } else { // Average carCost = carManager.getCarByQuality(carCondition).getMiddle(); } double carInterest = (Double) session.getAttribute("aspirations_interest"); int monthlyCarExpenses = (int) ((carCost / (12 * 5)) + (carCost * (carInterest / 100))); // ===== Post-grad housing int postGradHousingPayment = getPostGradHousing(session); // ===== Other debt double creditDebt = (Double) session.getAttribute("school_creditDebt"); double medicalDebt = (Double) session.getAttribute("school_medicalDebt"); double loanDebt = (Double) session.getAttribute("school_loanDebt"); int otherDebt = (int) (creditDebt + medicalDebt + loanDebt); // ===== Discretionary income int discretionaryIncome = (int) (salaryPerMonth - totalLoanPayment - incomeTaxPerMonth - miscellaneous - monthlyCarExpenses - postGradHousingPayment); request.setAttribute("salary", salaryPerMonth); request.setAttribute("studentLoans", totalLoanPayment); request.setAttribute("incomeTax", incomeTaxPerMonth); request.setAttribute("miscellaneous", miscellaneous); request.setAttribute("carExpenses", monthlyCarExpenses); request.setAttribute("mortgageRent", postGradHousingPayment); request.setAttribute("otherDebt", otherDebt); request.setAttribute("savings", savings); request.setAttribute("discretionaryIncome", discretionaryIncome); request .getRequestDispatcher(getServletContext().getInitParameter("result")) .forward(request, response); }
/** * Construct this Entry from XML. This member has to remain synchronized with the detailed DTD in * operations-cars.dtd * * @param e Car XML element */ public Car(org.jdom2.Element e) { super(e); loaded = true; org.jdom2.Attribute a; if ((a = e.getAttribute(Xml.PASSENGER)) != null) { _passenger = a.getValue().equals(Xml.TRUE); } if ((a = e.getAttribute(Xml.HAZARDOUS)) != null) { _hazardous = a.getValue().equals(Xml.TRUE); } if ((a = e.getAttribute(Xml.CABOOSE)) != null) { _caboose = a.getValue().equals(Xml.TRUE); } if ((a = e.getAttribute(Xml.FRED)) != null) { _fred = a.getValue().equals(Xml.TRUE); } if ((a = e.getAttribute(Xml.UTILITY)) != null) { _utility = a.getValue().equals(Xml.TRUE); } if ((a = e.getAttribute(Xml.KERNEL)) != null) { Kernel k = CarManager.instance().getKernelByName(a.getValue()); if (k != null) { setKernel(k); if ((a = e.getAttribute(Xml.LEAD_KERNEL)) != null && a.getValue().equals(Xml.TRUE)) { _kernel.setLead(this); } } else { log.error("Kernel " + a.getValue() + " does not exist"); } } if ((a = e.getAttribute(Xml.LOAD)) != null) { _loadName = a.getValue(); } if ((a = e.getAttribute(Xml.LOAD_FROM_STAGING)) != null && a.getValue().equals(Xml.TRUE)) { setLoadGeneratedFromStaging(true); } if ((a = e.getAttribute(Xml.WAIT)) != null) { try { _wait = Integer.parseInt(a.getValue()); } catch (NumberFormatException nfe) { log.error("Wait count ({}) for car ({}) isn't a valid number!", a.getValue(), toString()); } } if ((a = e.getAttribute(Xml.PICKUP_SCHEDULE_ID)) != null) { _pickupScheduleId = a.getValue(); } if ((a = e.getAttribute(Xml.SCHEDULE_ID)) != null) { _scheduleId = a.getValue(); } if ((a = e.getAttribute(Xml.NEXT_LOAD)) != null) { _nextLoadName = a.getValue(); } if ((a = e.getAttribute(Xml.NEXT_WAIT)) != null) { try { _nextWait = Integer.parseInt(a.getValue()); } catch (NumberFormatException nfe) { log.error( "Next wait count ({}) for car ({}) isn't a valid number!", a.getValue(), toString()); } } if ((a = e.getAttribute(Xml.NEXT_PICKUP_SCHEDULE_ID)) != null) { _nextPickupScheduleId = a.getValue(); } if ((a = e.getAttribute(Xml.NEXT_DEST_ID)) != null) { setFinalDestination(LocationManager.instance().getLocationById(a.getValue())); } if (getFinalDestination() != null && (a = e.getAttribute(Xml.NEXT_DEST_TRACK_ID)) != null) { setFinalDestinationTrack(getFinalDestination().getTrackById(a.getValue())); } if ((a = e.getAttribute(Xml.PREVIOUS_NEXT_DEST_ID)) != null) { setPreviousFinalDestination(LocationManager.instance().getLocationById(a.getValue())); } if (getPreviousFinalDestination() != null && (a = e.getAttribute(Xml.PREVIOUS_NEXT_DEST_TRACK_ID)) != null) { setPreviousFinalDestinationTrack(getPreviousFinalDestination().getTrackById(a.getValue())); } if ((a = e.getAttribute(Xml.PREVIOUS_SCHEDULE_ID)) != null) { setPreviousScheduleId(a.getValue()); } if ((a = e.getAttribute(Xml.RWE_DEST_ID)) != null) { _rweDestination = LocationManager.instance().getLocationById(a.getValue()); } if (_rweDestination != null && (a = e.getAttribute(Xml.RWE_DEST_TRACK_ID)) != null) { _rweDestTrack = _rweDestination.getTrackById(a.getValue()); } if ((a = e.getAttribute(Xml.RWE_LOAD)) != null) { _rweLoadName = a.getValue(); } addPropertyChangeListeners(); }
/** * Frame for adding and editing the car roster for operations. * * @author Bob Jacobsen Copyright (C) 2001 * @author Daniel Boudreau Copyright (C) 2008, 2009, 2010, 2011, 2012, 2013, 2014 * @version $Revision$ */ public class CarsTableFrame extends OperationsFrame implements TableModelListener { /** */ private static final long serialVersionUID = -5469624100056817632L; CarsTableModel carsTableModel; JTable carsTable; boolean showAllCars; String locationName; String trackName; CarManager carManager = CarManager.instance(); // labels JLabel numCars = new JLabel(); JLabel textCars = new JLabel(Bundle.getMessage("cars")); JLabel textSep1 = new JLabel(" "); // radio buttons JRadioButton sortByNumber = new JRadioButton(Bundle.getMessage("Number")); JRadioButton sortByRoad = new JRadioButton(Bundle.getMessage("Road")); JRadioButton sortByType = new JRadioButton(Bundle.getMessage("Type")); JRadioButton sortByColor = new JRadioButton(Bundle.getMessage("Color")); JRadioButton sortByLoad = new JRadioButton(Bundle.getMessage("Load")); JRadioButton sortByKernel = new JRadioButton(Bundle.getMessage("Kernel")); JRadioButton sortByLocation = new JRadioButton(Bundle.getMessage("Location")); JRadioButton sortByDestination = new JRadioButton(Bundle.getMessage("Destination")); JRadioButton sortByFinalDestination = new JRadioButton(Bundle.getMessage("FD")); JRadioButton sortByRwe = new JRadioButton(Bundle.getMessage("RWE")); JRadioButton sortByTrain = new JRadioButton(Bundle.getMessage("Train")); JRadioButton sortByMoves = new JRadioButton(Bundle.getMessage("Moves")); JRadioButton sortByBuilt = new JRadioButton(Bundle.getMessage("Built")); JRadioButton sortByOwner = new JRadioButton(Bundle.getMessage("Owner")); JRadioButton sortByValue = new JRadioButton(Setup.getValueLabel()); JRadioButton sortByRfid = new JRadioButton(Setup.getRfidLabel()); JRadioButton sortByWait = new JRadioButton(Bundle.getMessage("Wait")); JRadioButton sortByPickup = new JRadioButton(Bundle.getMessage("Pickup")); JRadioButton sortByLast = new JRadioButton(Bundle.getMessage("Last")); ButtonGroup group = new ButtonGroup(); // major buttons JButton addButton = new JButton(Bundle.getMessage("Add")); JButton findButton = new JButton(Bundle.getMessage("Find")); JButton saveButton = new JButton(Bundle.getMessage("Save")); JTextField findCarTextBox = new JTextField(6); public CarsTableFrame(boolean showAllCars, String locationName, String trackName) { super(Bundle.getMessage("TitleCarsTable")); this.showAllCars = showAllCars; this.locationName = locationName; this.trackName = trackName; // general GUI configuration getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); // Set up the table in a Scroll Pane.. carsTableModel = new CarsTableModel(showAllCars, locationName, trackName); TableSorter sorter = new TableSorter(carsTableModel); carsTable = new JTable(sorter); sorter.setTableHeader(carsTable.getTableHeader()); JScrollPane carsPane = new JScrollPane(carsTable); carsPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); carsTableModel.initTable(carsTable, this); // load the number of cars and listen for changes updateNumCars(); carsTableModel.addTableModelListener(this); // Set up the control panel // row 1 JPanel cp1 = new JPanel(); cp1.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("SortBy"))); cp1.add(sortByNumber); cp1.add(sortByRoad); cp1.add(sortByType); JPanel clp = new JPanel(); clp.setBorder(BorderFactory.createTitledBorder("")); clp.add(sortByColor); clp.add(sortByLoad); cp1.add(clp); cp1.add(sortByKernel); cp1.add(sortByLocation); JPanel destp = new JPanel(); destp.setBorder(BorderFactory.createTitledBorder("")); destp.add(sortByDestination); destp.add(sortByFinalDestination); destp.add(sortByRwe); cp1.add(destp); cp1.add(sortByTrain); JPanel movep = new JPanel(); movep.setBorder(BorderFactory.createTitledBorder("")); movep.add(sortByMoves); movep.add(sortByBuilt); movep.add(sortByOwner); if (Setup.isValueEnabled()) { movep.add(sortByValue); } if (Setup.isRfidEnabled()) { movep.add(sortByRfid); } if (ScheduleManager.instance().numEntries() > 0) { movep.add(sortByWait); movep.add(sortByPickup); } movep.add(sortByLast); cp1.add(movep); // row 2 JPanel cp2 = new JPanel(); cp2.setLayout(new BoxLayout(cp2, BoxLayout.X_AXIS)); JPanel cp2Add = new JPanel(); cp2Add.setBorder(BorderFactory.createTitledBorder("")); cp2Add.add(numCars); cp2Add.add(textCars); cp2Add.add(textSep1); cp2Add.add(addButton); cp2.add(cp2Add); JPanel cp2Find = new JPanel(); cp2Find.setBorder(BorderFactory.createTitledBorder("")); findButton.setToolTipText(Bundle.getMessage("findCar")); findCarTextBox.setToolTipText(Bundle.getMessage("findCar")); cp2Find.add(findButton); cp2Find.add(findCarTextBox); cp2.add(cp2Find); JPanel cp2Save = new JPanel(); cp2Save.setBorder(BorderFactory.createTitledBorder("")); cp2Save.add(saveButton); cp2.add(cp2Save); // place controls in scroll pane JPanel controlPanel = new JPanel(); controlPanel.setLayout(new BoxLayout(controlPanel, BoxLayout.Y_AXIS)); controlPanel.add(cp1); controlPanel.add(cp2); // some tool tips sortByFinalDestination.setToolTipText(Bundle.getMessage("FinalDestination")); sortByRwe.setToolTipText(Bundle.getMessage("ReturnWhenEmpty")); sortByPickup.setToolTipText(Bundle.getMessage("TipPickup")); sortByLast.setToolTipText(Bundle.getMessage("TipLastMoved")); JScrollPane controlPane = new JScrollPane(controlPanel); getContentPane().add(carsPane); getContentPane().add(controlPane); // setup buttons addButtonAction(addButton); addButtonAction(findButton); addButtonAction(saveButton); sortByNumber.setSelected(true); addRadioButtonAction(sortByNumber); addRadioButtonAction(sortByRoad); addRadioButtonAction(sortByType); addRadioButtonAction(sortByColor); addRadioButtonAction(sortByLoad); addRadioButtonAction(sortByKernel); addRadioButtonAction(sortByLocation); addRadioButtonAction(sortByDestination); addRadioButtonAction(sortByFinalDestination); addRadioButtonAction(sortByRwe); addRadioButtonAction(sortByTrain); addRadioButtonAction(sortByMoves); addRadioButtonAction(sortByBuilt); addRadioButtonAction(sortByOwner); addRadioButtonAction(sortByValue); addRadioButtonAction(sortByRfid); addRadioButtonAction(sortByWait); addRadioButtonAction(sortByPickup); addRadioButtonAction(sortByLast); group.add(sortByNumber); group.add(sortByRoad); group.add(sortByType); group.add(sortByColor); group.add(sortByLoad); group.add(sortByKernel); group.add(sortByLocation); group.add(sortByDestination); group.add(sortByFinalDestination); group.add(sortByRwe); group.add(sortByTrain); group.add(sortByMoves); group.add(sortByBuilt); group.add(sortByOwner); group.add(sortByValue); group.add(sortByRfid); group.add(sortByWait); group.add(sortByPickup); group.add(sortByLast); // sort by location if (!showAllCars) { sortByLocation.doClick(); if (locationName != null) { String title = Bundle.getMessage("TitleCarsTable") + " " + locationName; if (trackName != null) { title = title + " " + trackName; } setTitle(title); } } // build menu JMenuBar menuBar = new JMenuBar(); JMenu toolMenu = new JMenu(Bundle.getMessage("Tools")); toolMenu.add( new CarRosterMenu(Bundle.getMessage("TitleCarRoster"), CarRosterMenu.MAINMENU, this)); toolMenu.add(new ShowCheckboxesCarsTableAction(carsTableModel)); toolMenu.add(new ResetCheckboxesCarsTableAction(carsTableModel)); toolMenu.add(new ModifyLocationsAction()); toolMenu.add(new TrainsByCarTypeAction()); toolMenu.add(new CarsSetFrameAction(carsTable)); menuBar.add(toolMenu); menuBar.add(new jmri.jmrit.operations.OperationsMenu()); setJMenuBar(menuBar); addHelpMenu("package.jmri.jmrit.operations.Operations_Cars", true); // NOI18N initMinimumSize(); addHorizontalScrollBarKludgeFix(controlPane, controlPanel); // create ShutDownTasks createShutDownTask(); } public void radioButtonActionPerformed(java.awt.event.ActionEvent ae) { log.debug("radio button activated"); if (ae.getSource() == sortByNumber) { carsTableModel.setSort(carsTableModel.SORTBY_NUMBER); } if (ae.getSource() == sortByRoad) { carsTableModel.setSort(carsTableModel.SORTBY_ROAD); } if (ae.getSource() == sortByType) { carsTableModel.setSort(carsTableModel.SORTBY_TYPE); } if (ae.getSource() == sortByColor) { carsTableModel.setSort(carsTableModel.SORTBY_COLOR); } if (ae.getSource() == sortByLoad) { carsTableModel.setSort(carsTableModel.SORTBY_LOAD); } if (ae.getSource() == sortByKernel) { carsTableModel.setSort(carsTableModel.SORTBY_KERNEL); } if (ae.getSource() == sortByLocation) { carsTableModel.setSort(carsTableModel.SORTBY_LOCATION); } if (ae.getSource() == sortByDestination) { carsTableModel.setSort(carsTableModel.SORTBY_DESTINATION); } if (ae.getSource() == sortByFinalDestination) { carsTableModel.setSort(carsTableModel.SORTBY_FINALDESTINATION); } if (ae.getSource() == sortByRwe) { carsTableModel.setSort(carsTableModel.SORTBY_RWE); } if (ae.getSource() == sortByTrain) { carsTableModel.setSort(carsTableModel.SORTBY_TRAIN); } if (ae.getSource() == sortByMoves) { carsTableModel.setSort(carsTableModel.SORTBY_MOVES); } if (ae.getSource() == sortByBuilt) { carsTableModel.setSort(carsTableModel.SORTBY_BUILT); } if (ae.getSource() == sortByOwner) { carsTableModel.setSort(carsTableModel.SORTBY_OWNER); } if (ae.getSource() == sortByValue) { carsTableModel.setSort(carsTableModel.SORTBY_VALUE); } if (ae.getSource() == sortByRfid) { carsTableModel.setSort(carsTableModel.SORTBY_RFID); } if (ae.getSource() == sortByWait) { carsTableModel.setSort(carsTableModel.SORTBY_WAIT); } if (ae.getSource() == sortByPickup) { carsTableModel.setSort(carsTableModel.SORTBY_PICKUP); } if (ae.getSource() == sortByLast) { carsTableModel.setSort(carsTableModel.SORTBY_LAST); } // clear any sorts by column clearTableSort(carsTable); } public List<RollingStock> getSortByList() { return carsTableModel.sysList; } CarEditFrame f = null; // add, find or save button public void buttonActionPerformed(java.awt.event.ActionEvent ae) { // log.debug("car button activated"); if (ae.getSource() == findButton) { int rowindex = carsTableModel.findCarByRoadNumber(findCarTextBox.getText()); if (rowindex < 0) { JOptionPane.showMessageDialog( this, MessageFormat.format( Bundle.getMessage("carWithRoadNumNotFound"), new Object[] {findCarTextBox.getText()}), Bundle.getMessage("carCouldNotFind"), JOptionPane.INFORMATION_MESSAGE); return; } // clear any sorts by column clearTableSort(carsTable); carsTable.changeSelection(rowindex, 0, false, false); return; } if (ae.getSource() == addButton) { if (f != null) { f.dispose(); } f = new CarEditFrame(); f.initComponents(); f.setTitle(Bundle.getMessage("TitleCarAdd")); } if (ae.getSource() == saveButton) { if (carsTable.isEditing()) { log.debug("cars table edit true"); carsTable.getCellEditor().stopCellEditing(); } OperationsXml.save(); saveTableDetails(carsTable); if (Setup.isCloseWindowOnSaveEnabled()) { dispose(); } } } protected int[] getCurrentTableColumnWidths() { TableColumnModel tcm = carsTable.getColumnModel(); int[] widths = new int[tcm.getColumnCount()]; for (int i = 0; i < tcm.getColumnCount(); i++) { widths[i] = tcm.getColumn(i).getWidth(); } return widths; } public void dispose() { carsTableModel.removeTableModelListener(this); carsTableModel.dispose(); if (f != null) { f.dispose(); } super.dispose(); } public void tableChanged(TableModelEvent e) { if (Control.showProperty) { log.debug("Table changed"); } updateNumCars(); } private void updateNumCars() { String totalNumber = Integer.toString(CarManager.instance().getNumEntries()); if (showAllCars) { numCars.setText(totalNumber); return; } String showNumber = Integer.toString(getSortByList().size()); numCars.setText(showNumber + "/" + totalNumber); } private static final Logger log = LoggerFactory.getLogger(CarsTableFrame.class.getName()); }