954,541 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

A Simple Question

I am a student taking a java class online. its kinda hard because I don't have anyone to talk to directly.

I do not want someone to do this for me i just want a simple yes or no answer.

I have created a program for my second assignment.

The application displays text that requests the user input the name of the employee, the hourly rate, and the number of hours worked for that week. The application then prints out the name of the employee and the weekly pay amount.

my code for this application is as follows :

import java.util.Scanner; // program uses class Scanner

public class PayrollApp
{

// main method begins execution of java application

public static void main(String args[])
{
// create a scanner to obtain input in command window
Scanner input = new Scanner( System.in );

String employeename; // Name of employee
double hourlyrate; // Amount made in one hour
double hoursworked; // Number of hours worked in one week
double weeklypay; // The multiple of hourly rate and hours worked in one week

System.out.println("Enter an employee name:"); //prompt
employeename = input.nextLine();

System.out.println( "Enter Hourly Rate: "); // prompt
hourlyrate = input.nextDouble(); // read hourly rate

System.out.print( "Enter Hours Worked: "); // prompt
hoursworked = input.nextDouble(); // read hours worked

// calculate weekly pay
weeklypay = hourlyrate * hoursworked; // multiply numbers

// display employee name and weekly pay
System.out.printf( "Weekly Pay for %s,is $%.2f\n", employeename, weeklypay);

} // end method main

} // end class

End code:

I am currently using netbeans and the line that says "public class PayrollApp" gives me an error that says i have to define the class PayrollApp in another file.

My question is this. do i need to define it in another file. and if so what do i include?

(i am sorry, being new to this i may not be asking the question correctly)

blanklogo
Newbie Poster
3 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
 

I'm new sorry, i saw the code tags after the first post.

/* This application displays text that requests the user input the name
 *  of the employee, the hourly rate, and the number of hours worked for that week. The
 *  application then prints out the name of the employee and the weekly pay
 *  amount. 
       */


import java.util.Scanner; // program uses class Scanner

public class PayrollApp
{
    
// main method begins execution of java application

    public static void main(String args[])
{
         // create a scanner to obtain input in command window
        Scanner input = new Scanner( System.in );

        String employeename; // Name of employee
        double hourlyrate; // Amount made in one hour
        double hoursworked; // Number of hours worked in one week
        double weeklypay; // The multiple of hourly rate and hours worked in one week

        System.out.println("Enter an employee name:"); //prompt
        employeename = input.nextLine();         
        
        System.out.println( "Enter Hourly Rate: "); // prompt
        hourlyrate = input.nextDouble(); // read hourly rate

        System.out.print( "Enter Hours Worked: "); // prompt
        hoursworked = input.nextDouble(); // read hours worked

        // calculate weekly pay
        weeklypay = hourlyrate * hoursworked; // multiply numbers

        // display employee name and weekly pay
        System.out.printf( "Weekly Pay for %s,is $%.2f\n", employeename, weeklypay);
       
} // end method main

} // end class
blanklogo
Newbie Poster
3 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
 

What is the exact error that you are getting? Do you get it when you try to compile or when you run it?

darkagn
Veteran Poster
1,197 posts since Aug 2007
Reputation Points: 404
Solved Threads: 200
 

I think you need to read all posts not just the last one :)
What is the exact error that you are getting? Do you get it when you try to compile or when you run it?I am currently using netbeans and the line that says "public class PayrollApp" gives me an error that says i have to define the class PayrollApp in another file.

My question is this. do i need to define it in another file. and if so what do i include?

(i am sorry, being new to this i may not be asking the question correctly)
I have no idea why Netbeans do this as your code is fine and will run on any other IDE without problems. You can try and removepublic before class PayrollApp. If this doesn't help, please post exact error which you get from Netbeans

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

Yes. You need another file for it to work. I tried it in Netbeans and I couldn't get the figure out how to add the file so I used another Jgrasp and it automatically added the file and the program was successful. Here's the link to where you can get Jgrasp. http://spider.eng.auburn.edu/user-cgi/grasp/grasp.pl?;dl=download_jgrasp.html

Removing 'public' allows the program to run in Netbeans. I don't quite understand why it doesn't allow you to use it. Oh well.

Mr. Bill Klepto
Newbie Poster
7 posts since Jun 2007
Reputation Points: 10
Solved Threads: 1
 

You just need to save the class in a file called PayrollApp.java. It works just fine. I'm assuming your file name does not match the class name.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

It works pretty fine. I think your source file name is different than the class name i.e., PayrollApp. Rename the source file to PayrollApp.java.

lookof2day
Junior Poster in Training
83 posts since Aug 2007
Reputation Points: 16
Solved Threads: 11
 

yah... for your reference in future, in java you have to give the same name with java extension as the class name (unlike C++)... if you want to run it manually, add JRE in your classpath then simply open a console and compile it using:
c:/>yourAppDir/ javac PayrollApp.java
This will create PayrollApp.class file, run it using:
java PayrollApp
At the beginning using console will help you better understanding the process.

orko
Junior Poster
164 posts since Apr 2006
Reputation Points: 46
Solved Threads: 11
 

Thanks Loads everyone.. i thought i was going insane :-?

yep xfered to a file that is Named Payrollone.java.. for some reason i was trying to do something like modules.
i only have ever encountered psudeocode before so java class is a little rough.

Your all Aces !!!.. thanks.!

blanklogo
Newbie Poster
3 posts since Sep 2007
Reputation Points: 10
Solved Threads: 0
 

needed this info indeedm thanks
_______
my ip
validator

raananschwartz
Newbie Poster
14 posts since Aug 2007
Reputation Points: 10
Solved Threads: 1
 

I am a student taking a java class online. its kinda hard because I don't have anyone to talk to directly.

I do not want someone to do this for me i just want a simple yes or no answer.

I have created a program for my second assignment.

The application displays text that requests the user input the name of the employee, the hourly rate, and the number of hours worked for that week. The application then prints out the name of the employee and the weekly pay amount.

my code for this application is as follows :

import java.util.Scanner; // program uses class Scanner

public class PayrollApp { // main method begins execution of java application

public static void main(String args[]) { // create a scanner to obtain input in command window Scanner input = new Scanner( System.in );

String employeename; // Name of employee double hourlyrate; // Amount made in one hour double hoursworked; // Number of hours worked in one week double weeklypay; // The multiple of hourly rate and hours worked in one week

System.out.println("Enter an employee name:"); //prompt employeename = input.nextLine(); System.out.println( "Enter Hourly Rate: "); // prompt hourlyrate = input.nextDouble(); // read hourly rate

System.out.print( "Enter Hours Worked: "); // prompt hoursworked = input.nextDouble(); // read hours worked

// calculate weekly pay weeklypay = hourlyrate * hoursworked; // multiply numbers

// display employee name and weekly pay System.out.printf( "Weekly Pay for %s,is $%.2f\n", employeename, weeklypay); } // end method main

} // end class

End code:

I am currently using netbeans and the line that says "public class PayrollApp" gives me an error that says i have to define the class PayrollApp in another file.

My question is this. do i need to define it in another file. and if so what do i include?

(i am sorry, being new to this i may not be asking the question correctly)

I wish I could help you, but I am failing my Java class and don't know what to do. Good luck.

amylaney
Newbie Poster
3 posts since Sep 2007
Reputation Points: 10
Solved Threads: 1
 
I wish I could help you, but I am failing my Java class and don't know what to do. Good luck.


awww! tell us more about your situation... if you still try, you ll pass for sure... here we can at least show you some way.

orko
Junior Poster
164 posts since Apr 2006
Reputation Points: 46
Solved Threads: 11
 

It appears that all that you would need is to insert "import java.util.Scanner;" in your first line to use the java tool Scanner.

johnsene
Newbie Poster
1 post since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You