Need help with objects please
I have an array that stores 3 objects in it. The object uses a getInvoiceAmount method in a seperate class to multiply two variables that have been declared in a previous method. Now what I want to do is make a getInvoiceTotal method that gets each objects seperate getInvoiceAmount method total, and adds them together. How would I go about doing this?
Here is my code
publicclass Invoice
{
private String partNumber;
private String partDescription;
privateint quantity;
privatedouble pricePerUnit;
public Invoice()
{
partNumber = ("");
partDescription = ("");
quantity = 0;
pricePerUnit = 0;
}
publicvoid setPartNumber(String strPartNumber)
{
partNumber = strPartNumber;
}
public String getPartNumber()
{
return partNumber;
}
publicvoid setPartDescript(String strPartDesc)
{
partDescription = strPartDesc;
}
public String getPartDescript()
{
return partDescription;
}
publicvoid setQuantity(int num)
{
quantity = num;
}
publicint getQuantity()
{
return quantity;
}
publicvoid setPricePerUnit(double num)
{
pricePerUnit = num;
}
publicdouble getPricePerUnit()
{
return pricePerUnit;
}
publicdouble getInvoiceAmount()
{
return quantity * pricePerUnit;
}
}
Question 2
How would I got about aligning a some text in a system.out print statment, so that it prints out aligned , like you would see in a table?
Cheers
Message was edited by:
Prime08

