/** package EVPIApp; */ import java.awt.*; import java.awt.event.*; import java.applet.*; import com.sun.java.swing.*; import javax.swing.*; import java.lang.Float; import java.lang.Double; /** Expected Value of Perfect Infromation evpi) applet is to make a * decision under risk. In this applet user will be able to enter some * values into the textedit fields, after entering the values they will * be able to see how the calculations are calculated. If they choose * the 'Calculate' button then it will show the result at once, which is * the Expected Value of Perfect Information using the best alternative * or consequence by chossing their best State of Nature. If they choose * the 'Step' button then they will be able to see all the steps of the * calculations. There is also a 'Default' button, which will input some * default values to the textfield. If the user wish to clear all the * area they will be able to do just by clicking ont the 'Clear' button. */ public class evpi extends JApplet { boolean isStandalone = false; JLabel titleLabel = new JLabel(); JLabel tableLabel1 = new JLabel(); JLabel tableLabel2 = new JLabel(); JLabel tableLabel3 = new JLabel(); JLabel tableLabel4 = new JLabel(); JLabel tableLabel5 = new JLabel(); JLabel tableLabel6 = new JLabel(); JLabel tableLabel7 = new JLabel(); JLabel tableLabel8 = new JLabel(); JLabel tableLabel9 = new JLabel(); JLabel tableLabel10 = new JLabel(); JLabel tableLabel11 = new JLabel(); JLabel tableLabel12 = new JLabel(); JLabel tableLabel13 = new JLabel(); JLabel tableLabel14 = new JLabel(); JLabel tableLabel15 = new JLabel(); JLabel tableLabel16 = new JLabel(); JLabel tableLabel17 = new JLabel(); JLabel tableLabel18 = new JLabel(); JLabel tableLabel19 = new JLabel(); JLabel tableLabel110 = new JLabel(); JTextField favorableLarge = new JTextField(); JTextField unfavorableLarge = new JTextField(); JTextField favorableSmall = new JTextField(); JTextField unfavorableSmall = new JTextField(); JTextField favorableNothing = new JTextField(); JTextField unfavorableNothing = new JTextField(); JTextArea emvComputedLarge = new JTextArea(); JTextArea emvComputedSmall = new JTextArea(); JTextArea emvComputedNothing = new JTextArea(); JTextField favorableProbability = new JTextField(); JTextField unfavorableProbability = new JTextField(); JLabel displayAreaLabel = new JLabel(); JButton defaultButton = new JButton(); JButton calculateButton = new JButton(); JButton stepButton = new JButton(); JButton clearButton = new JButton(); TextArea displayArea = new TextArea(); /** variable to step through the applet calculation */ int step=1; /** variables to hold the maximum values of each state */ double maxFirstState=0.0, maxSecondState = 0.0; /** variable to hold the maximum value of the emv */ double maxProfit = 0.0; JLabel tableLabel20 = new JLabel(); JLabel tableLabel21 = new JLabel(); JLabel tableLabel111 = new JLabel(); JTextArea evpiComputed = new JTextArea(); JPanel jPanel1 = new JPanel(); JPanel jPanel2 = new JPanel(); JPanel jPanel3 = new JPanel(); JPanel jPanel4 = new JPanel(); JPanel jPanel5 = new JPanel(); /** Construct the applet */ public evpi() { } /** Initialize the applet */ public void init() { try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } /** Component initialization, GUI of the evpi applet */ private void jbInit() throws Exception { titleLabel.setText("Expected Value of Perfect Information"); titleLabel.setForeground(Color.blue); titleLabel.setFont(new Font("Dialog", 1, 20)); titleLabel.setBounds(new Rectangle(142, 9, 362, 37)); tableLabel1.setText("Decision Table with Probabilities, EMVs, and EVPI"); tableLabel1.setBackground(Color.red); tableLabel1.setFont(new Font("Dialog", 1, 14)); tableLabel1.setBounds(new Rectangle(9, 5, 350, 26)); tableLabel2.setFont(new Font("Dialog", 0, 14)); tableLabel2.setBackground(Color.red); tableLabel2.setText("STATE OF NATURE"); tableLabel2.setBounds(new Rectangle(226, 82, 140, 26)); tableLabel3.setFont(new Font("Dialog", 0, 14)); tableLabel3.setBackground(Color.red); tableLabel3.setText("ALTERNATIVE"); tableLabel3.setBounds(new Rectangle(19, 139, 99, 26)); tableLabel4.setBounds(new Rectangle(185, 105, 89, 26)); tableLabel5.setBounds(new Rectangle(304, 105, 110, 26)); tableLabel6.setBounds(new Rectangle(456, 105, 36, 26)); tableLabel7.setBounds(new Rectangle(196, 123, 60, 26)); tableLabel8.setBounds(new Rectangle(324, 122, 61, 26)); tableLabel9.setBounds(new Rectangle(431, 121, 85, 26)); tableLabel10.setBounds(new Rectangle(215, 138, 21, 26)); tableLabel11.setBounds(new Rectangle(342, 138, 21, 26)); tableLabel12.setBounds(new Rectangle(460, 137, 21, 26)); tableLabel13.setBounds(new Rectangle(182, 89, 247, 18)); tableLabel14.setBounds(new Rectangle(8, 142, 651, 26)); tableLabel15.setBounds(new Rectangle(10, 6, 151, 26)); tableLabel16.setFont(new Font("Dialog", 1, 13)); tableLabel16.setBackground(Color.red); tableLabel16.setText("Construct a small plant"); tableLabel16.setBounds(new Rectangle(7, 8, 154, 26)); tableLabel17.setBounds(new Rectangle(7, 7, 136, 26)); tableLabel18.setFont(new Font("Dialog", 0, 14)); tableLabel18.setBackground(Color.red); tableLabel18.setText("_______________________________________________________________________________"); tableLabel18.setBounds(new Rectangle(8, 257, 643, 26)); tableLabel19.setFont(new Font("Dialog", 1, 13)); tableLabel19.setBackground(Color.red); tableLabel19.setText("Probabilities"); tableLabel19.setBounds(new Rectangle(8, 8, 89, 26)); tableLabel110.setBounds(new Rectangle(8, 296, 641, 26)); favorableLarge.setBounds(new Rectangle(168, 4, 99, 29)); unfavorableLarge.setBounds(new Rectangle(295, 4, 99, 29)); favorableSmall.setBounds(new Rectangle(169, 4, 99, 29)); unfavorableSmall.setBounds(new Rectangle(296, 4, 99, 29)); favorableNothing.setBounds(new Rectangle(168, 5, 99, 29)); unfavorableNothing.setBounds(new Rectangle(296, 5, 99, 29)); emvComputedLarge.setDisabledTextColor(Color.black); emvComputedLarge.setBounds(new Rectangle(413, 4, 100, 29)); emvComputedSmall.setDisabledTextColor(Color.black); emvComputedSmall.setBounds(new Rectangle(413, 4, 100, 29)); emvComputedNothing.setDisabledTextColor(Color.black); emvComputedNothing.setBounds(new Rectangle(413, 5, 100, 29)); favorableProbability.setBounds(new Rectangle(169, 4, 99, 29)); unfavorableProbability.setBounds(new Rectangle(296, 5, 99, 29)); displayAreaLabel.setText("Display Area"); displayAreaLabel.setForeground(Color.red); displayAreaLabel.setFont(new Font("Dialog", 0, 16)); displayAreaLabel.setBounds(new Rectangle(278, 323, 94, 28)); /** set up for the default button */ defaultButton.setText("Default"); defaultButton.setFont(new Font("Dialog", 1, 12)); defaultButton.setBounds(new Rectangle(130, 540, 91, 37)); defaultButton.addActionListener(new java.awt.event.ActionListener() { /** action performed for the default button. */ public void actionPerformed(ActionEvent e) { defaultButton_actionPerformed(e); } }); /** set up for the calculate button */ calculateButton.setFont(new Font("Dialog", 1, 12)); calculateButton.setText("Calculate"); calculateButton.setBounds(new Rectangle(230, 540, 91, 37)); calculateButton.addActionListener(new java.awt.event.ActionListener() { /** action performed for the calculate button. */ public void actionPerformed(ActionEvent e) { calculateButton_actionPerformed(e); } }); /** set up for the step button */ stepButton.setFont(new Font("Dialog", 1, 12)); stepButton.setText("Step"); stepButton.setBounds(new Rectangle(329, 540, 91, 37)); stepButton.addActionListener(new java.awt.event.ActionListener() { /** action performed for the step button. */ public void actionPerformed(ActionEvent e) { stepButton_actionPerformed(e); } }); /** set up for the clear button */ clearButton.setFont(new Font("Dialog", 1, 12)); clearButton.setText("Clear"); clearButton.setBounds(new Rectangle(428, 540, 91, 37)); clearButton.addActionListener(new java.awt.event.ActionListener() { /** action performed for the clear button. */ public void actionPerformed(ActionEvent e) { clearButton_actionPerformed(e); } }); /** set up for the display area */ displayArea.setBackground(Color.white); displayArea.setBounds(new Rectangle(82, 353, 483, 177)); /** set up for the table label */ tableLabel20.setBounds(new Rectangle(567, 105, 36, 26)); tableLabel21.setBounds(new Rectangle(542, 121, 85, 26)); tableLabel111.setBounds(new Rectangle(572, 137, 21, 26)); evpiComputed.setDisabledTextColor(Color.black); evpiComputed.setBounds(new Rectangle(524, 4, 100, 29)); jPanel1.setLayout(null); jPanel1.setBackground(new Color(46, 170, 178)); jPanel1.setBounds(new Rectangle(8, 47, 633, 38)); jPanel2.setLayout(null); jPanel2.setBackground(new Color(46, 170, 178)); jPanel2.setBounds(new Rectangle(8, 163, 633, 38)); jPanel3.setLayout(null); jPanel3.setBackground(new Color(46, 170, 178)); jPanel3.setBounds(new Rectangle(8, 239, 633, 38)); jPanel4.setBounds(new Rectangle(8, 201, 633, 38)); jPanel5.setLayout(null); jPanel5.setBackground(new Color(85, 201, 255)); jPanel5.setBounds(new Rectangle(8, 278, 633, 38)); jPanel4.setBackground(new Color(85, 201, 255)); jPanel4.setLayout(null); tableLabel111.setText("($)"); tableLabel111.setBackground(Color.red); tableLabel111.setFont(new Font("Dialog", 0, 14)); tableLabel21.setText("COMPUTED"); tableLabel21.setBackground(Color.red); tableLabel21.setFont(new Font("Dialog", 0, 14)); tableLabel20.setText("EVPI"); tableLabel20.setBackground(Color.red); tableLabel20.setFont(new Font("Dialog", 0, 14)); tableLabel110.setText("_______________________________________________________________________________"); tableLabel110.setBackground(Color.red); tableLabel110.setFont(new Font("Dialog", 0, 14)); tableLabel17.setText("Construct nothing"); tableLabel17.setBackground(Color.red); tableLabel17.setFont(new Font("Dialog", 1, 13)); tableLabel15.setText("Construct a large plant"); tableLabel15.setBackground(Color.red); tableLabel15.setFont(new Font("Dialog", 1, 13)); tableLabel14.setText("_______________________________________________________________________________"); tableLabel14.setBackground(Color.red); tableLabel14.setFont(new Font("Dialog", 0, 14)); tableLabel13.setText("____________________________"); tableLabel13.setBackground(Color.red); tableLabel13.setFont(new Font("Dialog", 0, 14)); tableLabel12.setText("($)"); tableLabel12.setBackground(Color.red); tableLabel12.setFont(new Font("Dialog", 0, 14)); tableLabel11.setText("($)"); tableLabel11.setBackground(Color.red); tableLabel11.setFont(new Font("Dialog", 0, 14)); tableLabel10.setText("($)"); tableLabel10.setBackground(Color.red); tableLabel10.setFont(new Font("Dialog", 0, 14)); tableLabel9.setText("COMPUTED"); tableLabel9.setBackground(Color.red); tableLabel9.setFont(new Font("Dialog", 0, 14)); tableLabel8.setText("MARKET"); tableLabel8.setBackground(Color.red); tableLabel8.setFont(new Font("Dialog", 0, 14)); tableLabel7.setText("MARKET"); tableLabel7.setBackground(Color.red); tableLabel7.setFont(new Font("Dialog", 0, 14)); tableLabel6.setText("EMV"); tableLabel6.setBackground(Color.red); tableLabel6.setFont(new Font("Dialog", 0, 14)); tableLabel5.setText("UNFAVORABLE"); tableLabel5.setBackground(Color.red); tableLabel5.setFont(new Font("Dialog", 0, 14)); tableLabel4.setText("FAVORABLE"); tableLabel4.setBackground(Color.red); tableLabel4.setFont(new Font("Dialog", 0, 14)); this.getContentPane().setLayout(null); this.setSize(644,648); this.getContentPane().add(titleLabel, null); this.getContentPane().add(tableLabel20, null); this.getContentPane().add(tableLabel6, null); this.getContentPane().add(tableLabel5, null); this.getContentPane().add(tableLabel4, null); this.getContentPane().add(tableLabel111, null); this.getContentPane().add(tableLabel12, null); this.getContentPane().add(tableLabel11, null); this.getContentPane().add(tableLabel10, null); this.getContentPane().add(tableLabel21, null); this.getContentPane().add(tableLabel9, null); this.getContentPane().add(tableLabel8, null); this.getContentPane().add(tableLabel7, null); this.getContentPane().add(tableLabel13, null); this.getContentPane().add(tableLabel110, null); this.getContentPane().add(tableLabel18, null); this.getContentPane().add(tableLabel14, null); this.getContentPane().add(tableLabel3, null); this.getContentPane().add(tableLabel2, null); this.getContentPane().add(displayAreaLabel, null); this.getContentPane().add(clearButton, null); this.getContentPane().add(stepButton, null); this.getContentPane().add(calculateButton, null); this.getContentPane().add(defaultButton, null); this.getContentPane().add(displayArea, null); this.getContentPane().add(jPanel1, null); jPanel1.add(tableLabel1, null); this.getContentPane().add(jPanel3, null); jPanel3.add(tableLabel17, null); jPanel3.add(favorableNothing, null); jPanel3.add(unfavorableNothing, null); jPanel3.add(emvComputedNothing, null); this.getContentPane().add(jPanel4, null); jPanel4.add(tableLabel16, null); jPanel4.add(favorableSmall, null); jPanel4.add(unfavorableSmall, null); jPanel4.add(emvComputedSmall, null); this.getContentPane().add(jPanel2, null); jPanel2.add(tableLabel15, null); jPanel2.add(favorableLarge, null); jPanel2.add(evpiComputed, null); jPanel2.add(unfavorableLarge, null); jPanel2.add(emvComputedLarge, null); this.getContentPane().add(jPanel5, null); jPanel5.add(tableLabel19, null); jPanel5.add(favorableProbability, null); jPanel5.add(unfavorableProbability, null); } /** Get Applet information */ public String getAppletInfo() { return "Applet Information"; } /** Get parameter info */ public String[][] getParameterInfo() { return null; } /** clearButton_actionPerformed method is to clear all the textfield * and display area. This will also set the background of all the * textfield and display area back to white. */ void clearButton_actionPerformed(ActionEvent e) { displayArea.setText(""); favorableLarge.setText(""); favorableSmall.setText(""); emvComputedLarge.setText(""); unfavorableLarge.setText(""); unfavorableSmall.setText(""); emvComputedSmall.setText(""); favorableNothing.setText(""); unfavorableNothing.setText(""); emvComputedNothing.setText(""); favorableProbability.setText(""); unfavorableProbability.setText(""); displayArea.setText(""); favorableLarge.setBackground(Color.white); favorableSmall.setBackground(Color.white); favorableNothing.setBackground(Color.white); unfavorableLarge.setBackground(Color.white); unfavorableSmall.setBackground(Color.white); unfavorableNothing.setBackground(Color.white); emvComputedLarge.setBackground(Color.white); emvComputedSmall.setBackground(Color.white); emvComputedNothing.setBackground(Color.white); evpiComputed.setText(""); evpiComputed.setBackground(Color.white); step=1; } /** defaultButton_actionPerformed method is to input all the default * values into the textfield. This will also set the background of * all the textfield into white. */ void defaultButton_actionPerformed(ActionEvent e) { displayArea.setText(""); favorableLarge.setText("200000"); favorableSmall.setText("100000"); unfavorableLarge.setText("-180000"); unfavorableSmall.setText("-20000"); favorableNothing.setText("0"); unfavorableNothing.setText("0"); favorableProbability.setText("0.5"); unfavorableProbability.setText("0.5"); favorableLarge.setBackground(Color.white); favorableSmall.setBackground(Color.white); favorableNothing.setBackground(Color.white); unfavorableLarge.setBackground(Color.white); unfavorableSmall.setBackground(Color.white); unfavorableNothing.setBackground(Color.white); emvComputedLarge.setBackground(Color.white); emvComputedSmall.setBackground(Color.white); emvComputedNothing.setBackground(Color.white); emvComputedLarge.setText(""); emvComputedSmall.setText(""); emvComputedNothing.setText(""); evpiComputed.setText(""); evpiComputed.setBackground(Color.white); step=1; } /** calculateButton_actionPerformed method is to performed the * calculation of the Expected Value of Perfect Information applet. * This method takes the default values, which is already been set up * or the user input and then calculates all the necessary calculation * to get the alternative that gives the best result of perfect information * or consequence for every alternative. If no default values thenit takes * an user input and does the calculation for the evpi calculation as necessary. * To calculate the evpi, at first it calculates the emv for each alternatives. * It also set the background color of the emv outcome in green. Similarly, it * Then, it calculates the best outcomes from the favorable and unfavorable markets * set the background color to orange. After calculating the best alternatives, it * will calculate the highest emv and set the background color to orange. Finally, * it calculates the evpi using the best alternatives in a favorable market, an * unfavorable market and the highest emv computed. After, it will highlight the * result in green color. Which is the evpi value, by this value user will be able * to make a decision under risk. */ void calculateButton_actionPerformed(ActionEvent e) { /** declaration of all the variables that have been used in the calculation_actionPerformed * method. */ /** variables to hold all the values of the alternatives in each state of nature */ double favLarge=0.0, favSmall=0.0, favNothing=0.0, unfavLarge=0.0, unfavSmall=0.0, unfavNothing=0.0; /** variables to hold the values for the probability of each state of nature */ double favProbability=0.0, unfavProbability=0.0; /** variables to hold the values of the emv computed */ double emvCompLarge=0.0, emvCompSmall=0.0, emvCompNothing=0.0; /** variable to hold the maximum emv computed*/ double maxProfit=0.0; /** variable to hold the evpi of perfect information computed*/ double evpiComp=0.0; /** variable to hold the evpi with perfect information computed*/ double evpiCompInfo=0.0; /** variables to hold the maximum of each state of nature */ double maxFirstState=0.0, maxSecondState=0.0; try { displayArea.setText(""); favLarge = Double.parseDouble(favorableLarge.getText()); favSmall = Double.parseDouble(favorableSmall.getText()); favNothing = Double.parseDouble(favorableNothing.getText()); unfavLarge = Double.parseDouble(unfavorableLarge.getText()); unfavSmall = Double.parseDouble(unfavorableSmall.getText()); unfavNothing = Double.parseDouble(unfavorableNothing.getText()); favProbability = Double.parseDouble(favorableProbability.getText()); unfavProbability = Double.parseDouble(unfavorableProbability.getText()); if(favProbability<0||favProbability>1||unfavProbability<0||unfavProbability>1) { displayArea.appendText("Your values for probability must be between 0 and 1.\n"); } else { /** calculating the emv for the alternatives. */ emvCompLarge = ((favProbability)*(favLarge)+(unfavProbability)*(unfavLarge)); emvCompSmall = ((favProbability)*(favSmall)+(unfavProbability)*(unfavSmall)); emvCompNothing = ((favProbability)*(favNothing)+(unfavProbability)*(unfavNothing)); /** setting the emv values into the table. */ emvComputedLarge.setText(""+emvCompLarge); emvComputedSmall.setText(""+emvCompSmall); emvComputedNothing.setText(""+emvCompNothing); /** disabling the textfield for the emv that have been just calculated. */ emvComputedLarge.disable(); emvComputedSmall.disable(); emvComputedNothing.disable(); /** calculating the maximum emv. */ if ((emvCompLarge>=emvCompSmall)&(emvCompLarge>=emvCompNothing)) { maxProfit = emvCompLarge; emvComputedLarge.setBackground(Color.orange); } else emvComputedLarge.setBackground(Color.white); if ((emvCompSmall>=emvCompLarge)&(emvCompSmall>=emvCompNothing)) { maxProfit = emvCompSmall; emvComputedSmall.setBackground(Color.orange); } else emvComputedSmall.setBackground(Color.white); if ((emvCompNothing>=emvCompLarge)&(emvCompNothing>=emvCompSmall)) { maxProfit = emvCompNothing; emvComputedNothing.setBackground(Color.orange); } else emvComputedNothing.setBackground(Color.white); /** calculating the best alternative from the favorable market. */ if ((favLarge>=favSmall)&(favLarge>=favNothing)){ maxFirstState=favLarge; favorableLarge.setBackground(Color.orange); } else favorableLarge.setBackground(Color.white); if ((favSmall>=favLarge)&(favSmall>=favNothing)){ maxFirstState=favSmall; favorableSmall.setBackground(Color.orange); } else favorableSmall.setBackground(Color.white); if ((favNothing>=favLarge)&(favNothing>=favSmall)){ maxFirstState=favNothing; favorableNothing.setBackground(Color.orange); } else favorableNothing.setBackground(Color.white); /** calculating the best alternative from the unfavorable market. */ if ((unfavLarge>=unfavSmall)&(unfavLarge>=unfavNothing)){ maxSecondState=unfavLarge; unfavorableLarge.setBackground(Color.orange); } else unfavorableLarge.setBackground(Color.white); if ((unfavSmall>=unfavLarge)&(unfavSmall>=unfavNothing)){ maxSecondState=unfavSmall; unfavorableSmall.setBackground(Color.orange); } else unfavorableSmall.setBackground(Color.white); if ((unfavNothing>=unfavLarge)&(unfavNothing>=unfavSmall)){ maxSecondState=unfavNothing; unfavorableNothing.setBackground(Color.orange); } else unfavorableNothing.setBackground(Color.white); /** calculating the expected value with perfect information. */ evpiCompInfo = ((maxFirstState*favProbability)+(maxSecondState*unfavProbability)); /** calculating the expected value of perfect information.*/ evpiComp = evpiCompInfo - maxProfit; /** inserting the evpi value to the result area. */ evpiComputed.setText(""+evpiComp); evpiComputed.setBackground(Color.green); evpiComputed.disable(); /** displaying all the calculations into the display area. */ displayArea.append("EMV(large plant) = ("+favProbability+")($"+favLarge+ ") + ("+unfavProbability+")($"+unfavLarge+") = $"+emvCompLarge+"\n"); displayArea.append("EMV(small plant) = ("+favProbability+")($"+favSmall+ ") + ("+unfavProbability+")($"+unfavSmall+") = $"+emvCompSmall+"\n"); displayArea.append("EMV(construct nothing) = ("+favProbability+")($"+favNothing+ ") + ("+unfavProbability+")($"+unfavNothing+") = $"+emvCompNothing+"\n\n"); displayArea.append("The maximum of the favorable market is $" +maxFirstState+".\n"); displayArea.append("The maximum of the unfavorable market is $" +maxSecondState+".\n"); displayArea.append("The maximum of the EMV computed is $" +maxProfit+".\n"); displayArea.append("EVPI = ($"+maxFirstState+")("+favProbability+")+($"+maxSecondState+")("+unfavProbability+")-"+maxProfit+"\n"); displayArea.append("EVPI = $"+evpiComp+"\n\n"); step=1; /** back to step 1 */ } /** end of else */ } /** end of try */ /** try to catch the exception of invalid inputs */ catch (Exception r) { displayArea.append("Sorry! One of the values you have entered may not be valid.\n"); displayArea.append("Please check your values and re-enter any incorrect ones (non-digit).\n"); displayArea.append("You must also have values entered in all textfields for the \n"); displayArea.append("State of Nature, favorable and unfavorable markets. \n\n"); } /** end of catch */ }//end method /** stepButton_actionPerformed method is to performed the calculation of the * evpi applet when the 'Step' button has been click on. In each step it will * calculate one of the calculation of the evpi applet. To step through the * applet, user must input the default values or input some values into the * textfield, otherwise they will not be able to step through at all. At the * first step it will calculate the emv for constructing a large plant. It will * show all the calculation into the display area at the same time for user to * go through the calculation. It will also highlight the emv textfield to green color. * Similarlly, it will calculate the second and third steps and set the textfield to * green color. At the fourth step it will calculate the best alternative in a favorable * market. This calculation has also been shown into the display area at the same time for * user to go through. It will also highlight the textfield to orange color. * Similarly, in the next steps it will also calculte the best alternative for the unfavorable * market at the same time it will display them into the display area and set the textfield to * orange color. In the step six, it will calculate the alternatives with the highest emv, at * the same time dispaly it into the display area and highlight it to orange color. * At the final step it will calculate the evpi with perfect information and evpi of perfect * information. User will be able to see the calculation in the display area. It will highlight * the textfield to green color. If user wish to go through the step once more with the same * inputs, they can do that by keep clicking on the 'Step' button. */ void stepButton_actionPerformed(ActionEvent e) { /** declaration of all the variables that have been used in the calculation_actionPerformed * method. */ /** variables to hold all the values of the alternatives in each state of nature */ double favLarge=0.0, favSmall=0.0, favNothing=0.0, unfavLarge=0.0, unfavSmall=0.0, unfavNothing=0.0; /** variables to hold the values for the probability of each state of nature */ double favProbability=0.0, unfavProbability=0.0; /** variables to hold the values of the emv computed */ double emvCompLarge=0.0, emvCompSmall=0.0, emvCompNothing=0.0; /** variable to hold the evpi of perfect information computed*/ double evpiComp=0.0; /** variable to hold the evpi with perfect information computed*/ double evpiCompInfo=0.0; try { favLarge = Double.parseDouble(favorableLarge.getText()); favSmall = Double.parseDouble(favorableSmall.getText()); favNothing = Double.parseDouble(favorableNothing.getText()); unfavLarge = Double.parseDouble(unfavorableLarge.getText()); unfavSmall = Double.parseDouble(unfavorableSmall.getText()); unfavNothing = Double.parseDouble(unfavorableNothing.getText()); favProbability = Double.parseDouble(favorableProbability.getText()); unfavProbability = Double.parseDouble(unfavorableProbability.getText()); /** calculation of the emv */ emvCompLarge = ((favProbability)*(favLarge)+(unfavProbability)*(unfavLarge)); emvCompSmall = ((favProbability)*(favSmall)+(unfavProbability)*(unfavSmall)); emvCompNothing = ((favProbability)*(favNothing)+(unfavProbability)*(unfavNothing)); /** Step 1 is to find the emv for constructing a large plant. */ if (step==1){ displayArea.setText(""); if(favProbability<0||favProbability>1||unfavProbability<0||unfavProbability>1) { displayArea.appendText("Your values for probability must be between 0 and 1.\n"); } else { emvComputedLarge.setBackground(Color.white); emvComputedSmall.setBackground(Color.white); emvComputedNothing.setBackground(Color.white); evpiComputed.setBackground(Color.white); favorableLarge.setBackground(Color.white); favorableSmall.setBackground(Color.white); favorableNothing.setBackground(Color.white); unfavorableLarge.setBackground(Color.white); unfavorableSmall.setBackground(Color.white); unfavorableNothing.setBackground(Color.white); emvComputedLarge.setText(""); emvComputedSmall.setText(""); emvComputedNothing.setText(""); evpiComputed.setText(""); emvComputedLarge.setText(""+emvCompLarge); emvComputedLarge.setBackground(Color.green); emvComputedLarge.disable(); /** displaying the calculation into the display area. */ displayArea.append("The first step is to calculate the Expected Monetary Value for the large plant.\n"); displayArea.append("EMV(large plant) = ("+favProbability+")($"+favLarge+ ") + ("+unfavProbability+")($"+unfavLarge+") = $"+emvCompLarge+"\n\n"); displayArea.append("Click the 'Step' button again.\n\n"); step=2; } } /** Step 2 is to find the emv for constructing a small plant. */ else if(step==2){ displayArea.setText(""); emvComputedSmall.setText(""+emvCompSmall); emvComputedLarge.setBackground(Color.white); emvComputedSmall.setBackground(Color.green); emvComputedSmall.disable(); /** displaying the calculation into the display area. */ displayArea.append("The second step is to calculate the Expected Monetary Value for the small plant.\n"); displayArea.append("EMV(small plant) = ("+favProbability+")($"+favSmall+ ") + ("+unfavProbability+")($"+unfavSmall+") = $"+emvCompSmall+"\n\n"); displayArea.append("Click the 'Step' button again.\n\n"); step=3; } /** Step 3 is to find the emv for constructing nothing. */ else if(step==3){ displayArea.setText(""); emvComputedNothing.setText(""+emvCompNothing); emvComputedSmall.setBackground(Color.white); emvComputedNothing.setBackground(Color.green); emvComputedNothing.disable(); /** displaying the calculation into the display area */ displayArea.append("The third step is to calculate the Expected Monetary Value for constructing nothing.\n"); displayArea.append("EMV(construct nothing) = ("+favProbability+")($"+favNothing+ ") + ("+unfavProbability+")($"+unfavNothing+") = $"+emvCompNothing+"\n\n"); displayArea.append("Click the 'Step' button again.\n\n"); step=4; } /** Step 4 is to find the best alternative from the favorable market. */ else if(step==4){ displayArea.setText(""); emvComputedLarge.setBackground(Color.white); emvComputedSmall.setBackground(Color.white); emvComputedNothing.setBackground(Color.white); displayArea.append("Find the best alternative from the favorable market.\n"); if ((favLarge>=favSmall)&(favLarge>=favNothing)){ maxFirstState=favLarge; favorableLarge.setBackground(Color.orange); } else favorableLarge.setBackground(Color.white); if ((favSmall>=favLarge)&(favSmall>=favNothing)){ maxFirstState=favSmall; favorableSmall.setBackground(Color.orange); } else favorableSmall.setBackground(Color.white); if ((favNothing>=favLarge)&(favNothing>=favSmall)){ maxFirstState=favNothing; favorableNothing.setBackground(Color.orange); } else favorableNothing.setBackground(Color.white); /** displaying the calculation into the display area. */ displayArea.append("Maximum of Favorable Market = $"+maxFirstState+"\n\n"); displayArea.append("Click the 'Step' button again.\n\n"); step=5; } /** Step 5 is to find the best alternative from the unfavorable market. */ else if(step==5){ displayArea.setText(""); displayArea.append("Find the best alternative from the unfavorable market.\n"); if ((unfavLarge>=unfavSmall)&(unfavLarge>=unfavNothing)){ maxSecondState=unfavLarge; unfavorableLarge.setBackground(Color.orange); } else unfavorableLarge.setBackground(Color.white); if ((unfavSmall>=unfavLarge)&(unfavSmall>=unfavNothing)){ maxSecondState=unfavSmall; unfavorableSmall.setBackground(Color.orange); } else unfavorableSmall.setBackground(Color.white); if ((unfavNothing>=unfavLarge)&(unfavNothing>=unfavSmall)){ maxSecondState=unfavNothing; unfavorableNothing.setBackground(Color.orange); } else unfavorableNothing.setBackground(Color.white); /** displaying the calculation into the display area. */ displayArea.append("Maximum of Unfavorable Market = $"+maxSecondState+"\n\n"); displayArea.append("Click the 'Step' button again.\n\n"); step=6; } /** Step 6 is to find the alternative with the highest emv. */ else if(step==6){ displayArea.setText(""); displayArea.append("Find the alternative with the highest Expected Monetary Value.\n"); if ((emvCompLarge>=emvCompSmall)&(emvCompLarge>=emvCompNothing)) { maxProfit = emvCompLarge; emvComputedLarge.setBackground(Color.orange); } else emvComputedLarge.setBackground(Color.white); if ((emvCompSmall>=emvCompLarge)&(emvCompSmall>=emvCompNothing)) { maxProfit = emvCompSmall; emvComputedSmall.setBackground(Color.orange); } else emvComputedSmall.setBackground(Color.white); if ((emvCompNothing>=emvCompLarge)&(emvCompNothing>=emvCompSmall)) { maxProfit = emvCompNothing; emvComputedNothing.setBackground(Color.orange); } else emvComputedNothing.setBackground(Color.white); /** displaying the calculation into the display area. */ displayArea.append("The highest Expected Monetary Value = $"+maxProfit+"\n\n"); displayArea.append("Click the 'Step' button again.\n\n"); step=7; } /** end elseif */ /** Step 7 is to find the evpi using the best alternative in a favorable * market, an unfavorable market and the highest emv computed. */ else if(step==7){ displayArea.setText(""); evpiCompInfo = ((maxFirstState*favProbability)+(maxSecondState*unfavProbability)); evpiComp = evpiCompInfo - maxProfit; /** displaying the calculation into the display area. */ displayArea.append("Calculate the EVPI using the best alternative in a favorable market,\n"); displayArea.append("an unfavorable market, and the highest EMV computed.\n"); displayArea.append("The maximum of the EMV computed is $" +maxProfit+".\n"); displayArea.append("EVPI = ($"+maxFirstState+")("+favProbability+")+($"+maxSecondState+")("+unfavProbability+")-"+maxProfit+"\n"); displayArea.append("EVPI = $"+evpiComp+"\n\n"); /** setting the evpi into the result area.*/ evpiComputed.setText(""+evpiComp); evpiComputed.setBackground(Color.green); evpiComputed.disable(); step=1; /** back to step 1 */ } /** end elseif */ } /** end of try */ /** try to catch the exception of invalid inputs */ catch (Exception r) { displayArea.append("Sorry! One of the values you have entered may not be valid.\n"); displayArea.append("Please check your values and re-enter any incorrect ones (non-digit).\n"); displayArea.append("You must also have values entered in all textfields for the \n"); displayArea.append("State of Nature, favorable and unfavorable markets. \n\n"); } /** end of catch */ } /** end method */ } /** end class */