Hello all!
Brief background - College student. First course in programming. Trying to learn Java. We are using Eclipse for our IDE.
What this program is supposed to do: Have a user calculate a payroll by inputting information through a keyboard.
Name Hours Worked This Week Hourly Pay Rate Paul Dickson 35 18.36 Mary Ann Ginsburg 40 21.40 David Cheong 40 12.00
Problem: When I prompt the user for information it errors on the second block of information. The first set works great. They enter: Paul Dickson [return], 35 [return], and 18.36 [return]. No problems. But for some reason when you try and enter on the next set: Mary Ann Ginsburg it errors.
import java.util.Scanner; public class Payroll { /** * @author * @purpose * @date */ public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); System.out.println("Please enter a name: "); String n1 = keyboard.nextLine(); System.out.println("Now we will calculate weekly earnings for: " + n1); System.out.println("Please enter the amount of hours worked this week: "); int h1 = keyboard.nextInt(); System.out.println("Thank you. Now please enter the current hourly pay rate: "); double pr1 = keyboard.nextDouble(); System.out.println(n1 + " should be making $" + h1 * pr1 + " before deductions."); System.out.println(); System.out.println("Please enter a name: "); String n3 = keyboard.nextLine(); System.out.println("Now we will calculate weekly earnings for: " + n3); System.out.println("Please enter the amount of hours worked this week: "); int h2 = keyboard.nextInt(); System.out.println("Thank you. Now please enter the current hourly pay rate: "); double pr2 = keyboard.nextDouble(); System.out.println(n3 + " should be making $" + h2* pr2 + " before deductions."); } }
I would like to thank anyone in advance for taking the time to look at this and offering help!