#How to let this program work properly??

2 messages · Page 1 of 1 (latest)

fervent hamlet
#

Invoice.java

public class Invoice {
    private String invNumber;
    private Item [] itemList;
    private int itemCount;
    
    public Invoice(String invNumber, int itemNum) {
        // 1. Set instance variable invNumber
        // 2. Create an array of Item with number of elements specified 
        //    by parameter itemNum
        // 3. Set itemCount to 0, as there is no Item initially.
        ...
    }

    public String getInvNumber() {
        return invNumber;
    }

    public Array getItemList() {
        return itemList;
    }
    
    public int getItemCount() {
        return itemCount;
    }

    public Item getItem(int index) {
        return itemList[index];
    }

    public void addItem(String productCode, double price, int quantity) {
        if (itemCount < itemList.length) {
            // create a new Item; 
            // save item to appropriate element in itemList
            ...
            itemCount++;
        } else {
            System.out.println("Failed to add new item; max already");
        }
    }
}```
#

Item.java

public class Item {
    private String productCode;
    private double price;
    private int quantity;

    public Item(String productCode, double price, int quantity) {
        …
    }

    public double getItemTotal() {
        …
    }

    public String toString() {
        …
    }
}```