* Inventory Program - Parts 1
*/
package productjava;
/** Inventory Program 1-3
* IT 215
* @author Tammy
* June 21, 2008
*/
public class Product {
// Private variables
private String name;
private int quantity;
private double price;
private int productid = 0;
// Set the default state of the object
public Product() {
this(0, "Unknown",0,0.00);
}
// User can specify name, quantity, and price for items
public Product (int productId, String itemname, int quantityOnHand, double itemprice) {
productid = productId;
setName (itemname);
setQuantityOnHand(quantityOnHand);
setPrice (itemprice);
}
// Change state of object
public void setName(String itemname) {
name = itemname;
}
// Set quantity on hand and default to zero, if negative
public void setQuantityOnHand(int quantityOnHand) {
if (quantityOnHand > 0) {
quantity = quantityOnHand;
}
else {quantity = 0;}
}
// Set product price and default to zero, if negative
public void setPrice (double itemPrice) {
if (itemPrice > 0.00) {
price = itemPrice;
}
else {price = 0.00;}
}
public String getName() {
return name;
}
public int getQuantityOnHand() {
return quantity;
}
public double getPrice() {
return price;
}
// Calculate value of stock on this item
public double getItemValue() {
return (price * (double)quantity);
}
// String that represents product
@Override
public String toString() {
return name + " - " + price;
}
}
Part 2:
* Inventory Program Part 2
*/
package productjava;
/** Inventory Program Part 1-3
* IT 21
* @author Tammy
* June 21, 2008
*/
import java.text.DecimalFormat;
public class Inventory {
// Set up an array of Products to hold 30 items
int inventorySize = 30;
private Product items[] = new Product[inventorySize];
// Set up to format values into currency
DecimalFormat formatter = new DecimalFormat ("$##,###.00");
// Adds a product to first empty slot in array
public void addProduct(Product item) {
for (int i = 0; i < inventorySize; i++) {
if (items[i] == null) {
items[i] = item;
return;
}
}
}
// Add up total value of products
// Add quantity on hand, item by item; and multiply it by its price
// Add the value to a running total variable
public double getTotalInvValue() {
double sumOfInventory = 0.0;
for (Product item : items) {
if (item != null) {
sumOfInventory += item.getItemValue();
}
}
return sumOfInventory;
}
// Prints inventory list including name, quantity, price, and total stock value for each item
public void printInventory() {
System.out.println("Printing items in inventory...\n");
boolean hasItems = false;
for (Product item : items) {
if (item != null) {
hasItems = true;
System.out.println(item.toString() + " Quantity: " + item.getQuantityOnHand() + "Value of Stock: " formatter.format(item.getItemValue()));
}
}
// Print message if no items are found
if (!hasItems) {
System.out.println("Inventory is currently empty.\n");
}
}
}
and Part 3:
/* Inventory Program Part 3
* Inherited class from class Product
* Extra feature of year movie was made
*/
package productjava;
/** Inventory Program Part 1-3
* IT 215
* @author Tammy
* June 21, 2008
*/
public class DVD extends Product {
// Hold year movie was made
private int movieyear;
public DVD(int productId, String itemname, int quantityOnHand, double itemprice, int year) {
super(productId, itemname, quantityOnHand, itemprice);
movieyear = year;
}
public void setYear (int year) {
movieyear = year;
}
public int getYear() {
return movieyear;
}
//Override getItemValue() in Product class; calls base class version and adds a 5% restocking fee
@Override
public double getItemValue() {
return super.getItemValue() * 1.05;
}
public double getRestockingFee () {
return super.getItemValue() * .05;
}
}
This is my error message:
Compiling 3 source files to C:\Documents and Settings\Tammy\MyDocuments\NetBeansProjects\Product.java\build\classes C:\Documents and Settings\Tammy\My Documents\NetBeansProjects\Product.java\src\productjava\Inventory.java:56: ')' expected
System.out.println(item.toString() + " Quantity: " + item.getQuantityOnHand() + "Value of Stock: " formatter.format(item.getItemValue()));
1 error
I see that I am missing a quotation mark somewhere, but I cannot seem to find where??

New Topic/Question
Reply



MultiQuote



|