Answer to Question #275174 in Java | JSP | JSF for joy

Question #275174

Consider the association relationship between the class Customer in question 2 above and a class Invoice where the Customer class is a member of the Invoice class. Write the codes for the Invoice class and a test driver to test all the public methods

1
Expert's answer
2021-12-03T12:31:58-0500
public class Invoice {
    private Customer customer;
    private double total;

    public Invoice(Customer customer, double total) {
        this.customer = customer;
        this.total = total;
    }

    public Customer getCustomer() {
        return customer;
    }

    public double getTotal() {
        return total;
    }
}


public class Customer {
    private String name;

    public Customer(String name) {
        this.name = name;
    }

    @Override
    public String toString() {
        return name;
    }
}


public class Main {
    public static void main(String[] args) {
        Customer customer = new Customer("Tom Orange");
        Invoice invoice = new Invoice(customer,10);
        System.out.println(invoice.getCustomer()+" "+invoice.getTotal());
    }
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS