2014-05-05 31 views
-5

我寫一個程序基本上詢問用戶是否Java程序 - 加油站泵

  1. 他們是會員(是/否),10%的折扣,如果是
  2. 氣體的精品級(3種價格3年級) 然後返回與小計和稅收+總

這裏的發票是我想出了

我得到了一個錯誤說「無法找到符號」爲我的變量(加侖/ G rade/memberYN)

我該如何解決?

這裏是我的錯誤信息 http://puu.sh/8A60K/f9201eb57e.jpg

import java.util.Scanner; 


public class Kang_Invoice2 { 

    public static void main(String[] args) { 

     Scanner input = new Scanner(System.in); 
     System.out.println("Are you a member?"); 
     memberYN = input.nextLine(); 
     System.out.println("Quality of Gas:"); 
     grade = input.nextInt(); 
     System.out.println("Gallons sold:"); 
     gallon = input.nextDouble(); 

     double subtotal; 
     double countyTaxRate = 0.07; 
     double cityTaxRate = 0.0375; 
     double price87 = 3.87; 
     double price89 = 3.98; 
     double price91 = 4.01; 
     double total = subtotal * 1.1075; 
     double countyTax = subtotal * countyTaxRate; 
     double cityTax = subtotal * cityTaxRate; 
     double gallon; 
     int grade ; 

     if(memberYN.equalsIgnoreCase("yes")) 
     { 
      if (grade == 87) 
      {subtotal = price87 * gallon * 0.9;}; 
      if (grade == 89); 
      {subtotal = price89 * gallon * 0.9;}; 
      if (grade == 91); 
      {subtotal = price91 * gallon * 0.9;}; 
     } 
     elseif(memberYN.equalsIgnoreCase("no")); 
     { 
      if (grade == 87) 
      { 
       subtotal = price87 * gallon; 
      }; 
      if (grade == 89); 
      { 
       subtotal = price89 * gallon ; 
      }; 
      if (grade == 91); 
      { 
       subtotal = price91 * gallon; 
      }; 
     } 

     System.out.println("INVOICE FOR GASOLINE"); 
     System.out.println("Member status" + (memberYN.equalsIgnoreCase("yes") ? "yes" : "no") 
     ); 
     System.out.println("Gasoline Sold/Price:" + gallon + "@"); 
     System.out.println("\n"); 
     System.out.println("Subtotal : $" + subtotal); 
     System.out.println("County Tax : $" + countyTax); 
     System.out.println("City Tax : $" + cityTax); 
     System.out.println("-------------"); 
     System.out.println("Total : $ " + total); 

    } 
} 
截圖
+0

輸入? –

+0

對「無法找到符號」的含義進行搜索會更好。問題的標題與實際的具體問題無關。 –

回答

0

需要變量聲明後才能使用它們,例如

String memberYN = input.nextLine(); 
^ 
1

不能使用局部變量在宣佈之前:

gallon = input.nextDouble(); 
... 
double gallon; 

避免這些問題的最好方法是在首次使用變量時聲明變量:

double gallon = input.nextDouble(); 
0

您需要定義變量。這是通過在您第一次引用它們時指定它們的類型(帶或不帶初始化)完成的。例如,對於gallon

System.out.println("Gallons sold:"); 
Double gallon = input.nextDouble(); 
// ^^^ Notice the type specification 
0

你忘記了聲明變量。

int memberYN,grade;

double gallon; 
0

您需要聲明變量之前你在哪裏定義`memberYN`等,你可以得到他們

public static void main(String[] args) { 

    Scanner input = new Scanner(System.in); 
    double gallon; 
    int grade ; 
    String memberYN; 
    System.out.println("Are you a member?"); 
    memberYN = input.nextLine(); 
    System.out.println("Quality of Gas:"); 
    grade = input.nextInt(); 
    System.out.println("Gallons sold:"); 
    gallon = input.nextDouble(); 
    ........}