/******************************************************************** * * * * * A JAVA PROGRAM TO CALCULATE AIR FORCE RESERVE RETIREMENT * * * * * * IKE 24 Jan 04 * * * ********************************************************************/ import java.awt.*; import java.applet.*; import javax.swing.*; import java.awt.event.*; public class Retirement04 extends JApplet { private Container c; private JComboBox CompList; private JComboBox YearList; String rankList[ ] = {"Lieutenant General", "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[ ] = {.76073, .72077, .65181, .52090, .45579, .39813, .36398, .34106, .29029, .25069, .24563, .19781, .30702, .26498, .23206, .19513, .16444}; double payList1[ ] = {.77169, .73856, .65181, .53460, .46950, .39813 , .36398 , .34106, .29029, .25069, .24563, .19781, .31904, .27683, .24292, .19513, .16444}; double payList2[ ] = {.78752, .73856, .65181, .54846, .46950, .39813, .36398, .34106, .29029, .25069, .24563, .19781, .33171, .28342, .24994, .19513, .16444}; double payList3[ ] = {.81517, .73856, .65510, .57538, .46950, .39813, .36398, .34106, .29029, .25069, .24563, .19781, .35102, .29960, .26771, .19513, .16444}; 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 ); } } }