I have the first file for invoice no problem, I am unsure how to write TestInvoice
Invoice
import java.util.Scanner;
public class Invoice
{
private String partNumber;
private String partDescription;
private int quantity;
private double pricePerItem;
// four-argument constructor
public Invoice( String part, String description, int count,
double price )
{
partNumber = part;
partDescription = description;
setQuantity( count ); // validate and store quantity
setPricePerItem( price ); // validate and store price per item
} // end four-argument Invoice constructor
// set part number
public void setPartNumber( String part )
{
partNumber = part;
} // end method setPartNumber
// get part number
public String getPartNumber()
{
return partNumber;
} // end method getPartNumber
// set description
public void setPartDescription( String description )
{
partDescription = description;
} // end method setPartDescription
// get description
public String getPartDescription()
{
return partDescription;
} // end method getPartDescription
// set quantity
public void setQuantity( int count )
{
quantity = ( count < 0 ) ? 0 : count; // quantity cannot be negative
} // end method setQuantity
// get quantity
public int getQuantity()
{
return quantity;
} // end method getQuantity
// set price per item
public void setPricePerItem( double price )
{
pricePerItem = ( price < 0.0 ) ? 0.0 : price; // validate price
} // end method setPricePerItem
// get price per item
public double getPricePerItem()
{
return pricePerItem;
} // end method getPricePerItem
// return String representation of Invoice object
public String toString()
{
return String.format( "%s: \n%s: %s (%s) \n%s: %d \n%s: $%,.2f",
"invoice", "part number", getPartNumber(), getPartDescription(),
"quantity", getQuantity(), "price per item", getPricePerItem() );
} // end method toString
// method required to carry out contract with interface Payable
public double getPaymentAmount()
{
return getQuantity() * getPricePerItem(); // calculate total cost
} // end method getPaymentAmount
} // end class Invoice
TestInvoice
public class TestInvoice
{
public static void main(String[]args)
{
Invoice aToy = new Invoice("part number is 21945", "part is black with white dots" ,
}
}
Abubakar Q.
You will have to add multiple test cases for each method within your class file. The above is a good starting point.07/14/25