File, new project, Java+Java application, Project name just a random name, finish.

Then.. new file, Java+Java class, Class name payroll, finish..

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication5;

/**
 *
 * @author computer

public class Payroll
{
   public static void main(String[] args)
   {
      int hours = 40;
      double grossPay, payRate = 25.0;

      grossPay = hours * payRate;
      System.out.println("Your gross pay is $" + grossPay);
   }
}

Then I build it, then I run it. It does not run. I must have chosen the wrong settings or something. Asks me if I want to run it anyway, which is what I did...

then nothing happens and it just says:

run:
BUILD SUCCESSFUL (total time: 1 second)


What did I do wrong?

Recommended Answers

All 18 Replies

the whole program is commented out...
put */ at the line after the author

I still get the same result, but now it says..

"class Payroll is public, should be declared in a file named Payroll.java
public class Payroll".

But, as you can see here, the file is called payroll.

[IMG]http://img19.imageshack.us/img19/7411/javae.jpg[/IMG]

(zoom in)

Java is case sensitive
so that should be "Public class payroll" not Payroll

either change the file name's first letter to uppercase or the public class name's first letter to lowercase

Alright, I should have noticed that! Thanks.

Shouldn't there be any output? It should display the System.out.println , but it dosen't. I still only get the:

"run:
BUILD SUCCESSFUL (total time: 0 seconds)"

I think your running javaapplication5 class instead of payroll class
...judging from the image

Edit: If your figuring this out...Left click on payroll.java on the Projects tab at the left side of netbeans then click run file
... or simply Shift + F6 :)

[IMG]http://img853.imageshack.us/img853/290/java1.jpg[/IMG]


Everything is closed now. I am running Payroll.java Did not think it was this difficult to get this up and running..

Edit:

Oh, you mean at the bottom in the output window.. "Output - JavaApplication5". No idea why that's there or how I change that.

Try what I suggested a while ago

Left click on payroll.java on the Projects tab at the left side of netbeans then click run file

I didn't notice you added this to your post. Sorry. But I actually just did that myself. Thanks! Shouldn't it work the way I tried it? I don't understand why the F6 runs the other file.

F6 runs your main project
Try using Shift + F6 to run the java file on the current screen

or just right click in it and select 'run as'

Thank you! I have another problem and will just put it in here...

package javaapplication8;




public class RecursiveMultiplier
{
    public static void main(String[] args)
    {
        double num1, num2;    
        
        
        // Get the first number.
        input = JOptionPane.showInputDialog("Enter a number.");
        num1 = Double.parseDouble(input);
        
        // Get the second number.
        input = JOptionPane.showInputDialog("Okay, enter another number.");
        num2 = Double.parseDouble(input);
        
        // Show their product.
        JOptionPane.showMessageDialog(null, num1 + " times " + num2 +
                                      " equals " + multiply(num1, num2));
                                                
        System.exit(0);
    }
    
    

    public static double multiply(double x, double y)
    {
        if (x == 1)
            return y;
        else
            return y + multiply(x - 1, y);
    }
}

[IMG]http://i42.tinypic.com/6htjxs.jpg[/IMG]

The code should be fine. Is it just the way I run it or is the code not ok? It dosen't seem to run the correct file, either... Although I did do it correctly this time.

right click on your source file and click on run file option.

right click on your source file and click on run file option.

brilliant thought. which is why I suggested him to do so several days ago.

@Torf: what exactly do you mean? does it do what you want/expect it to do? if not: what does it do and what do you expect it to do.

The code should be fine.

Those red lines found at the rightmost side of netbeans says otherwise
try to fix those issues before running the right file

PS. next time just attach the image on your post so we can view it at the thumbnail

you don't declare input as a String, there's your first error seems to me.

If you want to use classes like JOptionPane from the javax.swing package then either
1. Use its fully qualified name javax.swing.JOptionPane or
2. import the class (or package) at the beginning of your program so you can use the class name without qualification

If you want to use classes like JOptionPane from the javax.swing package then either
1. Use its fully qualified name javax.swing.JOptionPane or
2. import the class (or package) at the beginning of your program so you can use the class name without qualification

should've seen that one ...

It's called teamwork. :)

ps Torf: While we're at it, if (x == 1) It's always dangerous to rely on an exact equals with a floating-point value. You can never be certain that x isn't 0.99999999999 after a calculation whose exact result should be 1.0. It's particularly dangerous in this case because you are relying on it to terminate a recursive algorithm. Far far safer to code that as if (x <= 1)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.