In each of the projects that follow, you should write a program that contains an introductory docstring. This documentation should describe what the program will do (analysis) and how it will do it (design the program in the form of a pseudocode algorithm). Include suitable prompts for all inputs, and label all outputs appropri- ately. After you have coded a program, be sure to test it with a reasonable set of legitimate inputs. 1 The tax calculator program of the case study outputs a floating-point number that might show more than two digits of precision. Use the round function to modify the program to display at most two digits of precision in the output number.
/*Java program that prompts the user to enter sales
amount from the user and then finds the 5% sales tax on sales
amount. Then print the sales and tax amount on sales . Print two
decimal places for tax amount on sales. * */
//TaxCalculator.java
import java.util.Scanner;
public class TaxCalculator
{
public static void main(String[] args)
{
//declare sales as double data
type
double sales;
//set initial sales as 0
sales=0;
//initialize the tax value as
5%
final double TAX=0.05;
//create an instance of Scanner
class
Scanner scanner=new
Scanner(System.in);
//Prompt user to enter sales
amount
System.out.print("Enter sales :$
");
//read sales as string and convert
to double
sales=Double.parseDouble(scanner.nextLine());
//calculate the tax on sales
double taxamount=sales*TAX;
System.out.println("Sales :
$"+sales);
//round the tax amount to 2 decimal
places
System.out.println("Tax amount:
$"+Math.round(taxamount*100)/100.0);
}
}//end of the class
Sample Output:
Enter sales :$ 5869
Sales : $5869.0
Tax amount: $293.45
Note: Program is assumed to write in java
language.
Get Answers For Free
Most questions answered within 1 hours.