Good Evening Everyone,
I am having trouble getting my instance variable named "invoiceNumber" to update as the class variable "numberOfInvoices" is incremented.
Would appreciate any help.
Thank You
Invoice Class File
package javatask1; public class Invoice { private static int numberOfInvoices = 0; //Counts total number of invoices made. private String companyName; private double amountDue; private String chargeDate; private int invoiceNumber; //CONSTRUCTORS public Invoice() { numberOfInvoices++; companyName = ""; amountDue = 0; chargeDate = ""; invoiceNumber = numberOfInvoices; } public Invoice(String coName, double Amount, String dateCharged) { numberOfInvoices++; companyName = coName; amountDue = Amount; chargeDate = dateCharged; invoiceNumber = numberOfInvoices; } //GET METHODS public static int getNumberOfInvoices() { return numberOfInvoices; } public String getCompanyName() { return companyName; } public double getAmountDue() { return amountDue; } public String getChargeDate() { return chargeDate; } public int getInvoiceNumber() { return invoiceNumber; } //SET METHODS public void setCompanyName(String coName) { companyName = coName; } public void setAmountDue(double Amount) { amountDue = Amount; } public void setChargeDate(String dateCharged) { chargeDate = dateCharged; } }
Test Program
package javatask1; public class JavaTask1 { public static void main(String[] args) { // TODO code application logic here Invoice myBill = new Invoice("SeaGraphics", 150, "06152013"); System.out.println(Invoice.getNumberOfInvoices()); System.out.println(myBill.getInvoiceNumber()); Invoice myBill2 = new Invoice("SeaGraphics", 150, "06152013"); System.out.println(Invoice.getNumberOfInvoices()); System.out.println(myBill.getInvoiceNumber()); Invoice myBill3 = new Invoice("SeaGraphics", 150, "06152013"); System.out.println(Invoice.getNumberOfInvoices()); System.out.println(myBill.getInvoiceNumber()); } }
Output
run:
1
1
2
1
3
1
BUILD SUCCESSFUL (total time: 0 seconds)