0

私はJavaを初めて使用し、このインベントリプログラムをコンパイルしようとしています。同じエラーメッセージが表示され続け、何が欠けているのかわかりません。エラーは記号が見つからないことであり、10、18、20、21、22、23行目にあり、Inventoryに^記号が付いていることを示しています。私は頭を悩ませたものを同封し、できる限りのことを試みました。これについて助けていただければ幸いです。

//InventoryProgram2.java
//Camera inventory program
import java.util.Arrays; 

public class InventoryProgram2
{
public static void main( String args [])
{
      //instantiate camera object
      Inventory myInventory = new Inventory();


      //displays welcome message
System.out.println( "Camera Invenotry Program");
System.out.println();//skips a line

//create and initialize an array of Cameras
Inventory[] Camera = new Inventory[4];

Camera[0] = new Inventory( 1980, "Cannon Rebel T3", 20, 489.99);
Camera[1] = new Inventory( 2120, "Nikon CoolPix L810", 5, 279.99);
Camera[2] = new Inventory( 1675, "Sony CyberShot HX200V", 12, 479.99);
Camera[3] = new Inventory( 1028, "Fujifilm FinePix S4300", 3, 199.99);

//for each array element, output value

for(int count = 0; count < Camera.length; count++)
{
    Camera[count] = count+1;

    System.out.printf("Product Number: %4.2f\n", Camera[count].getprodNumber() );
    System.out.printf("Product Name: %s\n", Camera[count].getprodName() );
    System.out.printf("Units In Stock: %.2f\n", Camera[count].getunitsTotal() );
    System.out.printf("Unit Price: $%4.2f\n", Camera[count].getunitPrice() );
    System.out.printf("Inventory Value: $%4.2f\n", Camera[0].gettotalInventory() );
    System.out.println();//blank line to seperate products

    }//end for 

}//end main method

}//end public class InventoryProgram2

class Camera
{

private int prodNumber;//product number
private String prodName;//product name
      private int unitsTotal;//total units in stock
      private double unitPrice;//price per unit
private double totalInventory;//amount of total inventory

//initializa four-argument constructor
public Camera ( int number, String name, int total, double price)
      {
     prodNumber = number;
     prodName = name;
     setUnitsTotal (total);//validate and store total of camera
     setUnitPrice (price);//validate and store price per camera

}//end four-argument constructor


public void setProdNumber (int number)
{
          prodNumber = number;
}

      public int getProdNumber()
{
    return prodNumber;
}

public void setProdName (String name)
{
    prodName = name;
}
      public String getProdName()
{
    return prodName;
}

public void setUnitsTotal (int total)
      {
    unitsTotal = total;
}
public int getUnitsTotal()
{
    return unitsTotal;
}  
      public void setUnitPrice (double price)
      {
    unitPrice = price;
}
      public double getUnitPrice()
{
    return unitPrice;
}


// method to set Inventory value
//public void setInventoryValue(double value)

//{
//InventoryValue = value;
//}end method setInventoryValue

//method to get InventoryValue
//public double getInventoryValue()
//{
// return InventoryValue;
//} //end method to getInventoryValue

public double getInventoryValue()
{
    return unitPrice * unitsTotal;
}//end method to getInventoryValue

//method to set TotalInventory
//public void setTotalInventory(double value)

//{
//TotalInventory = total;
//}end method setTotalInventory

//method to get TotalInventory
//public double getTotalInventory()

//{
//return TotalInventory;
//}end method to getTotalInventory

}//end class Camera

私は1つのクラスのカメラを維持する必要があったので、いくつかの調整を行いました。私は次のように7つのエラーにダウンしています:

10行目:エラー:CameraクラスのコンストラクターCameraは、指定されたタイプに適用できません。Camera myCamera = new Camera(); 必須:int、String、int、doubleが見つかりました:引数なし理由:実際の引数リストと仮引数リストの長さが異なります

29行目:エラー:互換性のないタイプInventory [count] = count + 1 ^必須:カメラが見つかりました:int

31、32、33、34、35行目:エラーでシンボルが見つかりませんSystem.out.printf(......)[count] .getprodNumber ^ symbol:メソッドgetprodNumber()場所:クラスCamera

これが私の更新されたコードです:

//Inventory.java

//カメラインベントリプログラムimportjava.util.Arrays;

public class Inventory
{
public static void main( String args [])
      {
      //instantiate camera object
      Camera myCamera = new Camera();


//displays welcome message
System.out.println( "Camera Invenotry Program");
System.out.println();//skips a line

//create and initialize an array of Cameras
Camera[] Inventory = new Camera[4];

Inventory[0] = new Camera( 1980, "Cannon Rebel T3", 20, 489.99);
Inventory[1] = new Camera( 2120, "Nikon CoolPix L810", 5, 279.99);
Inventory[2] = new Camera( 1675, "Sony CyberShot HX200V", 12, 479.99);
Inventory[3] = new Camera( 1028, "Fujifilm FinePix S4300", 3, 199.99);

//for each array element, output value

for(int count = 0; count < Inventory.length; count++)
{
      Inventory[count] = count+1;

      System.out.printf("Product Number: %4.2f\n", Inventory[count] .getprodNumber() );
      System.out.printf("Product Name: %s\n", Inventory[count] .getprodName() );
      System.out.printf("Units In Stock: %.2f\n", Inventory[count] .getunitsTotal() );
      System.out.printf("Unit Price: $%4.2f\n", Inventory[count] .getunitPrice() );
      System.out.printf("Inventory Value: $%4.2f\n", Inventory[0] .gettotalInventory() );
      System.out.println();//blank line to seperate products

    }//end for 

}//end main method

}//end public class Inventory

class Camera
{

private int prodNumber;//product number
private String prodName;//product name
      private int unitsTotal;//total units in stock
      private double unitPrice;//price per unit
private double totalInventory;//amount of total inventory

//initializa four-argument constructor
public Camera ( int number, String name, int total, double price)
      {
     prodNumber = number;
     prodName = name;
     setUnitsTotal (total);//validate and store total of camera
     setUnitPrice (price);//validate and store price per camera

}//end four-argument constructor


public void setProdNumber (int number)
{
    prodNumber = number;
}

      public int getProdNumber()
{
    return prodNumber;
}

public void setProdName (String name)
{
    prodName = name;
}
      public String getProdName()
{
    return prodName;
}

public void setUnitsTotal (int total)
      {
    unitsTotal = total;
}
public int getUnitsTotal()
{
    return unitsTotal;
}  
      public void setUnitPrice (double price)
      {
    unitPrice = price;
}
      public double getUnitPrice()
{
    return unitPrice;
}


// method to set Inventory value
//public void setInventoryValue(double value)

//{
//InventoryValue = value;
//}end method setInventoryValue

//method to get InventoryValue
//public double getInventoryValue()
//{
// return InventoryValue;
//} //end method to getInventoryValue

public double getInventoryValue()
{
    return unitPrice * unitsTotal;
}//end method to getInventoryValue

//method to set TotalInventory
//public void setTotalInventory(double value)

//{
//TotalInventory = total;
//}end method setTotalInventory

//method to get TotalInventory
//public double getTotalInventory()

//{
//return TotalInventory;
//}end method to getTotalInventory

}//end class Camera
4

2 に答える 2

2

Camera クラスは実際には Inventory と呼ぶ必要があるようです。メイン アプリケーション クラスで Camera を型としてではなく変数名として使用しています。

class Cameraに変更class Inventory

public Camera ( int number, String name, int total, double price)

public Inventory ( int number, String name, int total, double price)

そして、そこまでではないにしても、あなたを近づけるはずです.

于 2012-08-08T03:31:41.660 に答える
0

Inventoryクラスがこのクラスと同じパッケージにあるかどうかを確認します。それ以外の場合は、 の場合と同じようにそのクラスをインポートしますArrays

于 2012-08-08T03:28:37.127 に答える