belirli bir dizisine nesne ekleme. Ben InvTrans sınıfında özel dizi Invt sınıfında Fatura örnekleri için yapıcı ve Fatura örneklerini kabul edeceğini kabul etmek InvTrans nesne dizisi için Kurucular, (i doğru kelimeleri kullanıyorum düşünüyorum). İkilemim bunu diziye ekleyip eklemediğimi anlamaya çalışıyorum ama dizideki içeriği gösteren zor bir zamanım var.Ben java benim InvTrans dizisi "aleti" bir Fatura nesnesi eklemeye çalışıyorum nesnelerin
public class InvTrans
{
// variable for a counter in InvTrans Obj.
private int InvTransIndex = 0;
private Inv[] transactionArray;
// Constructor for InvTrans array.
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);
order1.display();
}
public void addLine(Inv a) {
transactionArray[InvTransIndex] = a;
InvTransIndex++;
}
// Method to add an inventory object to the array.
public boolean setTransactionLine(Inv i) {
transactionArray[InvTransIndex] = i;
InvTransIndex = InvTransIndex + 1;
return true;
}
}
// Class Inv (Inventory) contains a constructor for a part and a display method.
class Inv {
/*
* Need a constructor which will hold the fields necessary for our Inventory
* Tracker. Need: a) Date - Date transaction occurred. b) Units - Number of
* items added or subtracted from inventory. c) Type - Description of
* transaction. Sale, Receipt, Adjustment. d) Reference Number. e) Cost per
* Unit - price paid for each unit in inventory. Unused sales. f) Price per
* unit - What each unit was sold for. Unused receipts.
*/
String date, type;
int units, referenceNumber;
double costPerUnit, pricePerUnit;
Inv(String d, String t, int u, int r, double c, double p) {
date = d;
type = t;
units = u;
referenceNumber = r;
costPerUnit = c;
pricePerUnit = p;
}
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);
}
}
? Sorunuz nedir? Bir şey çalışmıyor mu? Derleme değil mi? – sisyphus
Ve yukarıdaki kodda neyin beklediğine karşı yanlış olan nedir? – vikingsteve
derler ama ben nesneler dizisine bir şey eklenip eklenmediğini kontrol etmek için fikirlerimi tükettim. –