I'm working on a java project, as far as I can tell, I've finished it all, but when i run the program, the first set of coding on the application does what it's supposed to, but the updated amounts give me 0 for the price and the amount. The same thing goes for the coding for the second object, the original invoice information works fine, except for the fact that but for the updated code, it gives me negative values when they're supposed to be zero besides that, it works fine. for the updated invoice amounts, it gives me 0 for the price and final amount. I can't see any errors, it all compiles and runs. Here is the class code.
public class Invoice
{
private String partNumber;
private String partDescription;
private int quantity;
private double price;
public Invoice (String part,String description, int quan, double value)
{
partNumber = part;
partDescription = description;
if(quan > 0);
quantity = quan;
if(price > 0.0);
price = value;
}
public void setpartNumber(String part)
{
partNumber = part;
}
public String getpartNumber()
{
return partNumber;
}
public void setpartDescription(String description)
{
partDescription = description;
}
public String getpartDescription()
{
return partDescription;
}
public void setquantity(int quan)
{
if(quan > 0);
quantity = quan;
if(quan <= 0);
quan = 0;
}
public int getquantity()
{
return quantity;
}
public void setprice(double value)
{
if(value > 0.0);
price = value;
if(value <= 0.0);
price = 0.0;
}
public double getprice()
{
return price;
}
public double getInvoiceAmount()
{
return (getquantity() * getprice());
}
}
And here is the application code.
public class InvoiceTest
{
public static void main (String args[])
{
Invoice invoiceA = new Invoice("1234", "Hammer",2,14.95 );
System.out.println("Original Invoice Information");
System.out.printf("Part Number: %s\n", invoiceA.getpartNumber());
System.out.printf("Description: %s\n",invoiceA.getpartDescription());
System.out.printf("Quantity: %d\n", invoiceA.getquantity());
System.out.printf("Price: %.2f\n", invoiceA.getprice());
System.out.printf("Invoice Amount: %.2f\n",invoiceA.getInvoiceAmount());
invoiceA.setpartNumber("001234");
invoiceA.setpartDescription("Yellow Hammer");
invoiceA.setquantity(3);
invoiceA.setprice(19.49);
System.out.println();
System.out.println("Updated Invoice Information");
System.out.printf("Part Number: %s\n", invoiceA.getpartNumber());
System.out.printf("Description: %s\n",invoiceA.getpartDescription());
System.out.printf("Quantity: %d\n",invoiceA.getquantity());
System.out.printf("Price: %.2f\n",invoiceA.getprice());
System.out.printf("Invoice Amount: %.2f\n",invoiceA.getInvoiceAmount());
Invoice invoiceB = new Invoice("5678","Paint Brush",-5,-9.99);
System.out.println("\nOriginal Invoice Information");
System.out.printf("Part Number: %s\n", invoiceB.getpartNumber());
System.out.printf("Description: %s\n",invoiceB.getpartDescription());
System.out.printf("Quantity: %d\n", invoiceB.getquantity());
System.out.printf("Price: %.2f\n", invoiceB.getprice());
System.out.printf("Invoice Amount: %.2f\n",invoiceB.getInvoiceAmount());
invoiceB.setquantity(3);
invoiceB.setprice(9.49);
System.out.println();
System.out.println("Updated Invoice Information");
System.out.printf("Part Number: %s\n", invoiceB.getpartNumber());
System.out.printf("Description: %s\n",invoiceB.getpartDescription());
System.out.printf("Quantity: %d\n",invoiceB.getquantity());
System.out.printf("Price: %.2f\n",invoiceB.getprice());
System.out.printf("Invoice Amount: %.2f\n",invoiceB.getInvoiceAmount());
}
}