Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Foodchain
Oct 13, 2005

Edit2:

I've ran in to this and have given up for the night.
code:
         array[0] = new Employee();
         ((Employee)array[0]).fillEmployee(input.readLine());
         System.out.println(array[0]);
         array[1] = new Employee();
         ((Employee)array[1]).fillEmployee(input.readLine());
         System.out.println(array[1]);
         array[2] = new Employee();
         ((Employee)array[2]).fillEmployee(input.readLine());
         System.out.println(array[2]);         
         System.out.println(array[1]);
Stores the employee stuff in element 0, prints it fine. Stores another employee in element 1, prints it fine. Stores another employee in element 2, prints it fine. When it tries to print any element such as 1 or 0 it just prints the data from element 2. Why?

Here's the full code to this if it helps you help me:

http://www.undergallows.com/Employee.java
http://www.undergallows.com/Company.java


-- end of edit -- the rest is old stuff that I figured out

Hey guys. So I'm working on a java homework project and I've come to a stop because I can't quite figure something out.

Why does this work (wage is set correctly)

code:
private int employeeID;
private int hours;
private double payRate;
private double wage;
    
public void fillEmployee(String input) {
    StringTokenizer in = new StringTokenizer(input);
    employeeID = Integer.parseInt(in.nextToken());
    hours = Integer.parseInt(in.nextToken());
    payRate = Double.parseDouble(in.nextToken());
    wage = payRate*hours;
}

public void computeWage() {
   wage = (payRate*hours);
}
and this does not (wage is just getting set to 0.00)

code:
private int employeeID;
private int hours;
private double payRate;
private double wage;

public void fillEmployee(String input) {
    StringTokenizer in = new StringTokenizer(input);
    employeeID = Integer.parseInt(in.nextToken());
    hours = Integer.parseInt(in.nextToken());
    payRate = Double.parseDouble(in.nextToken());
   // wage = payRate*hours;
}

public void computeWage() {
   wage = (payRate*hours);
}
I keep looking at it, and I just don't get it. It's probably some small newbie coder mistake that I'm missing here. I don't understand why I can set the wage from the fillEmployee method, but I can't set it from the computeWage method.

Edit: A little more thought and I solved my problem. I wasn't calling the computeWage method anywhere v:shobon:v I'm a terrible terrible programmer

Foodchain fucked around with this message at 07:00 on Mar 24, 2008

Adbot
ADBOT LOVES YOU

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply