I am a javanoob, hence my username. I am currently enrolled in a Java Programming class. We have to create a Java payroll program. I completed part 1 just fine, but I'm having issues with part 2. For part 2, I have to modify my application so that it continues to request user information (this portion works). I also have to make it so that when the user enters "stop" as the employee name, the program ends. Also, if a negative number is entered as hourly pay or hours worked, a prompt comes up asking the user to input a positive number. I am so sorry, but this website is my last hope. Unfortunately, my instructor is not much of a help, he expects me to be an expert after only 2 weeks. Can you guys please take a look at my code and help me out or at least point me in the right direction??? I hope I pasted the code right...thanks!
// Payroll Program Part 2
import java.util.Scanner; // class Scanner
public class PayrollProgramTwo
{
//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);
String cleanInputBuffer; // input
String employeename; // Employee Name
float hourly; // hourly pay rate
float hours; // hours worked this week
float product; // weekly pay amount
boolean end = false; // is the input name stop?
while (end = true) // as long as end is false, proceed
{
hourly = -1; // this way, both are initiated to be -1;
hours = -1;
System.out.print("Enter Name of Employee:");
employeename = input.nextLine();
if(employeename.toLowerCase() == "stop")
end = false;
System.out.print("Enter hourly pay rate:"); // prompt
hourly = input.nextFloat(); // input
while (hours <= 0) // same as hourly while loop
{
System.out.print("Enter number of hours worked this week:"); // prompt
hours = input.nextFloat(); // input
}
product = hourly * hours; // * numbers
System.out.printf("The employee %s was paid $ %.2f this week.\n\n", employeename, product);
cleanInputBuffer = input.nextLine(); //Read a line of text to clean the input buffer
} // end outer while
} // end method main
} // end class PayrollProgramTwo

New Topic/Question
This topic is locked




MultiQuote






|