Invoice Class - Create a class called Invoice that a hardware store might use to represent...

60.1K

Verified Solution

Question

Programming

Invoice Class - Create a class calledInvoice that a hardware store might use to represent aninvoice for an item sold at the store. An Invoice should includefour pieces of information as instance variables—a part number(type String), a part description (type String), a quantity of theitem being purchased (type int) and a price per item (double).

  • Your class should have a constructor that initializes the fourinstance variables. If the quantity passed to the constructor isnot positive, it should be set to 0 by the constructor. If theprice per item passed to the constructor is not positive, it shouldbe set to 0.0 by the constructor.

  • Provide a set and a get method for each instance variable. Ifthe quantity passed to the setQuantity method is notpositive, it should be set to 0 by the method. If the price peritem passed to the setPricePerItem method is not positive,it should be set to 0.0 by the method.

  • Provide a method named getInvoiceAmount thatcalculates the invoice amount (i.e., multiplies thequantity by the price per item), then returns theamount as a double value.

Write a test app named InvoiceTest that demonstratesclass Invoice’s capabilities. Create two Invoice objects, printtheir state, and invoice amounts.

(Java Programming)

Answer & Explanation Solved by verified expert
4.3 Ratings (829 Votes)
JavaProgrampackage invoicedriverclass Invoice Private data members private String partNumber private String partDescription private int quantity private double pricePerItemConstructorpublic InvoiceString partNumber String partDescription intquantity double pricePerItem thispartNumber partNumberthispartDescription    See Answer
Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students