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?

Edited 4 Years Ago by Torf: n/a

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

Edited 4 Years Ago by zeroliken: n/a

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

Edited 4 Years Ago by zeroliken: n/a

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 :)

Edited 4 Years Ago by zeroliken: n/a

[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.

Edited 4 Years Ago by Torf: n/a

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.

Edited 4 Years Ago by Torf: n/a

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.

Edited 4 Years Ago by Torf: n/a

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

Edited 4 Years Ago by zeroliken: n/a

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)

This question has already been answered. Start a new discussion instead.