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
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());
}
}
Comments
Leave a comment