/******************************************************************** * * * * * A JAVA PROGRAM TO CALCULATE AIR FORCE RESERVE RETIREMENT * * * * * * IKE 14 Feb 06 * * * ********************************************************************/ import java.awt.*; import java.applet.*; import javax.swing.*; import java.awt.event.*; public class Retirement06 extends JApplet { private Container c; private JComboBox CompList; private JComboBox YearList; String rankList[ ] = {"General", "Lieutenant General", "Major General", "Brigadier General", "Colonel", "Lieutenant Colonel", "Major", "Captain ", "First Lieutenant", "Second Lieutenant", "* Captain *", "* First 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[ ] = {0.92813, 0.81177, 0.76913, 0.69554, 0.55583, 0.48638, 0.42483, 0.36394, 0.2675, 0.21108, 0.3884, 0.30977, 0.2621, 0.32763, 0.28275, 0.24763, 0.20823, 0.17546, 0.14017 }; double payList1[ ] = {0.93267, 0.82344, 0.7881, 0.69554, 0.57046, 0.501, 0.42483, 0.36394, 0.2675, 0.21108, 0.3884, 0.30977, 0.2621, 0.34044, 0.2954, 0.25921, 0.20823, 0.17546, 0.14017 }; double payList2[ ] = {0.95206, 0.84035, 0.7881, 0.69554, 0.58525, 0.501, 0.42483, 0.36394, 0.2675, 0.21108, 0.3884,0.30977, 0.2621, 0.35396, 0.30242, 0.26671, 0.20823, 0.17546, 0.14017 }; double payList3[ ] = {0.98585, 0.86983, 0.7881, 0.69906, 0.61398, 0.501, 0.42483, 0.36394, 0.2675, 0.21108, 0.3884, 0.30977, 0.2621, 0.37458, 0.31969, 0.28567, 0.20823, 0.17546, 0.14017 }; private JLabel quant, rank, year, output, fourpay, blank; private JTextField quantity; private JTextArea outputArea; private JButton button1; private JPanel panel1; public void init() { 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"); c.add(button1); ButtonHandler handler = new ButtonHandler(); button1.addActionListener(handler); //this output = new JLabel("Monthly Retirement Estimate:"); c.add(output); outputArea = new JTextArea(1,15); c.add(outputArea); blank = new JLabel (" __________________________________________________________ "); c.add(blank); fourpay = new JLabel(" * over four years of enlisted service "); c.add(fourpay); setSize(360,140); } private class ButtonHandler implements ActionListener { public void actionPerformed (ActionEvent e) { buildOutput(); } } 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 ); } 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 ); } } }