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]
payroll program part1cant get program to print employees name
Page 1 of 1
4 Replies - 4573 Views - Last Post: 22 March 2009 - 09:46 PM
Replies To: payroll program part1
#2
Re: payroll program part1
Posted 22 March 2009 - 04:56 PM
You need to assign it to a variable.
Then to print is use a println
String name;
System.out.print("Enter Employee name: ");
name = input.nextLine();
Then to print is use a println
System.out.println("Employee name: " + name);
#3
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
#4
Re: payroll program part1
Posted 22 March 2009 - 09:43 PM
Fuzzyness, on 22 Mar, 2009 - 03:56 PM, said:
You need to assign it to a variable.
Then to print is use a println
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
#5
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
Happy Coding and goodluck with the program
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote



|