Week 6 Java Project LineItem.java
/**
*
* @author AMARE
*/
public class LineItem
{
private String itemName; //Holds item name.
private int quantity; //Holds quantity of the item.
private double price; // Holds price of the item.
/**
* The parameterized constructor accepts arguments
* @param itemName
* @param quantity
* @param price
*/
public LineItem(String itemName, int quantity, double price)
{
this.itemName = itemName;
this.setQuantity(quantity);
this.setPrice(price);
}
/**
* The no arguments constructors method returns item name
* @return
*/
public String getName()
{
return this.itemName;
}
/**
* The no argument constructors method returns item quantity
* @return
*/
public int getQuantity()
{
return quantity;
}
/**
* The parameterized arguments set quantity
* @param quantity
*/
public void setQuantity(int quantity)
{
this.quantity = quantity;
}
/**
* The no arguments constructor returns price of the item
* @return
*/
public double getPrice()
{
return price;
}
/**
* The parameterized argument sets price
* @param price
*/
public void setPrice(double price)
{
this.price = price;
}
/**
* The no arguments constructor returns total price
* @return
*/
public double getTotalPrice()
{
return price * quantity;
}
/**
* The no arguments constructor returns the strings
* @return
*/
public String toString()
{
return itemName + "\tqty " + quantity + "\t@ $" + price + "\t$"
+ getTotalPrice();
}
}
Comments
Post a Comment