A Simple Question

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Thread Solved

Join Date: Sep 2007
Posts: 3
Reputation: blanklogo is an unknown quantity at this point 
Solved Threads: 0
blanklogo blanklogo is offline Offline
Newbie Poster

A Simple Question

 
0
  #1
Sep 20th, 2007
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)
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 3
Reputation: blanklogo is an unknown quantity at this point 
Solved Threads: 0
blanklogo blanklogo is offline Offline
Newbie Poster

Re: A Simple Question

 
0
  #2
Sep 20th, 2007
I'm new sorry, i saw the code tags after the first post.

  1. /* This application displays text that requests the user input the name
  2.  * of the employee, the hourly rate, and the number of hours worked for that week. The
  3.  * application then prints out the name of the employee and the weekly pay
  4.  * amount.
  5.   */
  6.  
  7.  
  8. import java.util.Scanner; // program uses class Scanner
  9.  
  10. public class PayrollApp
  11. {
  12.  
  13. // main method begins execution of java application
  14.  
  15. public static void main(String args[])
  16. {
  17. // create a scanner to obtain input in command window
  18. Scanner input = new Scanner( System.in );
  19.  
  20. String employeename; // Name of employee
  21. double hourlyrate; // Amount made in one hour
  22. double hoursworked; // Number of hours worked in one week
  23. double weeklypay; // The multiple of hourly rate and hours worked in one week
  24.  
  25. System.out.println("Enter an employee name:"); //prompt
  26. employeename = input.nextLine();
  27.  
  28. System.out.println( "Enter Hourly Rate: "); // prompt
  29. hourlyrate = input.nextDouble(); // read hourly rate
  30.  
  31. System.out.print( "Enter Hours Worked: "); // prompt
  32. hoursworked = input.nextDouble(); // read hours worked
  33.  
  34. // calculate weekly pay
  35. weeklypay = hourlyrate * hoursworked; // multiply numbers
  36.  
  37. // display employee name and weekly pay
  38. System.out.printf( "Weekly Pay for %s,is $%.2f\n", employeename, weeklypay);
  39.  
  40. } // end method main
  41.  
  42. } // end class
Last edited by blanklogo; Sep 20th, 2007 at 9:29 pm. Reason: formatting
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 803
Reputation: darkagn has a spectacular aura about darkagn has a spectacular aura about darkagn has a spectacular aura about 
Solved Threads: 110
darkagn's Avatar
darkagn darkagn is offline Offline
Practically a Posting Shark

Re: A Simple Question

 
0
  #3
Sep 21st, 2007
What is the exact error that you are getting? Do you get it when you try to compile or when you run it?
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,253
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 492
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is offline Offline
Code tags enforcer

Re: A Simple Question

 
0
  #4
Sep 21st, 2007
I think you need to read all posts not just the last one
Originally Posted by darkagn View Post
What is the exact error that you are getting? Do you get it when you try to compile or when you run it?
Originally Posted by blanklogo View Post
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 remove public before class PayrollApp. If this doesn't help, please post exact error which you get from Netbeans
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 7
Reputation: Mr. Bill Klepto is an unknown quantity at this point 
Solved Threads: 1
Mr. Bill Klepto's Avatar
Mr. Bill Klepto Mr. Bill Klepto is offline Offline
Newbie Poster

Re: A Simple Question

 
0
  #5
Sep 21st, 2007
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.
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"
Reply With Quote Quick reply to this message  
Join Date: May 2007
Posts: 4,508
Reputation: Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future Ezzaral has a brilliant future 
Solved Threads: 522
Moderator
Featured Poster
Ezzaral's Avatar
Ezzaral Ezzaral is offline Offline
Industrious Poster

Re: A Simple Question

 
0
  #6
Sep 21st, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 81
Reputation: lookof2day is an unknown quantity at this point 
Solved Threads: 10
lookof2day lookof2day is offline Offline
Junior Poster in Training

Re: A Simple Question

 
0
  #7
Sep 21st, 2007
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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2006
Posts: 164
Reputation: orko is an unknown quantity at this point 
Solved Threads: 10
orko orko is offline Offline
Junior Poster

Re: A Simple Question

 
0
  #8
Sep 21st, 2007
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.
A Perfect World
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 3
Reputation: blanklogo is an unknown quantity at this point 
Solved Threads: 0
blanklogo blanklogo is offline Offline
Newbie Poster

Re: A Simple Question

 
0
  #9
Sep 22nd, 2007
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.!
Reply With Quote Quick reply to this message  
Join Date: Aug 2007
Posts: 14
Reputation: raananschwartz is an unknown quantity at this point 
Solved Threads: 1
raananschwartz raananschwartz is offline Offline
Newbie Poster

Re: A Simple Question

 
0
  #10
Sep 22nd, 2007
needed this info indeedm thanks
_______
my ip
validator
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC