This lab requires you to translate your work in the pseudocode and flowchart from Lab 2.2 and Lab 2.3 to actual code using Python. Read the following program prior to completing the lab.


A retail company must file a monthly sales tax report listing the total sales for the month and the amount of state and county sales tax collected. The state sales tax rate is 4 percent and the county sales tax rate is 2 percent. Write a program that asks the user to enter the total sales for the month. The application should calculate and display the following:

The amount of county sales tax

The amount of state sales tax

The total sales tax (county plus state)

Consider the following functions for your program:

main that calls your other functions

inputData that will ask for the monthly sales

calcCounty that will calculate the county tax

calcState that will calculate the state tax

calcTotal that will calculate the total tax

printData that will display the county tax, the state tax, and the total tax

If your program is correct, sample output might look as follows:

Welcome to the total tax calculator program

Enter the total sales for the month $12567
The county tax is $ 251.34
The state tax is $ 502.68
The total tax is $ 754.02

Respuesta :

Answer:

// Scanner class is imported to allow program receive user input

import java.util.Scanner;

// Solution is defined

public class Solution {

   // main method is defined to begin program execution

   public static void main(String args[]) {

    // A welcome message is displayed to user    

    System.out.println("Welcome to the total tax calculator program");

   

   //  inputData is called and assigned to total_sales

    int total_sales = inputData();

   //  calcCounty is called and assigned to county_tax

    double county_tax = calcCounty(total_sales);

   //  calcState is called and assigned to state_tax

    double state_tax = calcState(total_sales);

   //  calcTotal is called and assigned to total_tax

    double total_tax = calcTotal(state_tax, county_tax);

   //  printData is called

    printData(state_tax, county_tax, total_tax);

   }

   

   // The inputData method receive input from user

   // The method returns the received input

   public static int inputData(){

       // A scan object is defined to received input

       Scanner scan = new Scanner(System.in);

       System.out.print("Enter the total sales for the month $");

       int entered_total = scan.nextInt();

       return entered_total;

   }

   

   // The calcCounty method is defined and it

   // return the county_tax

   public static double calcCounty(double total_sales){

       double county_tax = 0.02 * total_sales;

       return county_tax;

   }

   

   // The calcState method is defined and it

   // return the state_tax

   public static double calcState(double total_sales){

       double state_tax = 0.04 * total_sales;

       return state_tax;

   }

   

   // The calcTotal method is defined and it

   // return the total_tax

   public static double calcTotal(double state_tax, double county_tax){

       double total_tax = state_tax + county_tax;

       return total_tax;

   }

   

   // The printData method print out the data

  // Each data is displayed to 2 decimal place

   public static void printData(double state_tax, double county_tax, double total_tax){

       System.out.println("The county tax is $" + String.format("%.2f", county_tax));

       System.out.println("The state tax is $" + String.format("%.2f", state_tax));

       System.out.println("The total tax is $" + String.format("%.2f", total_tax));

   }

}

Explanation: