/******************************************************************** * * * * * A JAVA PROGRAM TO CALCULATE AIR FORCE RESERVE RETIREMENT * * * * * * IKE 12 Jan 03 * * * ********************************************************************/ import java.awt.*; import java.applet.*; import javax.swing.*; import java.awt.event.*; public class Retirement03 extends JApplet { private Container c; 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" }; String yearsList[ ] = {"Over 20", "Over 22", "Over 24", "Over 26"}; double payList[ ] = {.69506, .62856, .50231, .43952, .38392, .35100, .32890, .27994, .24175, .23685, .19075, .29033, .25177, .21727, .18817, .15856}; double payList1[ ] = {.71221, .62856, .51552, .45275, .38392, .35100, .32890, .27994, .24175, .23685, .19075, .30169, .26302, .23135, .18817, .15856}; double payList2[ ] = {.71221, .62856, .52890, .45275, .38392, .35100, .32890, .27994, .24175, .23685, .19075, .31294, .26927, .23804, .18817, .15856}; double payList3[ ] = {.71221, .63173, .55485, .45275, .38392, .35100, .32890, .27994, .24175, .23685, .19075, .33038, .28467, .25496, .18817, .15856}; 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 ); } } }