Ask Experts Questions for FREE Help !
Ask
    Diend's Avatar
    Diend Posts: 1, Reputation: 1
    New Member
     
    #1

    Mar 3, 2016, 04:52 PM
    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;
    }

    }

Check out some similar questions!

How to invoke the variables from first class and second class to third class in java [ 0 Answers ]

I need to invoke the class1 and class2 variable to class3. class1 and class2 contain only variable , no methods. I am not able execute my program. My code contain some selenium scripts also My code as follows package TestObjects;

Class boundaries,class width,class mid-point [ 0 Answers ]

Find the class width of the following, 3-7 8-10 11-15 16-18 19-25.

Construct a table for class,freq, midpoint,class boundary,relative req,and cumulati [ 1 Answers ]

Construct a table for class,freq, midpoint,class boundary,relative req,and cumulative freg? Number of classes:5 Data set:35,32,51,39,44,41,42,38,37,42,38,39,36,40,39,46,44,37,43,35,40,41,40,39

What level or class felony is poss/w intent to distribute class d [ 3 Answers ]

In criminal law is possession with intent to distribute class d "one gram " a major or minor felony? I have this on my record because in mass there was no limit to be charged this way But now it is a civil offence no longer a crime.now that mass law is changed when it comes to marijauna will my...


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.