| | |
A Simple Question
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved |
•
•
Join Date: Sep 2007
Posts: 3
Reputation:
Solved Threads: 0
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 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)
•
•
Join Date: Sep 2007
Posts: 3
Reputation:
Solved Threads: 0
I'm new sorry, i saw the code tags after the first post.
Java Syntax (Toggle Plain Text)
/* 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
Last edited by blanklogo; Sep 20th, 2007 at 9:29 pm. Reason: formatting
I think you need to read all posts not just the last one 
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 remove public before class PayrollApp. If this doesn't help, please post exact error which you get from Netbeans

•
•
•
•
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)
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
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.
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.
Last edited by Mr. Bill Klepto; Sep 21st, 2007 at 4:14 am. Reason: Read the post above mine after I finished finding Jgrasp for the link.
"I don't like stupidity; I like stupid people"
•
•
Join Date: Apr 2006
Posts: 164
Reputation:
Solved Threads: 10
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.
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.
A Perfect World
![]() |
Similar Threads
- Quick Question: Is J# the same thing as Java? (Java)
- Simple array question (C++)
- This has to be a simple question to answer. (Visual Basic 4 / 5 / 6)
- Ribbon Question (Motherboards, CPUs and RAM)
- Simple question (Windows Servers and IIS)
- Simple Question (Linux Servers and Apache)
- A simple question about CMOS batteries (Motherboards, CPUs and RAM)
- XP Pro (re)activation question (Windows NT / 2000 / XP)
Other Threads in the Java Forum
- Previous Thread: Java WebStart adding unwanted statusbar
- Next Thread: Ifs to for loops
| Thread Tools | Search this Thread |
Tag cloud for Java
@param android animated api appinventor apple applet application arguments array arrays automation binary bluetooth c++ chat chatprogramusingobjects class classes client code codesnippet compare compiler component coordinates database doctype draw eclipse error event exception file fractal freeze game givemetehcodez graphics gui guidancer health helpwithhomework html ide image input int integer j2me java javaprojects jmf jni jpanel jtable julia linux list login loop map method methods mobile netbeans newbie nonstatic number object oracle page plazmic print problem program programming project recursion scanner screen sell server set sharepoint size sms socket sort sourcelabs sql string swing system test testautomation threads time tree windows






