Home arrow static arrow Java Programming [Archive] - Have a shot at fixing these errors/Puzzle
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - Have a shot at fixing these errors/Puzzle
This topic has 265 replies on 18 pages.    1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Next »

Posts:29
Registered: 6/3/04
Have a shot at fixing these errors/Puzzle  
Jun 3, 2004 5:34 AM



 
//This is the code anyone willing to have a crack at finding the errors go for it.
if successful full credit will be given, and thus earning the respect of my arrogant friend (and others) who dared me to find someone who could.
//Its a simple payslip calculation program drawing on .txt files for its data.
Have fun!!!!!
P.S if you think you have achieved success post the code in a reply for other to comment on.

import java.awt.*;
import java.awt.event.*;
import java.awt.swing.*;
import java.awt.io.*;
import java.awt.text.*;
import java.math.*;
import java.awt.util.*;

public class AllTheGoFrame extends JFrame

{
int maxEmployees = 100, maxGroups = 10, salary = 5050;
int employeeCount,groupCount,groupIndex,employeeIndex = 0;
int tabHere;

double pay,normal,overtime;
int hours;

char tab = '\t';

String[] employees = new String[maxEmployees];
String[][]groups = new String[maxGroups][2];

String thisEmployee = new String();
String employeeID = new String();
String employeeName = new String();
String employeeGroup = new String();
String employeeHours = new String();
String employeePay = new String();

Date today = new Date();

DecimalFormat dfmt = new DecimalFormat("0.0");
SimpleDateFormat sdfmt = new SimpleDateForma("d/M/yy");

//BEGIN GENERATED CODE
javax.swing.JButton startButton = new javax.swing.JButton();
javax.swing.JButton quitButton = new javax.swing.JButton();
javax.swing.JLabel titleLabel = new javax.swing.JLabel();
javax.swing.JLabel nameLabel = new javax.swing.JLabel();
javax.swing.JTextField nameTextField = new javax.swing.JTextField();
javax.swing.JLabel weekLabel = new javax.swing.JLabel();
javax.swing.JTextField dateTextField = new javax.swing.JTextField();
javax.swing.JLabel normalLabel = new javax.swing.JLabel();
javax.swing.JLabel overtimeLabel = new javax.swing.JLabel();
javax.swing.JLabel rateLabel = new javax.swing.JLabel();
javax.swing.JLabel payLabel = new javax.swing.JLabel();
javax.swing.JTextField normalTextField = new javax.swing.JTextField();
javax.swing.JTextField overtimeTextField = new javax.swing.JTextField();
javax.swing.JTextField rateLabel = new javax.swing.JTextField();
javax.swing.JTextField payTextField = new javax.swing.JTextField();
javax.swing.JButton nextButton = new javax.swing.JButton();

//END GENERATED CODE

public AllTheGoFrame()
{
}

public void initComponents() throws Exception

startButton.setText("Start");
startButton.setLocation(new java.awt.Point(50, 320));
startButton.setVisible(false);
startButton.setBackground(new java.awt.Color(0, 255, 0));
startButton.setSize(new java.awt.Dimension(110, 40));

quitButton.setText("Quit");
quitButton.setLocation(new java.awt.Point(50, 320));
quitButton.setVisible(true);
quitButton.setBackground(new java.awt.Color(255, 0, 0));
quitButton.setSize(new java.awt.Dimension(110, 40));

titleLabel.setText("All-The Go Couriers");
titleLabel.setLocation(new java.awt.Point(80, 10));
titleLabel.setVisible(true);
titleLabel.setFont(new java.awt.Font("Apple Chancery", 0, 72));
titleLabel.setHorizontalAlignment(0);
titleLabel.setSize(new java.awt.Dimension(240, 50));

nameLabel.setText("Employee name:");
nameLabel.setForeground(new java.awt.Color(0,0,0));
nameLabel.setLocation(new java.awt.Point(50, 105));
nameLabel.setVisible(true);
nameLabel.setSize(new java.awt.Dimension(110, 20));

nameTextField.setLocation(new java.awt.Point(150, 100));
nameTextField.setBackground(new java.awt.Color(255,255,255));
nameTextField.setVisible(true);
nameTextField.setSize(new java.awt.Dimension(210,30));
nameTextField.setEditable(false);

weekLabel.setText("Employee pay slip for week ending:");
weekLabel.setForeground(new java.awt.Color(0,0,0));
weekLabel.setLocation(new java.awt.Point(50, 70));
weekLabel.setVisible(true);
weekLabel.setSize(new java.awt.Dimension(250, 20));

dateTextField.setLocation(new java.awt.Point(310, 70));
dateTextField.setBackground(new java.awt.Color(255,255,255));
dateTextField.setVisible(true);
dateTextField.setSize(new java.awt.Dimension(70,20));
dateTextField.setEditable(false);

normalLabel.setText("Normal hours:");
normalLabel.setForeground(new java.awt.Color(0,0,0));
normalLabel.setLocation(new java.awt.Point(50, 145));
normalLabel.setVisible(true);

overtimeLabel.setText("Overtime hours:");
overtimeLabel.setForeground(new java.awt.Color(0,0,0));
overtimeLabel.setLocation(new java.awt.Point(50, 185));
overtimeLabel.setVisible(true);
overtimeLabel.setSize(new java.awt.Dimension(110, 20));

rateLabel.setText("Hourly rate:");
rateLabel.setForeground(new java.awt.Color(0,0,0));
rateLabel.setLocation(new java.awt.Point(50, 225));
rateLabel.setVisible(true);
rateLabel.setSize(new java.awt.Dimension(110, 20));

payLabel.setText("Pay:");
payLabel.setForeground(new java.awt.Color(0,0,0));
payLabel.setLocation(new java.awt.Point(50, 265));
payLabel.setVisible(true);
payLabel.setSize(new java.awt.Dimension(110, 20));

normalTextField.setLocation(new java.awt.Point(110, 140));
normalTextField.setBackground(new java.awt.Color(255,255,255));
normalTextField.setVisible(true);
normalTextField.setSize(new java.awt.Dimension(210,30));
normalTextField.setEditable(false);

overtimeTextField.setLocation(new java.awt.Point(120, 180));
overtimeTextField.setBackground(new java.awt.Color(255,255,255));
overtimeTextField.setVisible(true);
overtimeTextField.setSize(new java.awt.Dimension(210,30));
overtimeTextField.setEditable(false);

rateTextField.setLocation(new java.awt.Point(140, 220));
rateTextField.setBackground(new java.awt.Color(255,255,255));
rateTextField.setVisible(true);
rateTextField.setSize(new java.awt.Dimension(210,30));
rateTextField.setEditable(false);

payTextField.setLocation(new java.awt.Point(100, 260));
payTextField.setBackground(new java.awt.Color(255,255,255));
payTextField.setVisible(true);
payTextField.setSize(new java.awt.Dimension(210,30));
payTextField.setEditable(false);

nextButton.setText("Next...");
nextButton.setLocation(new java.awt.Point(260, 320));
nextButton.setVisible(false);
nextButton.setBackground(new java.awt.Color(255, 200, 0));
nextButton.setSize(new java.awt.Dimension(110, 40));

setLocation(new java.awt.Point(300,150));
setTitle("All-The-Go");
setBackground(new java.awt.Color(255, 255, 255));
getContentPane().setLayout(null);
setSize(new java.awt.Dimension(395, 367));

getContentPane().add(startButton);
getContentPane().add(quitButton);
getContentPane().add(titleLabel);
getContentPane().add(idTextField);
getContentPane().add(nameLabel);
getContentPane().add(nameTextField);
getContentPane().add(weekLabel);
getContentPane().add(dateTextField):
getContentPane().add(normalLabel);
getContentPane().add(overtimeLabel);
getContentPane().add(rateLabel);
getContentPane().add(payLabel);
getContentPane().add(normalTextField);
getContentPane().add(rateTextField);
getContentPane().add(payTextField);
getContentPane().add(nextButton);

startButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
startButtonActionPerformed(e);

}

});
quitButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
quitButtonActionPerformed(e);

}

});
nextButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
nextButtonActionPerformed(e);

}

});
addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent e) {
thisWindowClosing(e);
}
});

}

private boolean mShown = false;

public void addNotify()
{
super.addNotify();

if(mShown)
return;

JMenuBar jMenuBar = getJmenuBar();
if (jMenuBar !=null){
int jMenuBarHeight = jMenuBar.getPreferredSize().height;
Dimension dimension = getSize();
dimension.height += jMenuBarHeight;
setSize(dimension);

}

mShown = true;

}

void thisWindowClosing(java.awt.event.WindowEvent e)
{

setVisible(false);
dispose();
System.exit(0);

}

public void quitButtonActionPerformed(java.awt.event.ActionEvent e);
{

setVisible(false);
dispose();
System.exit(0);

}

public void startButtonActionPerformed(java.awt.event.ActionEvent e);
{

int index =0;

String nextLine = new String();

employeeIndex = 0;

try
{
String inFileName = "Employees.txt";
FileReader fr = new FileReader(inFileName);
BufferdReader br = new BufferedReader(fr);

while ((nextLine=br.readLine()) !=null);
{
employees[index]=nextLine;
index = index+1;

}
br.close();

emploeeCount=index - 1;
}catch(IOException ioe) {}

try
{
String inFileName = "Groups.txt";
FileReader fr = new FileReader(inFileName);
BufferedReader br = new BufferedReader(fr);

index = 0;
while((nextLine=br.readLine()) !=null)
{

howmany = nextLine.length();
tabHere=nextLine.indexOf(tab);
//Stores name of group
groups[index][0] = nextLine.substring(0,tabHere);
//Store the hourly rate of the group
groups[index][1] = nextLine.substring(tabHere + 1,howmany);
index = index +1;

}
br.close();

groupCount = index - 1;

jButton1.setVisible(true);
jButton2.setVisible(false);
jButton3.setVisible(false);
}catch (IOException ioe) {}

}

public void nextButtonActionPerformed(java.awt.event.ActionEvent e)
{

if(employeeIndex == employeeCount)
{
employeeIndex = 0;
}

thisEmployee = employees[employeeIndex];
howmany = thisEmployee.length();
tabHere = thisEmployee.indexOf(tab);
employeeID = thisEmployee.substring(0,tabHere);
thisEmployee = thisEmployee.substring(tabHere + 1,howmany);

howmany = thisEmployee.length();
tabHere = thisEmployee.indexOf(tab);
employeeName = thisEmployee.substring(0,tabHere);
thisEmployee = thisEmployee.substring(tabHere = 1, howmany);

howmany = thisEmployee.length();
tabHere = thisEmployee.indexOf(tab);
employeeGroup = thisEmployee.substring(0, tabHere);

if(employeeGroup.equals("Administration"))
{
normal=0;
overtime=0;
rate=0;
pay=salary/26

}
else

{
thisEmployee=thisEmployee.substring(tabHere + 1,howmany);

try

{
Double D = Double(thisEmployee);
hours = D.doubleValue();
}catch(NumberFormatException nfe) {}

rate = 0;

for(groupIndex=0;groupIndex<= groupCount;groupIndex++)
{

if(groups[groupIndex][0].equals(employeeGroup))
{

try
{

Double D = new Double(groups[groupIndex][1]);
rate=D.doubleValue();
}catch(NumberFormatException nfe){}
break;

}
}

if(hours>40)
{

normal = 40;
overtime = hours -40;

}
else
{

normal = hours;
overtime = 0;

}

pay = normal + overtime * rate * 1.5;

}

employeePay = dfmt.format(pay);

dateTextField.setText(sdfmt.format(today));
nameTextField.setText(employeeName);
normalTextField.setText(normal + "");
overtimeTextField.setText(overtime + "");
rateTextField.setText("$" + dfmt.format(rate) + "/hr");
payTextFiled.setText("$" + dfmt.format(pay));

employeeIndex = employeeIndex;
}

}

 

Posts:24,036
Registered: 2/3/03
Re: Have a shot at fixing these errors/Puzzle  
Jun 3, 2004 5:41 AM (reply 1 of 265)



 
1) No, we're not going to do your homework for you.

2) When you post code, please use [code] and [/code] tags as described in [url=http://forum.java.sun.com/features.jsp#Formatting]Formatting Help[/url] on the message entry page. It makes it much easier to read.

3) Please be a little more explicit about what you expect to happen, and what you actually observe.

4) Please post a short, concise, executable example of what you're trying to do. This does not have to be the actual code you are using. Write a small example that demonstrates your intent, and only that. Wrap the code in a class and give it a main method that runs it - if we can just copy and paste the code into a text file, compile it and run it without any changes, then we can be sure that we haven't made incorrect assumptions about how you are using it.

5) If you have an error message, post the exact, complete error along with a full stack trace, if possible.

6) While waiting for your personal forum slaves to hand you the answer to your problem, pass the time by pretending that you know how to read and do research, and see if you can find the answer before your slaves deliver it to you. Boy, won't they feel stupid.

§
 

Posts:29
Registered: 6/3/04
Re: Have a shot at fixing these errors/Puzzle  
Jun 3, 2004 5:53 AM (reply 2 of 265)



 
I did not ask for the third degree, its quite self explanitory have a crack or dont. Its simple. Its not my homework its a friends bet whether you see the fun side in it or not i dont really care just dont waste my time and others with judgemental replies. I will post how i want to post if you cant be bothered to read a few lines dont bother reading it, im sure that by the time you wrote that pointless reply you could have read the the code.
 

Posts:7,499
Registered: 02-11-14
Re: Have a shot at fixing these errors/Puzzle  
Jun 3, 2004 5:59 AM (reply 3 of 265)



 
I did not ask for the third degree, its quite self
explanitory have a crack or dont. Its simple. Its not
my homework its a friends bet whether you see the fun
side in it or not i dont really care just dont waste
my time and others with judgemental replies. I will
post how i want to post if you cant be bothered to
read a few lines dont bother reading it, im sure that
by the time you wrote that pointless reply you could
have read the the code.

Before you go off taking offense, yawmark was merely trying to give you hints on how to get better, quicker answers to your questions. In other words, he was trying to help you, even if not the way you expected. Please don't go off loose cannon. (and before you go off on me for my judgment, the more responses like this one you put up, the less likely you are to get those who post here often to answer your question).
 

Posts:5,119
Registered: 16.08.01
Re: Have a shot at fixing these errors/Puzzle  
Jun 3, 2004 6:13 AM (reply 4 of 265)



 
I did not ask for the third degree, its quite self
explanitory have a crack or dont. Its simple. Its not
my homework its a friends bet whether you see the fun
side in it or not i dont really care just dont waste
my time and others with judgemental replies. I will
post how i want to post if you cant be bothered to
read a few lines dont bother reading it, im sure that
by the time you wrote that pointless reply you could
have read the the code.

If yawmark reply is pointless to you, I won't bother to help either.
 

Posts:24,036
Registered: 2/3/03
Re: Have a shot at fixing these errors/Puzzle  
Jun 3, 2004 6:21 AM (reply 5 of 265)



 
whether you see the fun side in it or not i dont really care...

And I don't care whether you get your "fun" question answered or not. As stevejluke pointed out, I'm trying to help you get an answer around here. If you can't remedy your cranial-rectal inversion problem, you're going to have a tough time on these forums...
 

Posts:31,095
Registered: 4/30/99
Re: Have a shot at fixing these errors/Puzzle  
Jun 3, 2004 8:24 AM (reply 6 of 265)



 
It would be easy to find any compile-time errors by just running the compiler. No fun there, and I can't believe your alleged arrogant friend would be so stupid as to challenge people to find those, so I'm not going to bother. As for run-time errors, without the specs describing what the program is supposed to do, it would be impossible to find them. So I'm not going to bother with that either.

If you have a real problem you need solved, we're all willing to help with that. A decent description of the problem is all you need to post.
 

Posts:3,534
Registered: 9/30/99
Re: Have a shot at fixing these errors/Puzzle  
Jun 3, 2004 8:44 AM (reply 7 of 265)



 
You know, I get 100+ dollars an hour for doing just this type of stuff, why would I do it for free when you are so arogant to those that have made suggestions already?

Incase you haven't noticed, this is not a high school or college homework forum.
 

Posts:1,183
Registered: 1/23/02
Re: Have a shot at fixing these errors/Puzzle  
Jun 3, 2004 8:47 AM (reply 8 of 265)



 
just dont waste my time

?
 

Posts:4,680
Registered: 6/14/99
Re: Have a shot at fixing these errors/Puzzle  
Jun 3, 2004 8:58 AM (reply 9 of 265)



 
Okay I think I'll have a shot at it )):o(
 

Posts:4,680
Registered: 6/14/99
Re: Have a shot at fixing these errors/Puzzle  
Jun 3, 2004 8:58 AM (reply 10 of 265)



 
Nope I can't get it, sorry!

BTW morgalr ... that's pretty good $$$, good for you!
 

Posts:6,750
Registered: 1/25/04
Re: Have a shot at fixing these errors/Puzzle  
Jun 3, 2004 9:17 AM (reply 11 of 265)



 
Okay I think I'll have a shot at it )):o(

I like your "thinking hard" emoticon. :-)
 

Posts:19,725
Registered: 9/26/01
Re: Have a shot at fixing these errors/Puzzle  
Jun 3, 2004 9:25 AM (reply 12 of 265)



 
<marlon brando>
(wheeze) Do ma homework fo me or Guido'll give ya a "visit", CAPEESH?
</marlon brando>
 

Posts:1,183
Registered: 1/23/02
Re: Have a shot at fixing these errors/Puzzle  
Jun 3, 2004 9:28 AM (reply 13 of 265)



 
That's what we in the industry call a rough anal pounding.
 

Posts:24,036
Registered: 2/3/03
Re: Have a shot at fixing these errors/Puzzle  
Jun 3, 2004 9:31 AM (reply 14 of 265)



 
That's what we in the industry call a rough anal pounding.

I guess I'm thankful you're not a Corrections Officer.
 
This topic has 265 replies on 18 pages.    1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | Next »