2017-09-27 40 views
-2
/* 
* 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("///////////////////////////////////////////"); 





    } 

} 
+5

所以你調試到代碼?它的行爲方式與您期望的不同? –

+0

即時通訊初學者,所以我仍然在學習,所以我不知道這是我的代碼或我的百分比編寫方式的問題,因爲我試圖讓百分之百的稅率加倍價格 –

+0

我看到的一件事 - 重新將SalesTaxRate添加到價格*金額;所以稅款只收取一次。 – theGleep

回答

2

這條線是有問題對於初學者:

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

你只是增加稅率上的單個項目,總金額不

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; 
+0

如果您這樣做,您可能需要更改'SalesTaxRate'的名稱。 – EJoshuaS

+0

命名是一個全方位的問題! – notyou