2017-09-17 10 views
0

私はこのクラスから取り組んでいます。私は合計価格から "CA Resident 5%"を割引しようとしていますが、私のコードは個々の価格を個別に割り引いて追加していると思います。私のプログラムのどこでこれが起こっているのか分かりません。Java POSプログラム。割引全額、各価格ではない

私は基本レベルのJavaで2週間目ですので、私はまだ進んでいませんが、私の基本コードが間違っていることを学ぶことはできません。おかげ

import java.util.*; 
 

 
public class Sept13 { 
 

 
    public static void main(String[] args) { 
 

 
/* 
 
========Point of Sale======== 
 
Foods   No Tax 
 
Ciggarettes  25% Tax 
 
Books   No Tax 
 
Computer  10% Tax 
 
CA Resident  5% Discount 
 
Clothes   10 % Tax 
 

 
*/ 
 

 

 

 

 
boolean CAR = false; 
 
double total = 0, price = 0, Ca = .05, Fo, Ci = .25, Bo, Co = .10, Cl = .10; 
 
int ans = 0; 
 

 
Scanner in = new Scanner(System.in); 
 

 
System.out.print("Are you a California Resident? Type 1 if yes type 0 if no "); 
 
\t \t ans = in.nextInt(); 
 
     
 
     if (ans == 1){ 
 
     CAR = true; //Discount for California Resident 
 
     } 
 
      
 
    
 
//Cigarette Tax 
 
System.out.print("Are you buying cigarettes? Type 1 if yes type 0 if no "); 
 
\t \t ans = in.nextInt(); 
 
     
 

 
     
 
     if (ans == 1); 
 
     System.out.print("Enter price of item(s)"); 
 
\t \t price = in.nextDouble(); 
 
      
 
     if (CAR){ 
 
     total += ((price*Ci)+price); 
 
     } 
 
      
 
System.out.print(total); 
 

 

 
//Computer Tax 
 
System.out.print("Are you buying a computer(s)? Type 1 if yes type 0 if no "); 
 
\t \t ans = in.nextInt(); 
 
     
 
     
 
     if (ans == 1); 
 
     System.out.print("Enter price of item(s)"); 
 
\t \t price = in.nextDouble(); 
 
      
 
     if (CAR){ 
 
     total += ((price*Co)+price); 
 
     } 
 
System.out.print(total); 
 

 

 
//Clothes Tax 
 
System.out.print("Are you buying a Clothes? Type 1 if yes type 0 if no "); 
 
\t \t ans = in.nextInt(); 
 
     
 
     
 
     if (ans == 1); 
 
     System.out.print("Enter price of item(s)"); 
 
\t \t price = in.nextDouble(); 
 
      
 
     if (CAR){ 
 
     total += ((price*Cl)+price); 
 
     } 
 
      
 
      
 

 
System.out.print (total-(total*Ca)); 
 

 

 
     
 
    
 

 
    } 
 
}

+1

さて、価格を入力するたびに各商品を個別に割り引いてから合計に加算します。最後に割引を行う場合は、すべての入力が入った後に単一の 'if'文を書いて割引を適用してください。 – alejandrogiron

+0

また、割引を個別に適用するか、最後に1回適用すると同じ結果が出力されることは間違いありません。 – alejandrogiron

答えて

0

はこれを試してみてください、私はこれがあなたの問題の解決策だと思います。

関連する問題