paano pag enter ng code lalabas na agad name at yung salary rate?
Attachments
-
You do not have permission to view the full content of this post. Log in or register now.
PSSST !
the second variation is where i am having trouble i need to incorperate a overtime calculation into it which i was able to do but now it is not calculating any taxes being with held... the code is as follows....
[code] import java.util.Scanner; // import delcaration for program to use class Scanner
import java.text.NumberFormat;
import java.text.DecimalFormat;
import java.util.Scanner;
public class payrollattempt
{
// main method begins execution of Java application
public static void main( String args[] )
{
Scanner input = new Scanner( System.in ); // create Scanner to obtain input from the command window
boolean stop = false;
String cleanInputBuffer; // input
String getName;
double hoursWorked; // variable for the employee's hours worked
double hourlyRate; // variable for the employee's hourly rate
double grossPay; // Calculated weekly pay before taxes
double taxDeduction; // gross pay * 14%
double netPay; // Calculated weekly pay after taxes
double overTime;
while(stop== false)
{
System.out.print("Enter employees Name or 'quit' to exit: "); // prompt
getName = input.nextLine(); // read employee's name
if(getName.equalsIgnoreCase ( "quit" ) ) // condition statement to request data until stop is entered
{
System.out.print("Exiting Payroll Program. "); // prompt
stop = true;
}
else
{
System.out.print("Enter Hourly Rate: ");
hourlyRate = input.nextDouble(); // read hourly rate
while ( hourlyRate < 0 ) // condition statement to check for negative number
{
System.out.print("Enter the hourly rate of pay for the employee: "); // prompt
hourlyRate = input.nextDouble(); // read hourly rate
} // end while
System.out.print("Enter the hours worked by employee this week: "); // prompt
hoursWorked = input.nextDouble(); // read hours worked
while ( hoursWorked < 0 ) // condition statement to check for negative number
{
System.out.println("Error: You have entered a negative number!"); // error message
System.out.print("Enter the hours worked by employee this week: "); // prompt
hoursWorked = input.nextDouble(); // read hours worked
} // end while
if (hoursWorked > 40)// Overtime
{
grossPay = hoursWorked * hourlyRate;//multiplication
overTime = (hoursWorked-40) * (hourlyRate*1.5);
taxDeduction = grossPay * .14;
System.out.printf("federal taxes: $%.2f\n", taxDeduction);
System.out.println();
netPay = grossPay - taxDeduction;
System.out.printf("net pay: $%.2f\n", netPay);
System.out.println();
System.out.println("Employee:" + getName);
System.out.printf("Hourly Rate: $%.2f\n", hourlyRate);
System.out.println("Regular Hours worked:" + "40");
System.out.println("Overtime Hours worked:" + (hoursWorked-40));
System.out.printf("Total Pay: $%.2f\n", netPay);
System.out.printf("Overtime Pay: $%.2f\n", overTime);
System.out.printf("Gross Pay: $%.2f\n", netPay+overTime);
}
else // Under 40 Hours
{
netPay = hoursWorked * hourlyRate;
System.out.println("Employee:" + getName);
System.out.printf("Hourly Rate: $%.2f\n", hourlyRate);
System.out.println("Regular Hours worked:" + hoursWorked);
System.out.printf("Gross Pay: $%.2f\n", netPay);
}
System.out.printf( "Enter employee name or 'quit' to exit:");
getName = input.next();
cleanInputBuffer = input.nextLine();
}
}
} // end method main
} // end class Part2
alam niyo po ba yan post ko?yes ??
TANGNA MOimport java.util.Scanner;
public class Payroll {
public static void main(String[] args) {
Scanner input = new Scanner ( System.in );
double hourlyRate;
double hoursWorked;
double grossPay; // Calculated weekly pay before taxes
double taxDeduction; // gross pay * 14%
double netPay; // Calculated weekly pay after taxes
System.out.print("Employee name: ");
String employeeName = input.nextLine();
System.out.printf("Enter hourly rate for %s: $", employeeName);
hourlyRate = input.nextDouble();
while(hourlyRate < 0.00){
System.out.print("Please enter only a positive number: $");
hourlyRate = input.nextDouble();
}
System.out.printf("total hours worked: ");
hoursWorked = input.nextDouble();
while (hoursWorked < 0.00){
System.out.print("Please enter only a positive number: ");
hoursWorked = input.nextDouble();
}
grossPay = hourlyRate * hoursWorked;
System.out.printf("gross pay: $%.2f\n", grossPay);
System.out.println();
taxDeduction = grossPay * .14;
System.out.printf("federal taxes: $%.2f\n", taxDeduction);
System.out.println();
netPay = grossPay - taxDeduction;
System.out.printf("net pay: $%.2f\n", netPay);
System.out.println();
input.nextLine();
System.out.print("Employee name:"); // Loops back to start
employeeName = input.nextLine();
}
}Code:the second variation is where i am having trouble i need to incorperate a overtime calculation into it which i was able to do but now it is not calculating any taxes being with held... the code is as follows.... [code] import java.util.Scanner; // import delcaration for program to use class Scanner import java.text.NumberFormat; import java.text.DecimalFormat; import java.util.Scanner; public class payrollattempt { // main method begins execution of Java application public static void main( String args[] ) { Scanner input = new Scanner( System.in ); // create Scanner to obtain input from the command window boolean stop = false; String cleanInputBuffer; // input String getName; double hoursWorked; // variable for the employee's hours worked double hourlyRate; // variable for the employee's hourly rate double grossPay; // Calculated weekly pay before taxes double taxDeduction; // gross pay * 14% double netPay; // Calculated weekly pay after taxes double overTime; while(stop== false) { System.out.print("Enter employees Name or 'quit' to exit: "); // prompt getName = input.nextLine(); // read employee's name if(getName.equalsIgnoreCase ( "quit" ) ) // condition statement to request data until stop is entered { System.out.print("Exiting Payroll Program. "); // prompt stop = true; } else { System.out.print("Enter Hourly Rate: "); hourlyRate = input.nextDouble(); // read hourly rate while ( hourlyRate < 0 ) // condition statement to check for negative number { System.out.print("Enter the hourly rate of pay for the employee: "); // prompt hourlyRate = input.nextDouble(); // read hourly rate } // end while System.out.print("Enter the hours worked by employee this week: "); // prompt hoursWorked = input.nextDouble(); // read hours worked while ( hoursWorked < 0 ) // condition statement to check for negative number { System.out.println("Error: You have entered a negative number!"); // error message System.out.print("Enter the hours worked by employee this week: "); // prompt hoursWorked = input.nextDouble(); // read hours worked } // end while if (hoursWorked > 40)// Overtime { grossPay = hoursWorked * hourlyRate;//multiplication overTime = (hoursWorked-40) * (hourlyRate*1.5); taxDeduction = grossPay * .14; System.out.printf("federal taxes: $%.2f\n", taxDeduction); System.out.println(); netPay = grossPay - taxDeduction; System.out.printf("net pay: $%.2f\n", netPay); System.out.println(); System.out.println("Employee:" + getName); System.out.printf("Hourly Rate: $%.2f\n", hourlyRate); System.out.println("Regular Hours worked:" + "40"); System.out.println("Overtime Hours worked:" + (hoursWorked-40)); System.out.printf("Total Pay: $%.2f\n", netPay); System.out.printf("Overtime Pay: $%.2f\n", overTime); System.out.printf("Gross Pay: $%.2f\n", netPay+overTime); } else // Under 40 Hours { netPay = hoursWorked * hourlyRate; System.out.println("Employee:" + getName); System.out.printf("Hourly Rate: $%.2f\n", hourlyRate); System.out.println("Regular Hours worked:" + hoursWorked); System.out.printf("Gross Pay: $%.2f\n", netPay); } System.out.printf( "Enter employee name or 'quit' to exit:"); getName = input.next(); cleanInputBuffer = input.nextLine(); } } } // end method main } // end class Part2