Public feed #381374

Anonymous

public text v1 · immutable
Raw Edit
·published 2007-03-04 20:27 UTC
rendered paste body
/****************************************************************/
/*                      jobSim - by Evil_	                    */
/*                  used JFrameBuilder for GUI                  */
/****************************************************************/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
 *
 * Just a thing I made to do my HomeWork assignment for me,
 * you put in the amount you make per hour (Hourly wages), how much you
 * work per week, and the bills.
 *
 */
public class jobSim extends JFrame
{
	// Bill Variables
	private double hrly;
    private double hrwk;
    private double rent;
    private double wtrbl;
    private double elec;
    private double fone;
    private double carp;
    private double cable;
    private double carins;
    private double gar;
    // Bill Variables End
    
	// Variables declaration
	private JTextArea txt;
	private JScrollPane jScrollPane1;
	private JButton st;
	private JButton re;
	private JButton cl;
	private JPanel contentPane;
	// End of variables declaration
 
 
	public jobSim()
	{
		super();
		initializeComponent();
		//
		// TODO: Add any constructor code after initializeComponent call
		//
 
		this.setVisible(true);
	}
 
	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always regenerated
	 * by the Windows Form Designer. Otherwise, retrieving design might not work properly.
	 * Tip: If you must revise this method, please backup this GUI file for JFrameBuilder
	 * to retrieve your design properly in future, before revising this method.
	 */
	private void initializeComponent()
	{
		txt = new JTextArea();
		jScrollPane1 = new JScrollPane();
		st = new JButton();
		re = new JButton();
		cl = new JButton();
		contentPane = (JPanel)this.getContentPane();
 
		//
		// txt
		//
		//
		// jScrollPane1
		//
		jScrollPane1.setViewportView(txt);
		//
		// st
		//
		st.setText("Start");
		st.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e)
			{
				st_actionPerformed(e);
			}
 
		});
		//
		// re
		//
		re.setText("Reset");
		re.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e)
			{
				re_actionPerformed(e);
			}
 
		});
		//
		// cl
		//
		cl.setText("Close");
		cl.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e)
			{
				cl_actionPerformed(e);
			}
 
		});
		//
		// contentPane
		//
		contentPane.setLayout(null);
		addComponent(contentPane, jScrollPane1, 3,53,458,378);
		addComponent(contentPane, st, 62,13,83,28);
		addComponent(contentPane, re, 191,14,83,28);
		addComponent(contentPane, cl, 322,16,83,28);
		//
		// jobSim
		//
		this.setTitle("jobSim - made by Evil_");
		this.setLocation(new Point(0, 0));
		this.setSize(new Dimension(471, 469));
		this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		this.setResizable(false);
	}
 
	/** Add Component Without a Layout Manager (Absolute Positioning) */
	private void addComponent(Container container,Component c,int x,int y,int width,int height)
	{
		c.setBounds(x,y,width,height);
		container.add(c);
	}
 
	//
	// TODO: Add any appropriate code in the following Event Handling Methods
	//
	private void re_actionPerformed(ActionEvent e)
	{
		txt.setText("");
		hrly = -1;
		hrwk = -1;
		rent = -1;
		wtrbl = -1;
		elec = -1;
		fone = -1;
		carp = -1;
		cable = -1;
		gar = -1;
		carins = -1;	
	}
 
	private void cl_actionPerformed(ActionEvent e)
	{
		System.exit(0);
	}
	
	private void st_actionPerformed(ActionEvent e)
	{
        JOptionPane.showMessageDialog(null, "DO NOT INCLUDE A $ WITH ANY OF THESE NUMBERS!");
        hrly = Double.parseDouble(JOptionPane.showInputDialog("What are the Hourly Wages?"));
        hrwk = Integer.parseInt(JOptionPane.showInputDialog("What are the Hours Worked Per Week?"));
        rent = Double.parseDouble(JOptionPane.showInputDialog("What is the rent?"));
        wtrbl = Double.parseDouble(JOptionPane.showInputDialog("What is the Water Bill Payment?"));
        elec = Double.parseDouble(JOptionPane.showInputDialog("What is the Electric bill?"));
        fone = Double.parseDouble(JOptionPane.showInputDialog("What is the Phone Bill?"));
        carp = Double.parseDouble(JOptionPane.showInputDialog("What is the Car Payment?"));
        cable = Double.parseDouble(JOptionPane.showInputDialog("What is the Cable Bill?"));
        gar = Double.parseDouble(JOptionPane.showInputDialog("What is the Garbage Bill?"));
        carins = Double.parseDouble(JOptionPane.showInputDialog("What is the Car Insurance Payment?"));
        averageIt();
    }
 
    private void printPrices()
    {
        writeLn("Hourly Wages: $" + hrly);
        writeLn("Hours Worked Per Week: $" + hrwk);
        writeLn("");
        writeLn("Rent: $" + rent);
        writeLn("Water Bill: $" + wtrbl);
        writeLn("Electric Bill: $" + elec);
        writeLn("Phone Bill: $" + fone);
        writeLn("Car Payment: $" + carp);
        writeLn("Cable Bill: $" + cable);
        writeLn("Garbage Bill: $" + gar);
        writeLn("Car Insurance Payment: $" + carins);
    }
 
    private void averageIt()
    {
        printPrices();
        writeLn("");
        writeLn("");
        double weeklyPay = hrly * hrwk;
        double monthlyPay = weeklyPay * 4;
        double incTax = monthlyPay * .15;
        double socSec = monthlyPay * .05;
        double bigTaxLoss = incTax + socSec;
        monthlyPay = monthlyPay - bigTaxLoss;
        writeLn("Money made per month, after taxes: $" + monthlyPay);
        double moneyForBills = rent + wtrbl + elec + fone + carp + cable + gar + carins;
        monthlyPay = monthlyPay - moneyForBills;
        writeLn("");
        writeLn("After paying the bills ($"+moneyForBills+"), you have: $" + monthlyPay);
    }
 
    private void writeLn(String s)
    {
        txt.append(s + "\n");
    }
 
	public static void main(String[] args)
	{
		JFrame.setDefaultLookAndFeelDecorated(true);
		JDialog.setDefaultLookAndFeelDecorated(true);
		try
		{
			UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
		}
		catch (Exception ex)
		{
			System.out.println("Failed loading L&F: ");
			System.out.println(ex);
		}
		new jobSim();
	}
}