/******************************************************************** * * * * * A JAVA PROGRAM TO CALCULATE AIR FORCE RESERVE RETIREMENT * * * * * * IKE 4 JUNE 02 * * * ********************************************************************/ import java.awt.*; import java.applet.*; import javax.swing.*; import java.awt.event.*; import java.text.DecimalFormat; public class Retirement extends JFrame { //JApplet private Container c; // declare the container private JComboBox CompList; private JComboBox YearList; String rankList[ ] = {"Major General", "Brigadier General", "Colonel", "Lieutenant Colonel", "Major", "Captain *", "Captain", "First Lieutenant *", "First Lieutenant", "Second Lieutenant *", "Second Lieutenant", "Chief Master Sergeant", "Senior Master Sergeant", "Master Sergeant", "Technical Sergeant", "Staff Sergeant", "Senior Airman" }; String yearsList[ ] = {"Over 20", "Over 22", "Over 24", "Over 26"}; double payList[ ] = {.66769, .60381, .48252, .42221, .36879, .33717, .31594, .26892, .23223, .22752, .18323, .27390, .23752, .21231, .18075, .15231, .12169}; double payList1[ ] = {.68417, .60381, .49521, .43492, .36879, .33717, .31594, .26892, .23223, .22752, .18323, .28460, .24813, .22225, .18075, .15231, .12169}; double payList2[ ] = {.68417, .60381, .50806, .43492, .36879, .33717, .31594, .26892, .23223, .22752, .18323, .29523, .25867, .22867, .18075, .15231, .12169}; double payList3[ ] = {.68417, .60685, .53300, .43492, .36879, .33717, .31594, .26892, .23223, .22752, .18323, .31021, .27346, .24492, .18075, .15231, .12169}; private JLabel quant, rank, year, output, fourpay; private JTextField quantity; private JTextArea outputArea; private JButton button1; private JPanel panel1; public Retirement () { Container c = getContentPane(); c.setLayout(new FlowLayout()); rank = new JLabel("Rank"); c.add(rank); CompList = new JComboBox(rankList); c.add(CompList); year = new JLabel("Years "); c.add(year); YearList = new JComboBox(yearsList); c.add(YearList); panel1 = new JPanel(); quant = new JLabel("Enter # of Points:"); panel1.add(quant); quantity = new JTextField(5); panel1.add(quantity); c.add(panel1); button1 = new JButton("OK"); // create the button c.add(button1); ButtonHandler handler = new ButtonHandler(); // create a handler button1.addActionListener(handler); // listen to the button, using the handler output = new JLabel("Monthly Retirement Estimate:"); c.add(output); outputArea = new JTextArea(1,15); c.add(outputArea); setSize(350,160); fourpay = new JLabel(" Note: * Over four years active enlisted service "); c.add(fourpay); show(); } // ends constructor private class ButtonHandler implements ActionListener { public void actionPerformed (ActionEvent e) { buildOutput(); } } // end of buttonhandler public void buildOutput() { int compIndex = CompList.getSelectedIndex(); //getting the index int yearIndex = YearList.getSelectedIndex(); //I added this if (yearIndex == 0) { double price = payList[compIndex]; int compNum = Integer.parseInt(quantity.getText()); double totalPrice = price * compNum; String outputS = " $ " + totalPrice; outputArea.setText( outputS ); //DecimalFormat twoDigits = new DecimalFormat( "0.00"); //outputArea.setText(""+twoDigits.format (outputS )); } else if (yearIndex == 1) { double price = payList1[compIndex]; int compNum = Integer.parseInt(quantity.getText()); double totalPrice = price * compNum; String outputS = " $ " + totalPrice; outputArea.setText( outputS ); } else if (yearIndex == 2) { double price = payList2[compIndex]; int compNum = Integer.parseInt(quantity.getText()); double totalPrice = price * compNum; String outputS = " $ " + totalPrice; outputArea.setText( outputS ); } else if (yearIndex == 3) { double price = payList3[compIndex]; int compNum = Integer.parseInt(quantity.getText()); double totalPrice = price * compNum; String outputS = " $ " + totalPrice; outputArea.setText( outputS ); } } //end buildoutput public static void main (String args[]) { Retirement application = new Retirement(); application.addWindowListener( new WindowAdapter() { public void windowClosing( WindowEvent e ) { System.exit( 0 ); } } ); } // ends main } // ends class