I'm new to java, so please be kind if I'm not making any sense or making a rookie mistake! But I have been working for HOURS trying to figure out where I'm going wrong to no avail. I'm pretty sure I'm just missing something really simple, but hopefully someone here understands & is able to help!
I have 3 classes having to do with an invoice, Invoice, InvoiceItem & ProcessInvoice.
InvoiceItem is basically just a bunch of instance variables & getters & setters.
Invoice holds an array of InvoiceItems and a total for the invoice. It loops through the array and calculates the total, then displays it. It also is to have a set method for the array.
ProcessInvoice holds an object of Invoice. It has a private method that instantiates 3 InvoiceItems into a local array, sets their instance variables, and then sets this local array into the Invoice object via the set method. ProcessInvoice has another method that instantiates the Invoice object, calls the private method, and calls the method for calculating & displaying the total.
And I don't know if that made any sense... ANYWAY, why would you make a set method for an array?
Everything compiles fine, except ProcessInvoice, and I run into the problem when it gets to "invoice.createInvoiceItems();" where I get a "cannot find symbol" error.
public class Invoice{
private InvoiceItem[] invoiceArray;
private double invoiceTotal;
//set invoice items array
public void setInvoiceArray(InvoiceItem itemOne, InvoiceItem itemTwo, InvoiceItem itemThree) {
invoiceArray = new InvoiceItem[3];
invoiceArray[0] = new InvoiceItem();
invoiceArray[1] = new InvoiceItem();
invoiceArray[2] = new InvoiceItem();
invoiceArray[0] = itemOne;
invoiceArray[1] = itemTwo;
invoiceArray[2] = itemThree;
}
// calculate invoice
public void calculateInvoice(){
for(int counter = 0; counter < invoiceArray.length; counter++) {
invoiceTotal = invoiceTotal + invoiceArray[counter].calculateItemTotal();
}
}
// display invoice
public void displayInvoice(){
for(int counter = 0; counter < invoiceArray.length; counter++) {
invoiceArray[counter].display();
System.out.println("Invoice " + counter + " Total: " + getInvoiceTotal());
System.out.println();
}
}
// get invoice total
public double getInvoiceTotal(){
return invoiceTotal;
}
}
public class ProcessInvoice {
private Invoice invoice;
private void createInvoiceItems() {
// instantiate 3 invoiceitems into local array
InvoiceItem[] localArray = new InvoiceItem[3];
localArray[0] = new InvoiceItem();
localArray[1] = new InvoiceItem();
localArray[2] = new InvoiceItem();
// set instance variables
localArray[0].setItemID(9865);
localArray[0].setItemQuantity(3);
localArray[0].setItemPrice(16.99);
localArray[0].setItemDescription("50-pack of blank CD-R discs");
localArray[1].setItemID(8425);
localArray[1].setItemQuantity(6);
localArray[1].setItemPrice(10.99);
localArray[1].setItemDescription("2GB USB 2.0 Flash Drive");
localArray[2].setItemID(3241);
localArray[2].setItemQuantity(2);
localArray[2].setItemPrice(69.99);
localArray[2].setItemDescription("250 GB External 2.0 Portable Hard Drive");
// set array into invoice
invoice.setInvoiceArray(localArray[0], localArray[1], localArray[2]);
}
public void runProcess() {
invoice = new Invoice();
invoice.createInvoiceItems();
invoice.calculateInvoice();
invoice.displayInvoice();
}
}
What causes an error of "cannot find symbol"? And how do I go about fixing it?