Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I need help completing this problem. I am writing the code in Java and have gott

ID: 3879855 • Letter: I

Question

I need help completing this problem. I am writing the code in Java and have gotten pretty far with help from my textbook but how do I complete the code to answer the question? I am stuck on the InvoiceTest.java part. Thank you.
/* 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 as a double value. If the quantity is 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 app named InvoiceTest that demonstrates class Invoice’s capabilities. */


3.12 Invoice.javea //COP 3330-0R06 Donuay 27th, 2018 3.12 [s points] (Invoice Class) Create a class called Invoice thot a hardware store might use to represent 6 7 an invoice for an item sold at the store. An Invoice should include four pieces of information as 8 instance vartables-o part number (type String) a part description (type String), a quantity of the 9 item being purchased (type int) and a price per item (double). Your class should have a constructor 10 that initializes the four instance variables. Provide a set and a get me thod for each instance variable. 11 In addition, provide a methot named getInvoiceAmount that colculates the invoice amount (.e., multiplies the quantity by tfhe price per item), then returns the amount as a double value. If the 13 quantity is not positive, it should be set to e. I 14 .e. write a test app named InvoiceTest that demonstrates class Invoice's capabilities. 15 16 17 18 f the price per item is not positive, it should be set to public class Main//Public class Invoice begins 19 private String PartNumber;//Instance variable with type string for part numbers 20 private String PartDescription;//Instance variable with type String for part descriptions 21 private int PartQuantity://Instance vartable with type int for part quontities private doubleP 22 23 24 25 able with type double for prices per items 26 public Main (String Parthumber, String PartDescription, int PartQuantity, double PricePerItea )//Constructor receiving four parameters 27 28 this.PartNumber -PartNumber;//PartNumber is asstgned to Num this.PartDescription-PartDescription;//PartDescription is assigned to Des this.PricePeritem-Price;//PricePerItem is assigned to Price if ( Partouantity0 )//If PartQuantity {s not positive 29 31 32 this.PartQuantity -0://set PartQuantity to e

Explanation / Answer

//This.is the class Invoice with some changes: setters have been used within the constructor

public class Invoice {
private String PartNumber;
private String PartDescription;
private int PartQuantity;
private double PricePerItem;

public Invoice(String PartNumber,String PartDescription,int PartQuantity,double PricePerItem) {
  setPartNumber(PartNumber);
  setPartDescription(PartDescription);
  if(PartQuantity<0)
   setPartQuantity(0);
  else
   setPartQuantity(PartQuantity);
  if(PricePerItem<0)
   setPricePerItem(0.0);
  else
   setPricePerItem(PricePerItem);
}
public double getInvoiceAmount() {
  double amount;
  amount = PartQuantity * PricePerItem;
  return amount;
}
public void setPartNumber(String PartNumber) {
  this.PartNumber = PartNumber;
}
public void setPartDescription(String PartDescription) {
  this.PartDescription = PartDescription;
}
public void setPartQuantity(int PartQuantity) {
  this.PartQuantity = PartQuantity;
}
public void setPricePerItem(double PricePerItem) {
  this.PricePerItem = PricePerItem;
}
public String getPartNumber() {
  return this.PartNumber;
}
public String getPartDescription() {
  return this.PartDescription;
}
public int getPartQuantity() {
  return this.PartQuantity;
}
public double getPricePerItem() {
  return this.PricePerItem;
}
}

//This is the InvoiceTest class: it accepts all the inputs from the user and creates an object of the class Invoice. Then it calls the getters of the class Invoice to display all the info

public class InvoiceTest{
public static void main(String[] args) {
  Scanner input = new Scanner(System.in);
  System.out.println("Enter the Part Number: ");
  String PartNumber = input.nextLine();
  System.out.println("Enter the Part Description: ");
  String PartDescription = input.nextLine();
  System.out.println("Enter the Part Quantity: ");
  int PartQuantity = input.nextInt();
  System.out.println("Enter the Price Per Item: ");
  double PricePerItem = input.nextDouble();
  Invoice inv = new Invoice(PartNumber, PartDescription, PartQuantity, PricePerItem);
  System.out.println("Part Number: "+inv.getPartNumber()+" Part Description: "+inv.getPartDescription()+" Part Quantity: "+inv.getPartQuantity()+" Price Per Item:"+inv.getPricePerItem()+" Invoice Amount: "+inv.getInvoiceAmount());
  
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote