I also need the UML class diagram for invoice class, thanks. (Invoice Class) Cre
ID: 3623527 • Letter: I
Question
I also need the UML class diagram for invoice class, thanks.
(Invoice Class) Create a class called Invoice that a hardware store might use to represent an invoice for an item sold at the store. An Invoice should include four pieces of information as instance variables-a part number (type String), a part description (type String), a quantity of the item being purchased (type int) and a price per item (double). Your class should have a constructor that initializes the four instance variables. Provide a set and a get method for each instance variable. In addition, provide a method named getInvoiceAmount that calculates the invoice amount (i.e., multiplies the quantity by the price per item), then returns the amount at a double value. If the quantity it not positive, it should be set to 0. If the price per item is not positive, it should be set to 0.0. Write a test application named InvoiceTest that demonstrates class Invoice't capabilities.Explanation / Answer
import java.util.Scanner; class Invoice{ String partNumber; String partDescription; int itemPurchased; double pricePerItem; Invoice() partNumber = ""; partDescription = ""; itemPurchased = 0; pricePerItem = 0.0; } String getPartNumber(){ return partNumber; } String getPartDescription(){ return partDescription; } int getItemPurchased(){ return itemPurchased; } double getPricePerItem(){ return pricePerItem; } double getInvoiceAmount(){ return (itemPurchased * pricePerItem); } void setPartNumber(String pn){ partNumber = pn; } void setPartDescription(String pd){ partDescription = pd; } void setItemPurchased(int ip){ itemPurchased = ip; } void setPricePerItem(double ppi){ pricePerItem = ppi; } } class InvoiceDemo { public static void main(String args[]) { Scanner sc = new Scanner(System.in); Invoice invoice = new Invoice(); System.out.print(" Enter part number :"); invoice.setPartNumber(sc.nextLine()); System.out.print("Enter part description :"); invoice.setPartDescription(sc.nextLine()); System.out.print("Enter item purchased :"); invoice.setItemPurchased(sc.nextInt()); System.out.print("Enter price per item :"); invoice.setPricePerItem(sc.nextDouble()); System.out.print(" Detail of items purchasing-->"); System.out.print(" Part number :" + invoice.getPartNumber()); System.out.print(" Part description :" + invoice.getPartDescription()); System.out.print(" Total Billing Amount :" + invoice.getInvoiceAmount()); } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.