残念ですが、これは簡単な解決かもしれませんが、別のクラスコンストラクタの引数からパラメータを使用するオブジェクトを作成する際に、 Javaで。基本的には、特定のパラメータを持つこのInvオブジェクトがあり、Invオブジェクトの特定のパラメータのみを使用してWarehouseオブジェクトを作成しようとしています。このオブジェクトは、Warehouse Transactionクラスで使用されます。 Invオブジェクトコンストラクタ内でif文を実行できますか?誰でも後でこのオブジェクトをスタックにプッシュしますが、その2番目のオブジェクトを作成するロジックを開発することはできませんでした。助けてください、私はこれに新しいスーパーです。別のクラスコンストラクタのパラメータの一部を使用するために1つのクラスコンストラクタを試してください
public class InvTrans
{
private int InvTransIndex = 0;
private Inv[] transactionArray;
public InvTrans()
{
this.transactionArray = new Inv[100];
}
public static void main(String args[])
{
InvTrans widget = new InvTrans();
Inv order1 = new Inv("March 5th, 2016", "Received", 20, 0001, 2.10, 2.20);
Inv order2 = new Inv("March 6th, 2016", "Received", 100, 0002, 2.10, 2.50);
Inv order3 = new Inv("March 7th, 2016", "Received", 100, 0003, 2.10, 2.50);
Inv order4 = new Inv("March 12th, 2016", "Sold", 140, 0004, 2.40, 2.60);
widget.addLine(order1);
widget.addLine(order2);
widget.addLine(order3);
widget.addLine(order4);
for (int counter = 0; counter < widget.transactionArray.length; counter++)
{
widget.transactionArray[counter].display();
}
}
public void addLine(Inv a)
{
transactionArray[InvTransIndex] = a;
InvTransIndex = InvTransIndex + 1;
}
}
class Inv
{
String date, type;
int units, referenceNumber;
double costPerUnit, pricePerUnit;
Inv(String d, String t, int u, int r, double c, double p) {
this.date = d;
this.type = t;
this.units = u;
this.referenceNumber = r;
this.costPerUnit = c;
this.pricePerUnit = p;
Warehouse warehouseTransaction = new Warehouse(this.date, this.type, this.units, this.costPerUnit);
}
public void display()
{
System.out.println(this.date + "\t" + this.type + "\t" + this.units + "\t\t\t\t\t" + this.referenceNumber + "\t\t\t\t\t" + this.costPerUnit + "\t\t\t" + this.pricePerUnit);
}
}
public class Warehouse
{
String date, type = "";
int units = 0;
double costPerUnit = 0;
Warehouse(String d, String t, int u, double c)
{
date = d;
type = t;
units = u;
costPerUnit = c;
}
}
に役立ちます願っています。通常、倉庫と、倉庫に保管されている品目があります。 –
Invを作成するたびにWarehouseオブジェクトを作成する場合は、現在の実装で何が問題になりますか?私は倉庫をクラス変数にして後でアクセスできるようにします –
@ Toaster私は、Invオブジェクトが作成されるたびにウェアハウスオブジェクトを作成する方法を理解しようとしていました。私はそれについてどうやって行くのか分からない。 –