我制定了一个计算销售税的计划,当我输入1.0时,它的税率不会加倍?

时间:2017-09-27 15:57:35

标签: java

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication19;

import java.util.Scanner;

/**
 *
 * @author joshu
 */
public class JavaApplication19 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // also please don't block me this is my second time using this site

    System.out.println("// SALES_TAX////////////////////////////////////");
    Scanner input = new Scanner(System.in); 
    String emailAddress;
    double itemPrice, itemAmount, SALES_TAX;

    System.out.println("How many item will you like to buy?");
    itemAmount = input.nextDouble();

    System.out.println("What is the price of the item?");
    itemPrice = input.nextDouble();

    System.out.println("Enter sales tax rate: ");
    SALES_TAX = input.nextDouble();

    final Double SalesTaxRate = SALES_TAX * itemPrice;
    double totalprice = SalesTaxRate + (itemPrice * itemAmount);

    emailAddress = input.nextLine();
    System.out.println("Please enter emailAddress");
    emailAddress = input.nextLine();

    System.out.printf("Your total price is: $ %1.2f" + " a copy of this invoice"
    + " will be emailed to: %s\n",
    totalprice,emailAddress.toUpperCase());

    System.out.println("///////////////////////////////////////////");   





    }

}

2 个答案:

答案 0 :(得分:2)

此行对于初学者来说是个问题:

final Double SalesTaxRate = SALES_TAX * itemPrice;
double totalprice = SalesTaxRate + (itemPrice * itemAmount);

您只需在单个项目上添加税率,总额。

答案 1 :(得分:0)

我会像这样更改总计算的逻辑:

//gets the percentage of the item, and then adds the item price
    final Double SalesTaxRate = itemPrice + (itemPrice * (SALES_TAX / 100));

//simply multiply the new price by the amount required
        double totalprice = SalesTaxRate * itemAmount;