Untitled
unknown
java
a year ago
854 B
5
Indexable
import java.util.Scanner;
public class ConvertStringToInteger {
public static void main(String[] args) {
// Declare variables
String stringHours;
int hours;
final double PAY_RATE = 12.25;
// Create a Scanner object for keyboard input
Scanner scanner = new Scanner(System.in);
// Prompt user for hours worked
System.out.print("How many hours did you work this week? ");
stringHours = scanner.nextLine();
// Convert string input to an integer
hours = Integer.parseInt(stringHours);
// Display the total pay based on the hours worked
System.out.println("You worked " + hours + " hours at P" + PAY_RATE + " per hour.");
System.out.println("That's P" + (hours * PAY_RATE));
// Close the scanner
scanner.close();
}
}
Editor is loading...
Leave a Comment