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
import java.util.Scanner;
public class InvoiceTest
{
public static void main(String[]args)
{
Invoice purchase = new Invoice(" ", " ",0,0.00);
Scanner input = new Scanner(System.in);
String item;
String description;
int quantity;
double price;
System.out.print("Enter Number:");
item = input.nextLine();
Invoice.setPartNumber(item);
System.out.print ("Enter Description of Item:");
description = input.nextLine();
Invoice.setPartDescription(description);
System.out.print("Enter the Qauntity of Item:");
quantity = input.nextInt();
if (quantity > 0)
Invoice.setQauntityofItemPurchased(qauntity);
System.out.print("Enter the Price Per Item:");
price = input.nextDouble();
if (price > 0)
Invoice.setPricePerItem (price);
System.out.printf("The Total Amount for all items purchased = $%.2f\n",
Invoice.getInvoiceAmount());
}
}
Erin S.
Invoice.setPartNumber(item);
^
InvoiceTest.java:22: error: non-static method setPartDescription(String) cannot be referenced from a static context
Invoice.setPartDescription(description);
^
InvoiceTest.java:27: error: cannot find symbol
Invoice.setQauntityofItemPurchased(qauntity);
^
symbol: variable qauntity
location: class InvoiceTest
InvoiceTest.java:32: error: non-static method setPricePerItem(double) cannot be referenced from a static context
Invoice.setPricePerItem (price);
^
InvoiceTest.java:35: error: cannot find symbol
Invoice.getInvoiceAmount());
^
symbol: method getInvoiceAmount()
location: class Invoice
11/28/17