• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Java class produces no ouput when ran

Joined
Nov 26, 2006
Messages
620
Ok so for a hw assignment thats due tomorrow I had to create a class that creates objects with certain attributes and then a test class that creates five objects and set values for them and then prints out the data based on a tostring method in the first class. Anyway the two classes are below, the only problem is when I try to run the testclass in netbeans the output looks like this

init:
deps-jar:
Compiling 1 source file to K:\Weaver_Joseph_Cop2250_U03_Spring2008\Projects\Project 5\build\classes
compile-single:
run-single:
BUILD SUCCESSFUL (total time: 0 seconds)

as you can see the class doesn't produce any ouput like it should... I even put in a test println and it doesnt show up either

Code:
package project5;
import java.text.NumberFormat;

public class HourlyEmployee {
    
    private String name;
    private String position;
    private double rate;
    private double hours;
    private double pay;
    
    public HourlyEmployee(String aName, String aPosition, double aRate) {
        name = aName;
        position= aPosition;
        rate = aRate;
    }
    public double getpay(){
        pay = hours * rate;
        if (hours > 40)
            pay += (hours - 40) * rate *1.5;
        return pay;
    }
    public void work(double time){
        hours += time;
    }
    public void setaRaise(double inc){
        rate+= inc;
    }
    public boolean equals(String aName,String aPosition,double aRate) {
        
        if (name==aName && position == aPosition && rate == aRate){
            System.out.println("true");
            return true;
        }
        
        else System.out.println("false");
        return false;
    }
    public String toString(){
        NumberFormat nf = NumberFormat.getCurrencyInstance();
        return ("\n=======================" + "\nEmployee:" + name + "\nPosition:" + position
                + "\nPay Rate:" +rate + "\nHours Worked:" + hours + "\nHours" + nf.format(pay) );
    }
}
Code:
import project5.HourlyEmployee;
public class HourlyEmployeeTest {
    public static void main(String arguments[]) {
        System.out.println("TESTING");
        //create two HourlyEmployee objects
        HourlyEmployee emp1 = new HourlyEmployee("Joseph Weaver","Ruler of the Known Universe",300);
        HourlyEmployee emp2 = new HourlyEmployee("Joseph Weaver","Ruler of the Known Universe",300);
        HourlyEmployee emp3 = new HourlyEmployee("Clone of Joseph Weaver","Personal bodyguard and double",8);
        HourlyEmployee emp4 = new HourlyEmployee("Andrew","Teacher",50);
        HourlyEmployee emp5 = new HourlyEmployee("Batman","Crime Fighter",0);
        emp1.work(38);
        emp2.work(168);
        emp3.work(20);
        emp4.work(48);
        emp5.work(84);
        System.out.println(emp1);
        System.out.println(emp2);
        System.out.println(emp3);
        System.out.println(emp4);
        System.out.println(emp5);
        emp1.setaRaise(1);
        emp2.setaRaise(1);
        emp3.setaRaise(1);
        emp4.setaRaise(1);
        emp5.setaRaise(1);
        emp1.work(38);
        emp2.work(168);
        emp3.work(20);
        emp4.work(48);
        emp5.work(84);
        System.out.println(emp1);
        System.out.println(emp2);
        System.out.println(emp3);
        System.out.println(emp4);
        System.out.println(emp5);
    }
}
 
have you tried just running it at a command prompt or shell?

edit: i ran your code and received the following output..

Code:
TESTING

=======================
Employee:Joseph Weaver
Position:Ruler of the Known Universe
Pay Rate:300.0
Hours Worked:38.0
Hours$0.00

=======================
Employee:Joseph Weaver
Position:Ruler of the Known Universe
Pay Rate:300.0
Hours Worked:168.0
Hours$0.00

=======================
Employee:Clone of Joseph Weaver
Position:Personal bodyguard and double
Pay Rate:8.0
Hours Worked:20.0
Hours$0.00

=======================
Employee:Andrew
Position:Teacher
Pay Rate:50.0
Hours Worked:48.0
Hours$0.00

=======================
Employee:Batman
Position:Crime Fighter
Pay Rate:0.0
Hours Worked:84.0
Hours$0.00

=======================
Employee:Joseph Weaver
Position:Ruler of the Known Universe
Pay Rate:301.0
Hours Worked:76.0
Hours$0.00

=======================
Employee:Joseph Weaver
Position:Ruler of the Known Universe
Pay Rate:301.0
Hours Worked:336.0
Hours$0.00

=======================
Employee:Clone of Joseph Weaver
Position:Personal bodyguard and double
Pay Rate:9.0
Hours Worked:40.0
Hours$0.00

=======================
Employee:Andrew
Position:Teacher
Pay Rate:51.0
Hours Worked:96.0
Hours$0.00

=======================
Employee:Batman
Position:Crime Fighter
Pay Rate:1.0
Hours Worked:168.0
Hours$0.00

i would check to see if netbeans is hiding std out or putting it in some other tab for the "console" or writing to a log file or something. i'm not a fan of i so it can't tell you where to look :)
 
the ant build.xml that netbeans is using isn't doing what you expect when its trying to run the app. Unfortunately i think i remember the build.xml that it generates is unreadable. I would suggest trying to run it from the command line like the previous poster said.

plus eclipse > netbeans :)
 
You have some issues with your equals() method. If you're trying to override Object#equals(), your signature needs to be modified. I am not sure of the specifications of the assignment, but I would suspect the instructor wants you to implement this method rather than the "proprietary" equals method you have added.

Additionally, Strings (and most objects for that matter) should rarely be compared with the == operator.
 
Back
Top