payroll program part1

cant get program to print employees name

Page 1 of 1

4 Replies - 10033 Views - Last Post: 22 March 2009 - 09:46 PM Rate Topic: -----

#1 jlewis25  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 62
  • Joined: 22-March 08

payroll program part1

Post icon  Posted 22 March 2009 - 04:53 PM

I have been trying to get this to work I have this much code so far with no errors but I cant seem to figure out how to get it to print out the employee name with the pay here is what the assingment is asking for'

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.

any help would be great thanks







[code]
// Program that show employees weekly pay
import java.util.Scanner; // program uses class Scanner

public class PayrollProgramPart1 {

//main method begins execution of Java application
public static void main(String args[] )
{
// create Scanner to obtain input from command window

Scanner input = new Scanner(System.in );



double number1; // first number to add
double number2; // second number to add
double sum; // sum of number1 and number2

System.out.print("Enter Employee name: ");
input.nextLine();

System.out.print("Enter hourly rate: ");//prompt
number1 = input.nextDouble(); // read first number from user

System.out.print("Enter number of hours worked: "); //prompt
number2 = input.nextDouble(); //read second number form user

sum = number1 * number2; // multiply numbers

System.out.print("Employee name");

System.out.printf("Sum is $%.2f\n",sum ); // display sum


}//end method main
}// end payrollprogrampart1
[\code]

Is This A Good Question/Topic? 0
  • +

Replies To: payroll program part1

#2 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: payroll program part1

Posted 22 March 2009 - 04:56 PM

You need to assign it to a variable.
String name;
System.out.print("Enter Employee name: ");
name = input.nextLine();


Then to print is use a println
System.out.println("Employee name: " + name);


Was This Post Helpful? 0
  • +
  • -

#3 priya_lorha  Icon User is offline

  • D.I.C Head

Reputation: 6
  • View blog
  • Posts: 78
  • Joined: 02-August 08

Re: payroll program part1

Posted 22 March 2009 - 07:55 PM

import java.io.*;
class payrol
{
static void main(String na[])throws IOException{
InputStreamReader read = new InputStreamReader(System.in);	
BufferedReader in = new BufferedReader(read);
System.out.println("Enter the name");
String name=in.readLine();
System.out.println("Enter the rate (per hour)");
double rate=Double.parseDouble(in.readLine());
System.out.println("Enter the no of hours workes");
double work=Double.parseDouble(in.readLine());
double pay=work*rate;
System.out.println("Name:"+name+"\n"+"pay= "+"$"+pay );


}}

This post has been edited by priya_lorha: 22 March 2009 - 07:55 PM

Was This Post Helpful? 0
  • +
  • -

#4 jlewis25  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 62
  • Joined: 22-March 08

Re: payroll program part1

Posted 22 March 2009 - 09:43 PM

View PostFuzzyness, on 22 Mar, 2009 - 03:56 PM, said:

You need to assign it to a variable.
String name;
System.out.print("Enter Employee name: ");
name = input.nextLine();


Then to print is use a println
System.out.println("Employee name: " + name);


thanks for the help I hope someday I can be one of you guys
thanks again Ill be back Im sure
Was This Post Helpful? 0
  • +
  • -

#5 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: payroll program part1

Posted 22 March 2009 - 09:46 PM

Haha, flattered but its basic stuff you will learn andbe like, "Pft, i had a problem with that before?!"
Happy Coding and goodluck with the program :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1