All pastes #2061343 Raw Edit

Java

public text v1 · immutable
#2061343 ·published 2011-05-16 12:20 UTC
rendered paste body
//Josh Crichton
//Programming - Mr. Tennant
//Proj4_5 - Currency Converter

import java.awt.*;
import java.applet.*;
import java.awt.event.*;

public class Proj4_5 extends Applet implements ActionListener
{


Button button1, button2, button3, button4, button5, button6;
Label label1, label2, label3;
TextField text1, text2, text3;

Float dollars1, xRate1;
float forgnCurr1;
Float forgnCurr2, xRate2;
float dollars2;
Float principal, intRate, months;
double period, payment;

public void init()
{

setLayout(null);

button1 = new Button ("$ to EGP (Egyptian)");
button1.setBounds(30, 30, 150, 30);
add(button1);
button1.addActionListener(this);

button2 = new Button ("EGP (Egyptian) to $");
button2.setBounds(200, 30, 150, 30);
add(button2);
button2.addActionListener(this);

button3 = new Button ("Simple Loan");
button3.setBounds(370, 30, 150, 30);
add(button3);
button3.addActionListener(this);

button4 = new Button ("Convert $");
button4.setBounds(30, 240, 150, 30);
add(button4);
button4.addActionListener(this);
button4.hide();

button5 = new Button ("Convert Foreign Currency");
button5.setBounds(200, 240, 150, 30);
add(button5);
button5.addActionListener(this);
button5.hide();

button6 = new Button ("Foreign Currency to $");
button6.setBounds(370, 240, 150, 30);
add(button6);
button6.addActionListener(this);
button6.hide();

label1 = new Label();
label1.setBounds(30, 90, 150, 15);
add(label1);
label1.hide();

text1 = new TextField(10);
text1.setBounds(180, 90, 150, 20);
add(text1);
text1.hide();

label2 = new Label();
label2.setBounds(30, 120, 150, 15);
add(label2);
label2.hide();

text2 = new TextField(10);
text2.setBounds(180, 120, 150, 20);
add(text2);
text2.hide();

label3 = new Label();
label3.setBounds(30, 150, 150, 15);
add(label3);
label3.hide();

text3 = new TextField(10);
text3.setBounds(180, 150, 150, 20);
add(text3);
text3.hide();

}

public void actionPerformed(ActionEvent e)
{


if (e.getSource() == button1)
{
	label1.setText("Amount in $:");
	label1.show();
	text1.show();
	
	label2.setText("Foreign Currency Name:");
	label2.show();
	text2.show();
	
	label3.setText("Exchange Rate:");
	label3.show();
	text3.show();
	
	button4.show();
	button5.hide();
	button6.hide();
	
	}
	
if (e.getSource() == button2)
	{
		label1.setText("Amount in Foreign Currency:");
		label1.show();
		text1.show();
		
	label2.setText("Foreign Currency Name:");
	label2.show();
	text2.show();
	
	label3.setText("Exchange Rate:");
	label3.show();
	text3.show();
	
	button5.show();
	button6.hide();
	button4.hide();
		
	}
	
	if (e.getSource() == button3)
	{
	
	label1.setText("Amount borrowed:");
	label1.show();
	text1.show();	
	
	label2.setText("Interest rate (x.xx):");
	label2.show();
	text2.show();
	
	label3.setText("Months borrowed:");
	label3.show();
	text3.show();
	
	button6.show();
	button4.hide();
	button5.hide();
	}
	
	if (e.getSource() == button4)
	{
		dollars1 = Float.valueOf(text1.getText());
		text2.getText();
		xRate1 = Float.valueOf(text3.getText());
		forgnCurr1 = dollars1.floatValue() * xRate1.floatValue();
		
		showStatus("This amount of dollars converts to " + forgnCurr1 + " " + text2.getText() + ".");
		}
	
	if (e.getSource() == button5)
	{
		forgnCurr2 = Float.valueOf(text1.getText());
		text2.getText();
		xRate2 = Float.valueOf(text3.getText());
		dollars2 = forgnCurr2.floatValue() * xRate2.floatValue();
		
		showStatus("This amount " + text2.getText() + " converts to " + dollars2 + " dollars.");
	}
	
	if (e.getSource() == button6)
	{
		principal = Float.valueOf(text1.getText());
		intRate = Float.valueOf(text2.getText());
		months = Float.valueOf(text3.getText());
		
		period = months.floatValue() * 30/365;
		payment = principal.floatValue() + (principal.floatValue() * ((intRate.floatValue() / 100) * period));
		showStatus("The total amount you will owe is " + payment + ".");
		
	}
	}
	}