2011-02-06 30 views
0
C:\Users\gator\Documents\InventoryPart1.java:101: cannot find symbol 
symbol : constructor Television(java.lang.String,java.lang.String,int,double) 
location: class Television 
     Television sony = new Television ("SONY368", "Sony Vega", 2, 899.99); 
         ^

1錯誤 這是錯誤,我得到當我試圖編譯下面我java代碼:我需要知道什麼,以便爲它編寫任何人都可以幫助改變?我不明白錯誤消息中的int。的Java編程庫存

//Author:   Walter Rutherford 
//Date:    Feb. 03/2011 
//Class:   IT/215 week five inventory program 1 

import java.text.NumberFormat; 
import java.util.Locale; 
import java.util.Scanner; 

class Television { 

    private String itemNumber; 
    private String productName; 
    private double units; 
    private double unitPrice; 
    private double unitsTotal; 
    //constructor 
    public Television (String itemNumber, String productName, double units, double unitprice, double unitsTotal) { 
     setItemNumber(itemNumber); 
     setProductName(productName); 
     setUnits(units); 
     setUnitPrice(unitPrice); 
     unitsTotal = units ++; 
    } 

    //accessor methods for class variables 
    public String getItemNumber() { 
     return itemNumber; 
    } 

    public void setItemNumber (String itemNumber) { 
     this.itemNumber = itemNumber; 
    } 

    public String getProductName() { 
     return productName; 
    } 

    public void setProductName (String productName) { 
     this.productName = productName; 
    } 

    public double getUnits() { 
     return units; 
    } 

    public void setUnits (double units) { 
     this.units = units; 
    } 

    public double getUnitPrice() { 
     return unitPrice; 
    } 

    public void setUnitPrice (double unitPrice) { 
     this.unitPrice = units * unitPrice; 
    } 

    public double getUnitsTotal() { 
     return unitsTotal; 
    } 

    public void setUnitsTotal (double unitsTotal) { 
     this.unitsTotal = units ++; 
    } 


} 

public class InventoryPart1 { 

    public static void main (String args[]) { 


     int units; 

     double unitPrice; 

     double unitsTotal; 
     unitsTotal = units ++; 

     double unitsPrice; 
     unitsPrice = units * unitPrice; 

     double unitsTotalPrice; 
     unitsTotalPrice = unitsTotal * unitPrice; 

     double totalInventory; 
     totalInventory = unitsTotal * unitsTotalPrice; 


     NumberFormat nf = NumberFormat. getCurrencyInstance(Locale.US); 

     //create an instance of the Television class 
     Television sony = new Television ("SONY368", "Sony Vega", 2, 899.99); 

     //use the methods from class Television to output the inventory details. 
     System.out.println("Item Number: " + sony.getItemNumber()); 

     System.out.println("Product Name: " + sony.getProductName()); 

     System.out.print("Number of Units: "); 
     System.out.println(nf.format(units)); 

     System.out.print("Unit Price: "); 
     System.out.println(nf.format(unitPrice)); 

     System.out.print("Units Total: "); 
     System.out.println(nf.format(unitsTotal)); 

     System.out.print("Units Total Price: "); 
     System.out.println(nf.format(unitsTotalPrice)); 

     System.out.print("Total Inventory: "); 
     System.out.println(nf.format(totalInventory)); 
    } 

} 
+3

如果這是一項家庭作業,它應該有`家庭作業`標籤,我認爲。 – 2011-02-06 03:22:53

回答

2

你的構造函數有5個參數,並嘗試只用4.如果Java來調用它嘗試發明的一個缺失的值?

0
symbol : constructor Television(java.lang.String,java.lang.String,int,double) 
location: class Television 
     Television sony = new Television ("SONY368", "Sony Vega", 2, 899.99); 
        ^

我不明白錯誤消息的INT。

消息是想告訴你,它不能找到,當你在這裏調用構造函數時提供的參數相匹配的構造函數:

Television sony = new Television ("SONY368", "Sony Vega", 2, 899.99); 

具體而言,根據你如何的說法調用此構造方法,它需要尋找一個構造函數看起來像這樣:

constructor Television(java.lang.String,java.lang.String,int,double) 

注意方法的參數,它說你的電話要求。 Howeve,在你Television類的構造函數是這樣的:

public Television (String ..., String ..., double ..., double ..., double ...) 

我省略掉出來的參數名稱以使其更清晰。看看編譯器說你需要調用構造函數的參數與構造函數真正需要的參數之間的區別?特別要注意的是,你用4個參數調用構造函數,並且你在類中編寫的構造函數有5個參數。

因此,編譯器在類中查找其他具有4個參數的構造函數,這些參數與您提供的參數類型兼容,並且找不到一個參數。因爲它找不到一個,編譯器說:

cannot find symbol 
symbol : constructor Television(java.lang.String,java.lang.String,int,double) 
+0

謝謝你的幫助,我是新來的,這個班真的很難。 – user604937 2011-02-07 06:19:08