Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Java (https://www.askmehelpdesk.com/forumdisplay.php?f=440)
-   -   How to add a new line for Invoice class from my other class? (https://www.askmehelpdesk.com/showthread.php?t=822386)

  • Mar 3, 2016, 04:52 PM
    Diend
    How to add a new line for Invoice class from my other class?
    Hi I am new to java, I am having trouble adding a new line for my invoice class from my other class. The underline is where the issue is. We are supposed to addLine a method that takes the following four input parameters: items number, item description, item price, and quantity. The method then adds a line to the invoice only if the invoice has less than four lines. If the invoice already has four lines, then this method should print an error message.

    public class Invoice {
    // Instance Variables
    private String customerName;
    private int numItems;
    private InvoiceLine line1;
    private InvoiceLine line2;
    private InvoiceLine line3;
    private InvoiceLine line4;

    // Contructors
    public Invoice(){}

    public Invoice(String customerNam){
    customerName = customerNam;
    }
    //Getters
    public String getCustomerName(){
    return customerName;
    }
    //Setters
    private void setCustomerName(String customerNam){
    customerName = customerNam;
    }
    public void addLine(int itemNum, String Description, double itemPrice, int quantity){
    if (numItems <= 4){
    numItems += line1;
    if (numItems <= 4)
    numItems += line2;
    if (numItems <= 4)
    numItems += line3;
    if (numItems <= 4)
    numItems += line4;
    }
    if (numItems == 4){
    System.out.print("Error");
    }
    }
    public double getInvoiceTotal(){
    numItems *= numItems;
    return numItems;
    }
    public String toString(){
    String invoiceOutput = "";
    invoiceOutput += (customerName + " brought "+ numItems);
    return invoiceOutput;
    }
    }

    My invoiceLine class:

    public class InvoiceLine {
    //Instance Variables
    private Item itemSold;
    private int quantity;
    public double total = 0;

    // Constructors
    public InvoiceLine(){}

    public InvoiceLine(Item itemSold, int quantity){
    this.itemSold = itemSold;
    this.quantity = quantity;
    }

    public InvoiceLine(int itemNum, String itemDescription, double itemPrice, int quantity){
    this.itemSold = new Item(itemNum, itemDescription, itemPrice);
    this.quantity = 0;
    }
    //Getters
    public Item getItemSold(){
    return itemSold;
    }
    public int getQuantity(){
    return quantity;
    }
    //Setters
    private void setItemSold(Item itemSold){
    this.itemSold = itemSold;
    }
    private void setQuantity(int quantity){
    this.quantity = quantity;
    }
    // Methods
    public double getLineTotal(double total){
    total = (quantity * itemSold.getItemPrice());
    return total;
    }
    public String toString(){
    String invoiceLine = "";
    invoiceLine = (itemSold + " brought "+ quantity + ", which the total cost is "+ total);
    return invoiceLine;
    }

    }

  • All times are GMT -7. The time now is 10:03 PM.