I am trying to format my code and I cant seem to get it right any help would be greatly appreciated. I am very new to Java.
When I enter my Minutes and Earnings in the JTextFields I need it to out put what it looks like below to the JTextArea
***********************************
Raw Tutoring Earnings Data
Minutes Earnings
60.0 10.0
120.0 40.0
45.0 8.0
then when i hit the run report button it should look like this:
Minutes= 10.0 Earnings= 10.0
Minutes= 10.0 Earnings= 10.0
Minutes= 10.0 Earnings= 10.0
****************************************************
Report of your wages to Date:
Total Minutes Spent Tutoring = 30.0
Total Earnings = $30.0
Average Per Hour Wage = $7.5
Minimum Wage is Currently = $7.25 per hour
Your average wages per hour are Average
And right now after i enter the minutes and earnings and hit enter it looks like this:
Minutes= 10.0 Earnings= 10.0
Minutes= 10.0 Earnings= 10.0
Minutes= 10.0 Earnings= 10.0
And after I hit the Run Report button it looks like this:
Minutes= 10.0 Earnings= 10.0
Minutes= 10.0 Earnings= 10.0
Minutes= 10.0 Earnings= 10.0
****************************************************
Raw Tutoring Earnings Data
Minutes Earnings
10.0 10.0 0.0 0.0
10.0 10.0 0.0 0.0
10.0 10.0 0.0 0.0
0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0
**************************************************
Report of your wages to Date:
Total Minutes Spent Tutoring = 30.0
Total Earnings = $30.0
Average Per Hour Wage = $7.5
Minimum Wage is Currently = $7.25 per hour
Your average wages per hour are Average
I was thinking it might be an easy fix but I am just not finding it.
When I enter my Minutes and Earnings in the JTextFields I need it to out put what it looks like below to the JTextArea
***********************************
Raw Tutoring Earnings Data
Minutes Earnings
60.0 10.0
120.0 40.0
45.0 8.0
then when i hit the run report button it should look like this:
Minutes= 10.0 Earnings= 10.0
Minutes= 10.0 Earnings= 10.0
Minutes= 10.0 Earnings= 10.0
****************************************************
Report of your wages to Date:
Total Minutes Spent Tutoring = 30.0
Total Earnings = $30.0
Average Per Hour Wage = $7.5
Minimum Wage is Currently = $7.25 per hour
Your average wages per hour are Average
And right now after i enter the minutes and earnings and hit enter it looks like this:
Minutes= 10.0 Earnings= 10.0
Minutes= 10.0 Earnings= 10.0
Minutes= 10.0 Earnings= 10.0
And after I hit the Run Report button it looks like this:
Minutes= 10.0 Earnings= 10.0
Minutes= 10.0 Earnings= 10.0
Minutes= 10.0 Earnings= 10.0
****************************************************
Raw Tutoring Earnings Data
Minutes Earnings
10.0 10.0 0.0 0.0
10.0 10.0 0.0 0.0
10.0 10.0 0.0 0.0
0.0 0.0 0.0 0.0
0.0 0.0 0.0 0.0
**************************************************
Report of your wages to Date:
Total Minutes Spent Tutoring = 30.0
Total Earnings = $30.0
Average Per Hour Wage = $7.5
Minimum Wage is Currently = $7.25 per hour
Your average wages per hour are Average
I was thinking it might be an easy fix but I am just not finding it.
import javax.swing.JOptionPane;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author AlanDesktop
*/
public class Task1UI extends javax.swing.JFrame {
double[][] array = new double[10][4];
int index = 0;
double tutoringMins = 0;
double earnings = 0;
static final String lineSeparator = System.getProperty("line.separator");
/**
* Creates new form Task1UI
*/
public Task1UI() {
initComponents();
//set the title
setTitle("Tutoring Wages Report");
}
/**
* 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 Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jMenu1 = new javax.swing.JMenu();
jpanel = new javax.swing.JPanel();
enterMinutes = new javax.swing.JTextField();
jScrollPane1 = new javax.swing.JScrollPane();
Report = new javax.swing.JTextArea();
jLabel1 = new javax.swing.JLabel();
runReportButton = new javax.swing.JButton();
enterButton = new javax.swing.JButton();
quitButton = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
enterDollarCents = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jMenu1.setText("jMenu1");
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jpanel.setBackground(new java.awt.Color(51, 255, 255));
jpanel.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createTitledBorder(null, "", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, new java.awt.Color(255, 51, 51)), "Tutoring Earnings", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Bookman Old Style", 1, 10), new java.awt.Color(0, 0, 0))); // NOI18N
enterMinutes.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
enterMinutesActionPerformed(evt);
}
});
Report.setColumns(20);
Report.setRows(5);
jScrollPane1.setViewportView(Report);
jLabel1.setText("Number of Minutes for Tutoring Session:");
runReportButton.setText("Run Report");
runReportButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
runReportButtonActionPerformed(evt);
}
});
enterButton.setText("Enter");
enterButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
enterButtonActionPerformed(evt);
}
});
quitButton.setText("Quit");
quitButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
quitButtonActionPerformed(evt);
}
});
jLabel2.setText("Earning in Dollar and cents Recieved:");
enterDollarCents.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
enterDollarCentsActionPerformed(evt);
}
});
jLabel3.setText("Results:");
javax.swing.GroupLayout jpanelLayout = new javax.swing.GroupLayout(jpanel);
jpanel.setLayout(jpanelLayout);
jpanelLayout.setHorizontalGroup(
jpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jpanelLayout.createSequentialGroup()
.addContainerGap()
.addGroup(jpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2)
.addComponent(jLabel3)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(jpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jpanelLayout.createSequentialGroup()
.addComponent(enterButton)
.addGap(42, 42, 42)
.addComponent(runReportButton, javax.swing.GroupLayout.PREFERRED_SIZE, 106, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(quitButton, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
.addGroup(jpanelLayout.createSequentialGroup()
.addGroup(jpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(enterMinutes, javax.swing.GroupLayout.DEFAULT_SIZE, 266, Short.MAX_VALUE)
.addComponent(enterDollarCents))
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 472, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(0, 68, Short.MAX_VALUE))))
);
jpanelLayout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {enterButton, runReportButton});
jpanelLayout.setVerticalGroup(
jpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jpanelLayout.createSequentialGroup()
.addGap(19, 19, 19)
.addGroup(jpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 29, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(enterMinutes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addGroup(jpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(enterDollarCents, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(26, 26, 26)
.addGroup(jpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jpanelLayout.createSequentialGroup()
.addComponent(jLabel3)
.addGap(0, 0, Short.MAX_VALUE))
.addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 217, Short.MAX_VALUE))
.addGap(18, 18, 18)
.addGroup(jpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpanelLayout.createSequentialGroup()
.addComponent(quitButton)
.addGap(21, 21, 21))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jpanelLayout.createSequentialGroup()
.addGroup(jpanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(enterButton)
.addComponent(runReportButton))
.addGap(35, 35, 35))))
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jpanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jpanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
pack();
}// </editor-fold>
private void enterMinutesActionPerformed(java.awt.event.ActionEvent evt) {
//Code Exception error messages when data keyed incorrectly for both textfields
}
private void quitButtonActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}
private void enterDollarCentsActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void enterButtonActionPerformed(java.awt.event.ActionEvent evt) {
//if minutes entered do not meet whats required exception will be thrown
try {
tutoringMins = Double.parseDouble(
this.enterMinutes.getText());
if (tutoringMins <= 0 || tutoringMins > 240) {
throw new Exception();
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Invalid input. Please try again",
"Error", JOptionPane.ERROR_MESSAGE);
return;
}
try {
earnings = Double.parseDouble(
this.enterDollarCents.getText());
if (earnings <= 0) {
throw new Exception();
}
} catch (Exception e) {
JOptionPane.showMessageDialog(this, "Invalid input. Earnings must be greater than zero. Please try again", "Error", JOptionPane.ERROR_MESSAGE);
return;
}
array[index][0] = tutoringMins;
array[index][1] = earnings;
String message = "";
for (int i = 0; i <= index; i++) {
message += "Minutes= " + array[i][0] + " " + "Earnings= " + array[i][1] + "\n";
Report.setText(message);
}
this.enterMinutes.setText("");
this.enterDollarCents.setText("");
index++;
}
private void runReportButtonActionPerformed(java.awt.event.ActionEvent evt) {
//program will add, total and sum entered information
int cols = 4;
int rows = array[0].length;
double timeSpentTotal = 0.00;
double earningsTotal = 0.00;
double averageWage = 0.00;
double minimumWage = 7.25;
String report = new String();
report += "****************************************************\n\n";
report += "Raw Tutoring Earnings Data\n\n";
report += "\n";
report += "Minutes Earnings\n";
for (int i = 0; i < rows+1; i++) {
for (int j = 0; j < cols; j++) {
report += array[i][j];
report += " ";
if (j == 0) {
timeSpentTotal += array[i][j];
} else if (j == 1) {
earningsTotal += array[i][j];
}
}
report += "\n";
}
if (array[0].length > 0) {
averageWage = earningsTotal / array[0].length;
}
report += "**************************************************\n\n";
report += "Report of your wages to Date:\n";
report += "\n";
report += "Total Minutes Spent Tutoring = " + timeSpentTotal + "\n";
report += "Total Earnings = $" + earningsTotal + "\n";
report += "Average Per Hour Wage = $" + averageWage + "\n";
report += "Minimum Wage is Currently = $" + minimumWage + " per hour" + "\n";
report += "Your average wages per hour are ";
if (averageWage < minimumWage) {
report += "Below Average";
} else if (averageWage >= minimumWage && averageWage <= minimumWage * 2.00) {
report += "Average";
} else if (averageWage > minimumWage * 2.00) {
report += "Above Average";
}
Report.append(report);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Task1UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Task1UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Task1UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Task1UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/* Create and display the form */
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Task1UI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JTextArea Report;
private javax.swing.JButton enterButton;
private javax.swing.JTextField enterDollarCents;
private javax.swing.JTextField enterMinutes;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JMenu jMenu1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JPanel jpanel;
private javax.swing.JButton quitButton;
private javax.swing.JButton runReportButton;
// End of variables declaration
}