BEGINNER Java payroll

  • (5 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »

64 Replies - 4375 Views - Last Post: 21 June 2009 - 06:56 PM Rate Topic: -----

#1 inf4mi5  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 14-June 09

BEGINNER Java payroll

Post icon  Posted 14 June 2009 - 01:29 PM

I am just starting Java (I've been using VB for about 3 years) and as I'm sure you all know, the two are MUCH different. To be honest, I have no idea where to begin. I've read a few chapters of Java for Dummies 4th Edition, and I just can't seem so make it click. I am supposed to create a non-GUI based Java application that calculates weekly pay for an employee. The application should display 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 should then print out the name of the employee and the weekly pay amount. In the printout, display the dollar symbol ($) to the left of the weekly pay amount and format the weekly pay amount to display currency.
Then I'm supposed to modify the Payroll Program application so it continues to request employee information until the user enters stop as the employee name. In addition, program the application to check that the hourly rate and number of hours worked are positive numbers. If either the hourly rate or the number of hours worked is not a positive value, the application should prompt the user to enter a positive amount.
The last program is all that really matters. If someone can give me some code to play with and modify, it would be greatly appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: BEGINNER Java payroll

#2 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 561
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: BEGINNER Java payroll

Posted 14 June 2009 - 01:33 PM

Wont happen on this site. No one will just give you the code. You need to make an attempt and who your code, and then someone can advise you. All you need to do is a simple console program. Look into using scanners to get the user input, and chuck it all in a do while loop.
Was This Post Helpful? 0
  • +
  • -

#3 inf4mi5  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 14-June 09

Re: BEGINNER Java payroll

Posted 14 June 2009 - 02:01 PM

This is what I've managed to come up with now, but it keeps giving me an error when I try to compile.

import java.util.Scanner;

public class PayRoll2
{
private static void Quit()

{
System.out.println( "Sign Off" );
System.exit (0);
}

public static void main( String args[] )
{

Scanner input = new Scanner( System.in );


double hourlyRate = 0.0; 
double hoursWorked = 0.0; 
double pay = 0.0;
String name = "";

if (name.setName().equals( "Stop" ))
{
System.outprintln( "Stop is entered" );
Stop = true;

} 
else

System.out.print( "Please Enter Employees Name:" );
name.setName = input.nextLine();
if (name.getName().equals( "Stop"))
{
System.out.println( "Stop is entered" );
Stop = true;

}
else

System.out.print( "Please Enter Total Number of Hours Worked This Week: ");
hoursWorked = input.nextDouble();

if ( hourlyRate < 0.0 );
System.out.println( "Input must be a positive number, reenter hourly rate: ");
System.out.println( "Please Enter Employees Hourly Rate: "); 

pay = hourlyRate * hoursWorked;

System.out.printf( "Employee Name: %s\n",name );

System.out.printf( "Total Pay for the Week: $%.2f\n",pay);
} 

}


Was This Post Helpful? 0
  • +
  • -

#4 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 520
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: BEGINNER Java payroll

Posted 14 June 2009 - 02:10 PM

View Postinf4mi5, on 14 Jun, 2009 - 03:01 PM, said:

This is what I've managed to come up with now, but it keeps giving me an error when I try to compile.


The error is...?

This post has been edited by Locke: 14 June 2009 - 02:15 PM

Was This Post Helpful? 0
  • +
  • -

#5 inf4mi5  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 14-June 09

Re: BEGINNER Java payroll

Posted 14 June 2009 - 02:13 PM

java.lang.NoClassDefFoundError: Payroll
Caused by: java.lang.ClassNotFoundException: Payroll
	at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
	at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: Payroll.  Program will exit.

Was This Post Helpful? 0
  • +
  • -

#6 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 561
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: BEGINNER Java payroll

Posted 14 June 2009 - 02:15 PM

Your first couple of errors is ur using getName and setName when you dont have these methods. All you need to do is
String name = input.nextLine();


Then you can do
if (name.equals( "Stop"))

Was This Post Helpful? 0
  • +
  • -

#7 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 520
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: BEGINNER Java payroll

Posted 14 June 2009 - 02:16 PM

You need to name your file PayRoll2.java. Or else it can't access the program properly.

The compile errors are all fairly straightforward...

And I think you need { } around your else block of code, or I don't think it will run how you want it to.

This post has been edited by Locke: 14 June 2009 - 02:18 PM

Was This Post Helpful? 0
  • +
  • -

#8 inf4mi5  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 14-June 09

Re: BEGINNER Java payroll

Posted 14 June 2009 - 02:17 PM

I put the {} around the else block. Still got the same error. Java is much more difficult than VB6. =(
Was This Post Helpful? 0
  • +
  • -

#9 Locke  Icon User is offline

  • Sarcasm Extraordinaire!
  • member icon

Reputation: 520
  • View blog
  • Posts: 5,596
  • Joined: 20-March 08

Re: BEGINNER Java payroll

Posted 14 June 2009 - 02:19 PM

Is the compiler giving you any errors? I copied the code...and got a handful of errors before I could even run it.
Was This Post Helpful? 0
  • +
  • -

#10 inf4mi5  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 14-June 09

Re: BEGINNER Java payroll

Posted 14 June 2009 - 02:22 PM

javac: file not found: src_payroll.txt (The system cannot find the path specified)



That's the only error I get, but I don't even know why it's looking for that text file.
Was This Post Helpful? 0
  • +
  • -

#11 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 561
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: BEGINNER Java payroll

Posted 14 June 2009 - 02:28 PM

You compiling from the command line?
Was This Post Helpful? 0
  • +
  • -

#12 inf4mi5  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 14-June 09

Re: BEGINNER Java payroll

Posted 14 June 2009 - 02:29 PM

I click "Build" ->"Compile Project" in JCreator.
Is that the problem?
Was This Post Helpful? 0
  • +
  • -

#13 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 561
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: BEGINNER Java payroll

Posted 14 June 2009 - 02:36 PM

compile project in JCreator? JCreator is better for creating single java files, not projects. go to file, new file. Work on a single java file. Compile it. You might get the same error. If so, you havnt set up your jdk properly
Was This Post Helpful? 0
  • +
  • -

#14 inf4mi5  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 14-June 09

Re: BEGINNER Java payroll

Posted 14 June 2009 - 02:43 PM

how much different is making a single file as compared to a project? I've never tried making a single file before. Are there any restrictions that I would have to change code for?
Was This Post Helpful? 0
  • +
  • -

#15 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 561
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Re: BEGINNER Java payroll

Posted 14 June 2009 - 02:46 PM

No difference in the actual code. The only difference is you dont need to import your package. For beginners, i think its a lot easier starting on single files, which is why JCreator is good. When you compile it, go to build - compile file
Was This Post Helpful? 0
  • +
  • -

  • (5 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »