[SOLVED] Expected errors, I can't see what's wrong.
Code:
public String toString()
{
return String.format("%s: %s\n %s: %.2f\n %s: %.2f\n %s: %.2f"
"Item name",getItemName(),
"Item Number",getItemNumber(),
"Stock",getInvStock(),
"Item Price",getItemPrice(),
"Total Inventory Value",getCalculateInventoryValue());
}
I keep getting errors that tell me ")" is expected and ';' is expected but I am not sure where they are supposed to go. This looks right to me (and the text book) so I am not too sure where I went wrong. The whole program is posted below. There are other issues I have to deal with too but getting this right is my first step I think. :confused:
Code:
public class Inventory
{
private String itemName; // variable that stores the cartridge name
private int itemNumber; // variable that stores the item number
private int invStock; // variable that stores the quantity in stock
private double itemPrice; // variable that stores the cartridge price
public double getValue;
public String calculateInventoryValue;
public Inventory(String name, int number, int stock, double price)
{
itemName = name;
itemNumber = number;
invStock = stock;
itemPrice = price;
}
public void setItemName(String name) // Method to set the item name
{
this.itemName = name;
}
public String getItemName() // Method to get the item name
{
return itemName;
}
public void setItemNumber(int number) // Method to set the item number
{
this.itemNumber = number;
}
public int getItemNumber() // Method to get the item number
{
return itemNumber;
}
public void setinvStock(int stock) // Method to set the stock in stock
{
invStock = stock;
}
public int getInvStock() // Method to get the stock in stock
{
return invStock;
}
public void setItemPrice(double price) // Method to set the item price
{
this.itemPrice = price;
}
public double getItemPrice() // Method to get the item price
{
return itemPrice;
}
public double getCalculateInventoryValue() // Method to calculate the value of the inventory
{
return (double) itemPrice * invStock;
}
public double getValue()
{
}
public int compareTo(Object o)
{
Inventory p = null;
try
{
p = (Inventory) o;
}
catch (ClassCastException cE)
{
cE.printStackTrace();
}
return itemName.compareTo(p.getItemName());
}
public String toString()
{
return String.format("%s: %s\n %s: %.2f\n %s: %.2f\n %s: %.2f"
"Item name",getItemName(),
"Item Number",getItemNumber(),
"Stock",getInvStock(),
"Item Price",getItemPrice(),
"Total Inventory Value",getCalculateInventoryValue());
}
private void calculateInventoryValue() {
throw new UnsupportedOperationException("Not yet implemented");
}
} //end class Product
class DVD extends Inventory
{
private double reStockingFee;
public DVD(String itemName, int itemNumber, int invStock, double itemPrice, double reStockingFee)
{
super(itemName, itemNumber, invStock, itemPrice);
this.reStockingFee = reStockingFee;
}
public double getItemPrice() //returns the value of the inventory, plus the restocking fee
{
return super.getItemPrice() + reStockingFee;
}
public String toString()
{
return new StringBuffer().append("Price: " + super.getItemPrice()).append(" With RestockingFee: " + getItemPrice()).toString();
}
} // end class Product
-------
import java.util.Scanner;
import java.util.Arrays;
public class Inventory3
{
public static void main(String args[] )
{
double restockFee = 0.05;
//Declare and initialize the inventory array
Inventory[] inventory = new Inventory[5]; //Array variables
inventory[0] = new Inventory("Robin Hood", 1001, 3, 10.95);
inventory[1] = new Inventory("NCIS Season 4", 1002, 2, 44.00);
inventory[2] = new Inventory("The Departed", 1003, 4, 22.45);
inventory[3] = new Inventory("A Man Apart", 1004, 16, 18.99);
inventory[4] = new Inventory("Gone with the Wind", 1005, 14, 13.50);
Inventory temp[] = new Inventory[1];
System.out.println("Inventory Program for DVD's"); //display header
System.out.println(); // blank line
System.out.println(); // blank line
for(int i = 0; i < inventory.length; i++)
{
System.out.println("Item Number: " + inventory[i].getItemNumber());
System.out.println("Item Name: " + inventory[i].getItemName());
System.out.println("Inventory On Hand: " + inventory[i].getInvStock());
System.out.printf("Item Price: $%,.2f\n " + inventory[i].getItemPrice());
System.out.printf("Value of Inventory: $%,.2f\n " + inventory[i].getValue());
System.out.println("Restock Fee: " + (inventory[i].getInvStock() * inventory[i].getItemPrice()) * 0.05);
System.out.println();
}
}
} //End class Inventory3