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

java invoice exercise

Uploaded by

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

java invoice exercise

Uploaded by

heranialemu69
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

public class Invoice {

private String partNumber;


private String partDescription;
private int quantity;
private double pricePerItem;

public Invoice(String partNumber, String partDescription, int quantity, double


pricePerItem) {
this.partNumber = partNumber;
this.partDescription = partDescription;
this.quantity=quantity;
this.PricePerItem=pricePerItem;
}

public String getPartNumber() {


return partNumber;
}

public void setPartNumber(String partNumber) {


this.partNumber = partNumber;
}

public String getPartDescription() {


return partDescription;
}

public void setPartDescription(String partDescription) {


this.partDescription = partDescription;
}
public void setPricePerItem(double pricePerItem) {
if(pricePerItem > 0){
this.pricePerItem = pricePerItem:
}else{
this.pricePerItem = 0.0;
}
}
public double getPricePerItem() {
return pricePerItem;
}
public void setQuantity(int quantity) {
if(quantity>0){
this.quanity=quantity:
}else{
this.quantity=0:
}
}
public int getQuantity() {
return quantity;
}

public double getInvoiceAmount() {


return quantity * pricePerItem;
}

public static void main(String[] args) {


Invoice invoiceTest = new Invoice("typeA2", "chip", 10, 100);
System.out.println("Item's Part Number: " + InvoiceTest.getPartNumber());
System.out.println("Item's Part Description: " +
InvoiceTest.getPartDescription());
System.out.println("Item's Quantity: " + InvoiceTest.getQuantity());
System.out.println("Price per Item: $" +InvoiceTest.getPricePerItem());
System.out.println("Invoice Amount: $" + InvoiceTest.getInvoiceAmount());
}
}

You might also like