Knowee
Questions
Features
Study Tools

import java.util.Scanner; public class PayrollCalculator { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.println("====================================="); System.out.println("||Welcome to the Payroll Calculator System! Please select the action you would like to perform!||"); System.out.println("====================================="); System.out.println("A. Calculate Payroll"); System.out.println("B. Display History"); System.out.println("C. Exit"); System.out.print("Enter your choice (A/B/C): "); char choice = scanner.next().charAt(0); switch (choice) { case 'A': case 'a': calculatePayroll(); break; case 'B': case 'b': displayHistory(); break; case 'C': case 'c': exit(); break; // Added break statement to prevent fall-through default: System.out.println("Invalid choice. Please select either A, B, or C."); } } public static void calculatePayroll() { // Your code for calculating payroll goes here System.out.println("Calculating Payroll..."); } public static void displayHistory() { // Your code for displaying history goes here System.out.println("Displaying History..."); } public static void exit() { // Your code for exit goes here System.out.println("Exiting..."); System.exit(0); // Exiting the program } }

Question

import java.util.Scanner;

public class PayrollCalculator { public static void main(String[] args) { Scanner scanner = new Scanner(System.in);

    System.out.println("=====================================");
    System.out.println("||Welcome to the Payroll Calculator System! Please select the action you would like to perform!||");
    System.out.println("=====================================");
    System.out.println("A. Calculate Payroll");
    System.out.println("B. Display History");
    System.out.println("C. Exit");

    System.out.print("Enter your choice (A/B/C): ");
    char choice = scanner.next().charAt(0);

    switch (choice) {
        case 'A':
        case 'a':
            calculatePayroll();
            break;
        case 'B':
        case 'b':
            displayHistory();
            break;
        case 'C':
        case 'c':
            exit();
            break; // Added break statement to prevent fall-through
        default:
            System.out.println("Invalid choice. Please select either A, B, or C.");
    }
}

public static void calculatePayroll() {
    // Your code for calculating payroll goes here
    System.out.println("Calculating Payroll...");
}

public static void displayHistory() {
    // Your code for displaying history goes here
    System.out.println("Displaying History...");
}

public static void exit() {
    // Your code for exit goes here
    System.out.println("Exiting...");
    System.exit(0); // Exiting the program
}

}

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

This is a Java program that acts as a simple payroll calculator. It provides three options to the user: calculate payroll, display history, and exit.

The user's choice is taken as input and based on the choice, the corresponding method is called. If the user enters 'A' or 'a', the calculatePayroll() method is called. If 'B' or 'b' is entered, the displayHistory() method is called. If 'C' or 'c' is entered, the exit() method is called which terminates the program.

If the user enters anything other than 'A', 'B', or 'C' (case insensitive), a default message is printed stating that the choice is invalid.

The calculatePayroll(), displayHistory(), and exit() methods are currently placeholders and you would need to implement the actual functionality.

In the exit() method, System.exit(0) is used to terminate the program. The argument 0 indicates that the program is terminating normally. If any other number is used, it would indicate that the program is terminating due to some error.

This problem has been solved

Similar Questions

import java.util.Scanner;public class SalarioVendedor {    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        System.out.print("Digite o nome do vendedor: ");        String nome = sc.nextLine();        System.out.print("Digite o salário base: ");        double salarioBase = sc.nextDouble();        System.out.print("Digite o total de vendas: ");        double totalVendas = sc.nextDouble();        double comissao = totalVendas * 0.05;        double salarioTotal = salarioBase + comissao;        System.out.println("Salário total: " + salarioTotal);    }}Analisando o código anterior, o que acontece se o valor das vendas inserido for 200.00 e o salário base for 200.00?Questão 3Escolha uma opção:a. O salário total será 210.0b.O salário total será 105.0c.O salário total será 200.5d.O salário total será 0.05

Scanner input = new Scanner("This\nhas 5\n4\nlines\n");System.out.println("%" + input.next() + "%"); System.out.println("%" + input.nextLine() + "%"); System.out.println("%" + input.nextLine() + "%"); System.out.println("%" + input.nextInt() + "%"); System.out.println("%" + input.nextLine() + "%"); System.out.println("%" + input.nextLine() + "%");

Arrange the below code in correct order :import java.util.Scanner;public static void main(String args[]) {Scanner sc=new Scanner(System.in);public class Main{int num1 = sc.nextInt();System.out.println("The value is "+num1);}}

import java.io.*;import java.util.Scanner; // Driver Classclass GFG {      // main function    public static void main(String[] args)    {        // Declare the variables        int num;         // Input the integer        System.out.println("Enter the integer: ");         // Create Scanner object        Scanner s = new Scanner(System.in);         // Read the next integer from the screen        num = s.nextInt();         // Display the integer        System.out.println("Entered integer is: "                           + num);    }}

import java.io.*;import java.util.*;public class Solution { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int Myint = scanner.nextInt(); double d = scanner.nextDouble(); scanner.nextLine(); String mystring = scanner.nextLine(); System.out.println(mystring); System.out.println(d); System.out.println(Myint); /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */ }}

1/3

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.