I wrote a bit of code at school using a copy of Net Beans that they have installed on the computers in the lab at my school. I saved my file to my thumb drive as Lab2.Java.

When I got home I opened my copy of Net Beans 7.0.1 and then opened my saved file on my thimb drive (Lab2.Java). Only to find that once the file is opened in Net Beans it will not RUN.

It is a simple bit of code. Can someone please give me there input as to why I can't get this to RUN.

The CODE is below. Thanks all.

import java.text.*;
import javax.swing.JOptionPane;

public class Lab2 {

    public static void main(String[] args) {

        System.out.println("Welcome to the Payroll System!");

        String strName = JOptionPane.showInputDialog("Please Enter your Name");
        Double hrsWork = Double.parseDouble(JOptionPane.showInputDialog("Please Enter Hours Worked"));
        Double hrRate = Double.parseDouble(JOptionPane.showInputDialog("Please Enter your Hourly Rate"));
        Double fedTax = Double.parseDouble(JOptionPane.showInputDialog("Please Enter Federal Tax Withholding"));
        Double staTax = Double.parseDouble(JOptionPane.showInputDialog("Please Enter State Tax Rate"));
        Double grossPay = hrsWork * hrRate;
        Double fedWith = grossPay * fedTax;
        Double stateWith = grossPay * staTax;
        Double totalDeduction = fedWith + stateWith;
        Double netPay = grossPay - totalDeduction;
        DecimalFormat df = new DecimalFormat("#.##");

        String Capture = "Employee Name: " + strName + "\n \n \r"
                + "Hours Worked" + df.format(hrsWork) + "\n \r"
                + "Pay Rate" + df.format(hrRate) + "\n \r"
                + "Gross Pay" + df.format(grossPay) + "\n \r"
                + "Deductions" + "\n \r"
                + "\t" + "Fedral Withholding: " + (fedTax * 100) + ": " + df.format(fedWith) + "\n \r"
                + "\t" + "State Withholding: " + (staTax * 100) + ": " + df.format(stateWith) + "\n \r"
                + "\t" + "Total Deductions: " + df.format(totalDeduction) + "\n \r"
                + "Net Pay" + df.format(netPay) + "\n \r";

        JOptionPane.showMessageDialog(null, Capture);

It was a copy and paste error. Thank you. Sorry I do in fact have my closing brackets in place like so:

JOptionPane.showMessageDialog(null, Capture);
    }
}

but it still errors when I run it. I am not too familiar with NetBeans but it is the best program I have for writting Java code in.

I have Visual Studio 2010 Profesional but need to download the required files for correctly setting up my enviorment for Java.

Thank you for the quick reply.

Edited 5 Years Ago by 918_Nix: n/a

Ok, I open my Java file with Net Beans. I go to run the file the option is just not there. I'm starting to think that there is not a problem with my code but with how I am trying to use Net Beans.

I wrote this code on a diffrent computer and it ran fine it's just when I saved it to my flash and attempted to re-open it on my personel laptop it will not.

I'm used to frustrating in this line of work I have just been banging my head on the wall trying to figure this out.

Can you maybe recommend some good literature on Net Beans or maybe on another program that you can recommend for me to use.

I know that I am not a seasoned developer so I really appreciate you taking the time to read my post and reply.

Edited 5 Years Ago by 918_Nix: n/a

Hmmm, seems that NetBeans did change lately and one cannot run single file as it has been in the past.
Ok, do following

  • Create new project - Lab2
  • Create new package - lab2 - inside this project
  • Create new class -Lab2.java - inside above package
  • Press "Run" button (big green triangle on top menu bar), it will tell you it hasn't got set main class set for project, so if just confirm default of "lab2.Lab2" if you followed above instructions

Next time you will need to copy whole project structure and open project instead of single file.

Comments
Spot On!
This question has already been answered. Start a new discussion instead.