/*Author: Stephen Marsh Date: 2/13 Description: MIS 225 Hands on Exam, computes payment owed using the ComputePayment class */ import java.applet.*; import java.awt.*; import java.awt.event.*; import java.text.NumberFormat; public class Payment_Marsh extends Applet implements ActionListener{ //create three labels private Label prompt1; private Label prompt2; private Label prompt3; //create three input textfields private TextField inputField1; private TextField inputField2; private TextField inputField3; //create result label and fields private TextField resultField; private Label resultLabel; private String resultStr; private Button button; private boolean buttonClicked; //tells program when to paint frog image private Image frogImage; public void init(){ prompt1 = new Label("Enter the amount borrowed:"); prompt2 = new Label("Enter the annual interest rate:"); prompt3 = new Label("Enter the number of years:"); inputField1 = new TextField(10); inputField1.setEditable (true); inputField2 = new TextField(10); inputField2.setEditable(true); inputField3 = new TextField(10); inputField3.setEditable(true); resultLabel = new Label("The Maturity Value is:"); resultField = new TextField(10); resultField.setEditable (false); button = new Button("Calculate the Payment Value"); button.addActionListener(this); add(prompt1); add(inputField1); add(prompt2); add(inputField2); add(prompt3); add(inputField3); add(resultLabel); add(resultField); add(button); frogImage = getImage(getCodeBase(),"frog_funny.gif"); setSize(300,300); }//init public double convertStringToDouble(String s){ Double doubleObject = Double.valueOf(s); return doubleObject.doubleValue(); }//convert public void actionPerformed(ActionEvent e){ //store principal and convert to double String inputString = inputField1.getText(); double principal = convertStringToDouble(inputString); //store interest rate and convert to double inputString = inputField2.getText (); double rate = convertStringToDouble(inputString); //store years and convert to double inputString = inputField3.getText(); double years = convertStringToDouble(inputString); //create a ComputePayment object and have it compute the payment ComputePayment compPay = new ComputePayment(); double payment = compPay.calcPayment(principal,rate,years); NumberFormat dollars = NumberFormat.getCurrencyInstance (); resultStr = dollars.format (payment); //convert payment to currency formated string resultField.setText (resultStr); buttonClicked = true; //establish that the button has been clicked repaint(); }//actionPerformed public void paint(Graphics g) { if(buttonClicked) g.drawImage(frogImage,20,120,this); }//paint }//MaturityAppletPaint