/******************************************************************** * * * * * A JAVA PROGRAM TO CALCULATE AIR FORCE RESERVE RETIREMENT * * * * * * IKE 7 Feb 05 * * * ********************************************************************/ import java.awt.*; import java.applet.*; import javax.swing.*; import java.awt.event.*; public class Retirement05 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.90021, 0.78735, 0.746, 0.67463, 0.53913, 0.47175 ,0.41206, 0.353, 0.25946, 0.20473, 0.37671, 0.30046, 0.25423 ,0.31777,0.27425, 0.24019, 0.20196, 0.17019, 0.13596 }; double payList1[ ] = {0.90463, 0.79869, 0.76442, 0.67463, 0.55331, 0.48594 ,0.41206, 0.353, 0.25946, 0.20473, 0.37671, 0.30046, 0.25423 ,0.33021, 0.28652, 0.25142, 0.20196, 0.17019, 0.13596 }; double payList2[ ] = {0.92344, 0.81508, 0.76442, 0.67463, 0.56765, 0.48594 ,0.41206, 0.353, 0.25946, 0.20473, 0.37671, 0.30046, 0.25423 ,0.34331, 0.29333, 0.25869, 0.20196, 0.17019, 0.13596 }; double payList3[ ] = {0.95621, 0.84369, 0.76442, 0.67804, 0.59552, 0.48594 ,0.41206, 0.353, 0.25946, 0.20473, 0.37671, 0.30046, 0.25423 ,0.36331, 0.31008, 0.27708, 0.20196, 0.17019, 0.13596 }; 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 ); } } }