In reference to a message posted on Feb 07 at 8:11pm with the subject "Need Help."
I've taking CSC 160 (
Java) and I'm still teaching myself programming and Java. I'm since transferred to another university that will not teaching java, but rather, C++. I thought I would give this problem a shot. Can someone review my program and let me know how I did on my approach.
//Gross.java
//Will calculate payrol for 3 employees
import java.awt.Container;
import javax.swing.*;
import java.text.DecimalFormat;
public class Gross {
public static void main(
String args [] )
{
String employee1, employee1Hours, employee1Rate,
employee2, employee2Hours, employee2Rate,
employee3, employee3Hours, employee3Rate;
int e1, e2, e3;
double e1R, e1H, e2H, e3H, e2R, e3R, e1P, e2P, e3P;
// Prompt user for first employee name
employee1 = JOptionPane.showInputDialog(
"Enter the first employee's name. ");
// Prompt user for the first employee hours
employee1Hours = JOptionPane.showInputDialog(
"Enter the first employee's hours\n" +
"for the week. ");
// Prompt user for the first employee's rate
employee1Rate = JOptionPane.showInputDialog(
"Enter the first employee's pay rate. ");
// Prompt user for second employee name
employee2 = JOptionPane.showInputDialog(
"Enter the second employee's name. ");
// Prompt user for the second employee hours
employee2Hours = JOptionPane.showInputDialog(
"Enter the second employee's hours\n" +
"for the week. ");
// Prompt user for the second employee's rate
employee2Rate = JOptionPane.showInputDialog(
"Enter the second employee's pay rate. ");
// Prompt user for third employee name
employee3 = JOptionPane.showInputDialog(
"Enter the third employee's name. ");
// Prompt user for the third employee hours
employee3Hours = JOptionPane.showInputDialog(
"Enter the third employee's hours\n" +
"for the week. ");
// Prompt user for the third employee's rate
employee3Rate = JOptionPane.showInputDialog(
"Enter the third employee's pay rate. ");
// Conversion of strings to doubles
e1H = Integer.parseInt( employee1Hours );
e2H = Integer.parseInt( employee2Hours );
e3H = Integer.parseInt( employee3Hours );
e1R = Double.parseDouble( employee1Rate );
e2R = Double.parseDouble( employee2Rate );
e3R = Double.parseDouble( employee3Rate );
DecimalFormat twoDigits = new DecimalFormat( "0.00" );
// Calculation of all employees Pay
if ( e1H <= 40 )
e1P = (double) e1H * e1R;
else
e1P = (double) ((e1H * 2) + (e1H/2)) * e1R;
if ( e2H <= 40 )
e2P = (double) e2H * e2R;
else
e2P = (double) ((e2H * 2) + (e2H / 2)) * e2R;
if ( e3H <= 40 )
e3P = (double) e3H * e3R;
else
e3P = (double) ((e3H * 2) + (e3H / 2)) * e3R;
JTextArea outputArea = new JTextArea( 4, 20 );
outputArea.setText( "Name\tHours\tPay" +
"\n" + employee1 + "\t" + e1H + "\t" + "$" + twoDigits.format( e1P ) +
"\n" + employee2 + "\t" + e2H + "\t" + "$" + twoDigits.format( e2P ) +
"\n" + employee3 + "\t" + e3H + "\t" + "$" + twoDigits.format( e3P ) );
JOptionPane.showMessageDialog( null, outputArea,
"Last Week's Pay",
JOptionPane.INFORMATION_MESSAGE );
System.exit( 0 );
}
}