Untitled

 avatar
unknown
plain_text
5 months ago
1.5 kB
3
Indexable
import java.util.Scanner;

public class ConvertStringToInteger {

    public static void main(String[] args) {

        // Create a Scanner object for input
        Scanner scanner = new Scanner(System.in);

        // Declare variables
        String stringHours, stringPayRate, stringTaxRate;
        int hours;
        double payRate, taxRate;

        // Prompt user for hours worked
        System.out.print("How many hours did you work this week? ");
        stringHours = scanner.nextLine();
        hours = Integer.parseInt(stringHours);

        // Prompt user for hourly pay rate
        System.out.print("What is your hourly pay rate? ");
        stringPayRate = scanner.nextLine();
        payRate = Double.parseDouble(stringPayRate);

        // Prompt user for tax rate
        System.out.print("What is your tax rate (in percentage)? ");
        stringTaxRate = scanner.nextLine();
        taxRate = Double.parseDouble(stringTaxRate) / 100; // Convert percentage to decimal

        // Calculate gross pay, tax amount, and net pay
        double grossPay = hours * payRate;
        double taxAmount = grossPay * taxRate;
        double netPay = grossPay - taxAmount;

        // Display the results
        System.out.println("You worked " + hours + " hours at ₱" + payRate + " per hour.");
        System.out.println("Gross Pay: ₱" + grossPay);
        System.out.println("Tax Amount: ₱" + taxAmount);
        System.out.println("Net Pay: ₱" + netPay);

        // Close the scanner
        scanner.close();
    }
}
Editor is loading...
Leave a Comment