0% found this document useful (0 votes)
10 views

Invoice Class

Uploaded by

tourism app
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views

Invoice Class

Uploaded by

tourism app
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

(Invoice Class):

Part1:
public class Invoice {
private String partNumber = "0";
private String partDescription = "0";
private int quantity = 0;
private double price = 0;
public Invoice(String pNum, String pDesc, int qty, double
prc) {
partNumber = pNum;
partDescription = pDesc;
quantity = qty;
price = prc;
}
public String getPartNum() {
return partNumber;
}
public String getPartDesc() {
return partDescription;
}
public int getQuantity() {
return quantity;
}
public double getPrice() {
return price;
}
public void setPrice(double prc) {
if (prc > 0.0) {
price = prc;
} else {
price = 0.0;
}
}
public double getInvoiceAmount() {
return (double) quantity * price;
}
}
Part2:
public class InvoiceTest {

public static void main(String args[]) {


Invoice invoice1 = new Invoice("A5544", "Big Black Book", 500, 250.00);

System.out.printf("Invoice 1: %s\\t%s\\t%d\\t$%.2f\\n", invoice1.getPartNum(),


invoice1.getPartDesc(), invoice1.getQuantity(), invoice1.getPrice());

System.out.printf("invoice amount is:", invoice1.getInvoiceAmount());

}
}

You might also like