By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,855 Members | 1,970 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,855 IT Pros & Developers. It's quick & easy.

Inventory Program - Won't complie

P: 9
I am having trouble figuring out my code and was hoping someone could point me in the right direction. Below is my code what I need to due is create a method to add and display the value of the entire inventory. I have what I think is the correct code but it's not working. Help is greatly appreciated

Expand|Select|Wrap|Line Numbers
  1. class Inventory3
  2. {
  3.     public static final int MAXIMUM_ITEMS = 4;
  4.     private static Product product[] = new Product[MAXIMUM_ITEMS];
  5.  
  6.         public static void main(String args[]) 
  7.             {
  8.                 buildInventory();
  9.                 getInventory();        
  10.             }
  11.  
  12.         // Build the inventory, storing 10 different products.
  13.         public static void buildInventory() 
  14.             {
  15.                 product[0] = new Product(1001, "Megaforce", 10, 18.95);
  16.                 product[1] = new Product(502, "Abyss", 25, 12.95);
  17.                 product[2] = new Product(1003, "Deep Impact", 65, 21.95);
  18.                 product[3] = new Product(750, "Forest Gump", 28, 7.95);
  19.                 Arrays.sort(product);               
  20.             }
  21.  
  22.     public static void getInventory() 
  23.         {
  24.             System.out.println(); // blank line
  25.             System.out.println("Welcome to DVD Inventory 1.0"); //display header
  26.             System.out.println();
  27.             for(int i = 0; i < product.length; i++) 
  28.                 {
  29.                     System.out.println("Item Number: " + product[i].getItemNumber());
  30.                     System.out.println("Item Name: " + product[i].getItemName());
  31.                     //System.out.println("Director: " + product[i].getDirector());
  32.                     System.out.println("Inventory On Hand: " + product[i].getInvQuantity());
  33.                     System.out.println("Item Price: $" + product[i].getItemPrice());
  34.                     System.out.println("Value of Inventory: $" + product[i].getValue());
  35.                     System.out.println("Restock Fee: $" + (product[i].getValue()) * 0.05);
  36.                     System.out.println();
  37.  
  38.                 }
  39.         }
  40.  
  41.     public double entireValue() 
  42.         {
  43.             double value = 0;
  44.                 for (int i = 0; i < Product; i++) 
  45.                 {
  46.                 value = value + product[i].getValue();
  47.                 }
  48.             return value;
  49.         }
  50.  
  51.     public void display() 
  52.         {
  53.         System.out.printf("Total Value is: $%.2f\n\n", entireValue());
  54.         }
  55.  
  56.  
  57. } //end Class Inventory3
  58.  
Below is the error I get when I try to complie this into my code
Inventory3.java:104: cannot find symbol
symbol : variable Product
location: class Inventory3
for (int i = 0; i < Product; i++)
^
1 error

here is my complete working code so far
Expand|Select|Wrap|Line Numbers
  1. import java.util.Arrays;
  2.  
  3. class Product implements Comparable
  4. {
  5.         private long itemNumber;    // class variable that stores the item number
  6.         private String itemName;    // class variable that stores the item name
  7.         private long invQuantity;   // class variable that stores the quantity in stock
  8.         private double itemPrice;   // class variable that stores the item price
  9.  
  10.             public Product(long number, String name, long quantity, double price) // Constructor for the Supplies class
  11.                 {
  12.                     itemNumber = number;
  13.                     itemName = name;
  14.                     invQuantity = quantity;
  15.                     itemPrice = price;
  16.                 }
  17.  
  18.             public long getItemNumber() { return itemNumber; } // Method to set item number
  19.             public String getItemName() { return itemName;} // Method to set the item name
  20.             public long getInvQuantity() { return invQuantity;} // Method to set the quantity in stock
  21.             public double getItemPrice() { return itemPrice;} // Method to get the item Price
  22.  
  23.             public double getValue() { return (double) invQuantity * itemPrice; } // Method to calculate the valure of the inventory
  24.  
  25.     public int compareTo(Object o)
  26.         {
  27.             Product p = null;
  28.                 try
  29.                     {
  30.                         p = (Product) o;
  31.                     }
  32.  
  33.                 catch (ClassCastException cE)
  34.                     {
  35.                         cE.printStackTrace();
  36.                     }
  37.                 return itemName.compareTo(p.getItemName());
  38.         }
  39. }  //end class Product
  40.  
  41. class DVD extends Product 
  42.     {
  43.         public DVD(int itemNumber, String itemName, long invQuantity, double itemPrice) 
  44.         {
  45.             super(itemNumber, itemName, invQuantity, itemPrice);
  46.         }
  47.  
  48.        public double getValue() 
  49.        {
  50.         double inventoryValue = super.getValue();
  51.         return (inventoryValue * 1.05);
  52.         }    
  53. }
  54.  
  55. class Inventory3
  56. {
  57.     public static final int MAXIMUM_ITEMS = 4;
  58.     private static Product product[] = new Product[MAXIMUM_ITEMS];
  59.  
  60.         public static void main(String args[]) 
  61.             {
  62.                 buildInventory();
  63.                 getInventory();        
  64.             }
  65.  
  66.         // Build the inventory, storing 10 different products.
  67.         public static void buildInventory() 
  68.             {
  69.                 product[0] = new Product(1001, "Megaforce", 10, 18.95);
  70.                 product[1] = new Product(502, "Abyss", 25, 12.95);
  71.                 product[2] = new Product(1003, "Deep Impact", 65, 21.95);
  72.                 product[3] = new Product(750, "Forest Gump", 28, 7.95);
  73.                 Arrays.sort(product);               
  74.             }
  75.  
  76.     public static void getInventory() 
  77.         {
  78.             System.out.println(); // blank line
  79.             System.out.println("Welcome to DVD Inventory 1.0"); //display header
  80.             System.out.println();
  81.             for(int i = 0; i < product.length; i++) 
  82.                 {
  83.                     System.out.println("Item Number: " + product[i].getItemNumber());
  84.                     System.out.println("Item Name: " + product[i].getItemName());
  85.                     System.out.println("Inventory On Hand: " + product[i].getInvQuantity());
  86.                     System.out.println("Item Price: $" + product[i].getItemPrice());
  87.                     System.out.println("Value of Inventory: $" + product[i].getValue());
  88.                     System.out.println("Restock Fee: $" + (product[i].getValue()) * 0.05);
  89.                     System.out.println();
  90.  
  91.                 }
  92.         }
  93.  
  94. } //end Class Inventory3
  95.  
Mar 23 '08 #1
Share this Question
Share on Google+
13 Replies


100+
P: 539
I am having trouble figuring out my code and was hoping someone could point me in the right direction. Below is my code what I need to due is create a method to add and display the value of the entire inventory. I have what I think is the correct code but it's not working. Help is greatly appreciated

Expand|Select|Wrap|Line Numbers
  1. class Inventory3
  2. {
  3.     public static final int MAXIMUM_ITEMS = 4;
  4.     private static Product product[] = new Product[MAXIMUM_ITEMS];
  5.  
  6.         public static void main(String args[]) 
  7.             {
  8.                 buildInventory();
  9.                 getInventory();        
  10.             }
  11.  
  12.         // Build the inventory, storing 10 different products.
  13.         public static void buildInventory() 
  14.             {
  15.                 product[0] = new Product(1001, "Megaforce", 10, 18.95);
  16.                 product[1] = new Product(502, "Abyss", 25, 12.95);
  17.                 product[2] = new Product(1003, "Deep Impact", 65, 21.95);
  18.                 product[3] = new Product(750, "Forest Gump", 28, 7.95);
  19.                 Arrays.sort(product);               
  20.             }
  21.  
  22.     public static void getInventory() 
  23.         {
  24.             System.out.println(); // blank line
  25.             System.out.println("Welcome to DVD Inventory 1.0"); //display header
  26.             System.out.println();
  27.             for(int i = 0; i < product.length; i++) 
  28.                 {
  29.                     System.out.println("Item Number: " + product[i].getItemNumber());
  30.                     System.out.println("Item Name: " + product[i].getItemName());
  31.                     //System.out.println("Director: " + product[i].getDirector());
  32.                     System.out.println("Inventory On Hand: " + product[i].getInvQuantity());
  33.                     System.out.println("Item Price: $" + product[i].getItemPrice());
  34.                     System.out.println("Value of Inventory: $" + product[i].getValue());
  35.                     System.out.println("Restock Fee: $" + (product[i].getValue()) * 0.05);
  36.                     System.out.println();
  37.  
  38.                 }
  39.         }
  40.  
  41.     public double entireValue() 
  42.         {
  43.             double value = 0;
  44.                 for (int i = 0; i < Product; i++) 
  45.                 {
  46.                 value = value + product[i].getValue();
  47.                 }
  48.             return value;
  49.         }
  50.  
  51.     public void display() 
  52.         {
  53.         System.out.printf("Total Value is: $%.2f\n\n", entireValue());
  54.         }
  55.  
  56.  
  57. } //end Class Inventory3
  58.  
Below is the error I get when I try to complie this into my code
Inventory3.java:104: cannot find symbol
symbol : variable Product
location: class Inventory3
for (int i = 0; i < Product; i++)
^
You are comparing a variable with a Product class... Am i right? correct me if im wrong.

Can you show us the code of Product?

Maybe you can't compare them... Maybe the product's length that you have initialized will do...

Update us.
Mar 23 '08 #2

P: 9
So here is my complete updated code that i've been working on for several hours. I'm able to complie it now but it does not display "Total Value is " $"

Total value should be the inventoryValue of each dvd added up to create an entireValue. I have the code but i'm told I'm missing my call to display it. Everything I've tried doesn't work. any suggestions?

Expand|Select|Wrap|Line Numbers
  1. import java.util.Arrays;
  2.  
  3. class Product implements Comparable
  4. {
  5.         private long itemNumber;    // class variable that stores the item number
  6.         private String itemName;    // class variable that stores the item name
  7.         private long invQuantity;   // class variable that stores the quantity in stock
  8.         private double itemPrice;   // class variable that stores the item price
  9.  
  10.             public Product(long number, String name, long quantity, double price) // Constructor for the Supplies class
  11.                 {
  12.                     itemNumber = number;
  13.                     itemName = name;
  14.                     invQuantity = quantity;
  15.                     itemPrice = price;
  16.                 }
  17.  
  18.             public long getItemNumber() { return itemNumber; } // Method to set item number
  19.             public String getItemName() { return itemName;} // Method to set the item name
  20.             public long getInvQuantity() { return invQuantity;} // Method to set the quantity in stock
  21.             public double getItemPrice() { return itemPrice;} // Method to get the item Price
  22.  
  23.             public double getValue() { return (double) invQuantity * itemPrice; } // Method to calculate the valure of the inventory
  24.  
  25.     public int compareTo(Object o)
  26.         {
  27.             Product p = null;
  28.                 try
  29.                     {
  30.                         p = (Product) o;
  31.                     }
  32.  
  33.                 catch (ClassCastException cE)
  34.                     {
  35.                         cE.printStackTrace();
  36.                     }
  37.                 return itemName.compareTo(p.getItemName());
  38.         }
  39. }  //end class Product
  40.  
  41. class DVD extends Product 
  42.     {
  43.         public DVD(int itemNumber, String itemName, long invQuantity, double itemPrice) 
  44.         {
  45.             super(itemNumber, itemName, invQuantity, itemPrice);
  46.         }
  47.  
  48.        public double getValue() 
  49.        {
  50.         double inventoryValue = super.getValue();
  51.         return (inventoryValue * 1.05);
  52.         }    
  53. }
  54.  
  55. class Inventory3
  56. {
  57.     public static final int MAXIMUM_ITEMS = 4;
  58.     private static Product product[] = new Product[MAXIMUM_ITEMS];
  59.     public static int sizeOfArray;
  60.  
  61.         public static void main(String args[]) 
  62.             {
  63.                 buildInventory();
  64.                 getInventory();        
  65.             }
  66.  
  67.         // Build the inventory, storing 10 different products.
  68.     public static void buildInventory() 
  69.         {
  70.             product[0] = new Product(1001, "Megaforce", 10, 18.95);
  71.             product[1] = new Product(502, "Abyss", 25, 12.95);
  72.             product[2] = new Product(1003, "Deep Impact", 65, 21.95);
  73.             product[3] = new Product(750, "Forest Gump", 28, 7.95);
  74.             sizeOfArray = 4;
  75.             Arrays.sort(product);               
  76.         }
  77.  
  78.     public static void getInventory() 
  79.         {
  80.             System.out.println(); // blank line
  81.             System.out.println("Welcome to DVD Inventory 1.0"); //display header
  82.             System.out.println();
  83.             for(int i = 0; i < product.length; i++) 
  84.                 {
  85.                     System.out.println("Item Number: " + product[i].getItemNumber());
  86.                     System.out.println("Item Name: " + product[i].getItemName());
  87.                     System.out.println("Inventory On Hand: " + product[i].getInvQuantity());
  88.                     System.out.println("Item Price: $" + product[i].getItemPrice());
  89.                     System.out.println("Value of Inventory: $" + product[i].getValue());
  90.                     System.out.println("Restock Fee: $" + (product[i].getValue()) * 0.05);
  91.                     System.out.println();
  92.  
  93.                 }
  94.         }
  95.  
  96.     double entireValue() 
  97.         {
  98.             double value = 0;
  99.                 for (int i = 0; i < sizeOfArray; i++) 
  100.                 { value = value + product[i].getValue(); }
  101.             return value;
  102.         }
  103.  
  104.     public void display() 
  105.         {
  106.             System.out.printf("Total Value is: $%.2f", + entireValue());
  107.         }
  108.  
  109. } //end Class Inventory3
  110.  
Mar 23 '08 #3

100+
P: 539
You forgot to call display() after showing the elements...
Since display() and entireValue() cannot be reference from a static context, make it a static method....

Hope it helps,
sukatoa
Mar 23 '08 #4

P: 9
You forgot to call display() after showing the elements...
Since display() and entireValue() cannot be reference from a static context, make it a static method....

Hope it helps,
sukatoa
how? I'm confused at this point and am trying to understand it.
Mar 23 '08 #5

100+
P: 539
how? I'm confused at this point and am trying to understand it.
After you print all necessary informations, then, that is the time you call that display method... It depends on your implementation... Would you like to display it before/after printing the said info by calling it in method main? or in getInventory() method? Depends upon you...

Just like i wrote, your display() and intireValue() were not static methods... And you have tried to print those info in the method main that was a static context, by calling getInventory() that was also a static method. you should also make both of them static. ( display and intireValue methods )...

You may read this if you have time...

sukatoa
Mar 23 '08 #6

P: 9
Let me ask you this I'm working on two different programs. below is code from my second program and I am trying to get the director to show. I have the code in correctly and it's appended the string but it's not pulling itemDirector and displaying it. Is my problem similar to my other one?

Expand|Select|Wrap|Line Numbers
  1. class Product implements Comparable
  2. {
  3.     private long itemNumber;    // class variable that stores the item number
  4.     private String itemName;    // class variable that stores the item name
  5.     private long invQuantity;   // class variable that stores the quantity in stock
  6.     private double itemPrice;   // class variable that stores the item price
  7.  
  8.         public Product(long number, String name, long quantity, double price) // Constructor for the Supplies class
  9.             {
  10.                 itemNumber = number;
  11.                 itemName = name;
  12.                 invQuantity = quantity;
  13.                 itemPrice = price;
  14.             }
  15.  
  16.         public long getItemNumber() { return itemNumber; } // Method to set item number
  17.         public String getItemName() { return itemName;} // Method to set the item name
  18.         public long getInvQuantity() { return invQuantity;} // Method to set the quantity in stock
  19.         public double getItemPrice() { return itemPrice;} // Method to get the item Price
  20.  
  21.         public double calculateInventoryValue() { return itemPrice * invQuantity;}
  22.  
  23.         public int compareTo(Object o)
  24.             {
  25.                 Product p = null;
  26.                     try
  27.                         {
  28.                             p = (Product) o;
  29.                         }
  30.  
  31.                     catch (ClassCastException cE)
  32.                         {
  33.                             cE.printStackTrace();
  34.                         }
  35.  
  36.                     return itemName.compareTo(p.getItemName());
  37.             }
  38.  
  39.         public String toString()
  40.             {
  41.                 return "Item #: " + itemNumber + "\nName: " + itemName + "\nQuantity: " + invQuantity + "\nPrice: $" + itemPrice + "\nValue: $" + calculateInventoryValue();
  42.             }
  43. }  //end class Product
  44.  
  45. class DVD extends Product
  46. {
  47.     private String itemDirector;
  48.  
  49.     public DVD(String itemDirector,int itemNumber, String itemName, long invQuantity, double itemPrice) 
  50.         {
  51.             super(itemNumber, itemName, invQuantity, itemPrice);
  52.             //itemDirector = director;
  53.         }
  54.  
  55.     public String toString() 
  56.         {
  57.             String s = String.format("Director: \n", itemDirector);
  58.             s = s + super.toString();
  59.             return s;
  60.         }
  61.  
  62. }
  63.  
  64. public class Inventory2
  65.  
  66.     {
  67.         Product[] supplies;
  68.  
  69.         public static void main(String[] args)
  70.             {
  71.                 Inventory2 inventory = new Inventory2();
  72.                 inventory.addProduct(new DVD("John Cato", 1001, "Megaforce", 10, 18.95));
  73.                 inventory.addProduct(new DVD("John Cato", 502, "Abyss", 25, 12.95));
  74.                 inventory.addProduct(new DVD("John Cato", 1003, "Deep Impact", 65, 21.95));
  75.                 inventory.addProduct(new DVD("John Cato", 750, "Forest Gump", 28, 7.95));
  76.  
  77.                 System.out.println(); // blank line
  78.                 System.out.println("Welcome to DVD Inventory 1.0"); //display header
  79.                 inventory.sortByName(); //sort list by name
  80.                 System.out.println(); // blank line
  81.                 inventory.showInventory(); //display inventory
  82.  
  83.                 double total = inventory.calculateTotalInventory();
  84.                 System.out.println("Total Value is: $" + total);
  85.  
  86.             }
  87.  
  88.         public void sortByName()
  89.             {
  90.                 for (int i = 1; i < supplies.length; i++)
  91.                     {
  92.                         int j;
  93.                         Product val = supplies[i];
  94.                         for (j = i - 1; j > -1; j--)
  95.                             {
  96.                                 Product temp = supplies[j];
  97.                                 if (temp.compareTo(val) <= 0)
  98.                                     {
  99.                                     break;
  100.                                     }
  101.                                 supplies[j + 1] = temp;
  102.                             }
  103.                         supplies[j + 1] = val;
  104.                     }
  105.             }
  106.  
  107.         public String toString() //creates a String representation of the array of products
  108.             {
  109.                 String s = "";
  110.                 for (Product p : supplies)
  111.                     {
  112.                         s = s + p.toString();
  113.                         s = s + "\n\n";
  114.                     }
  115.                 return s;
  116.             }
  117.  
  118.         public void addProduct(Product p1) //Increases the size of the array
  119.             {
  120.                 if (supplies == null)
  121.                     {
  122.                         supplies = new Product[0];
  123.                     }
  124.                 Product[] p = supplies; //Copy all products into p first
  125.                 Product[] temp = new Product[p.length + 1]; //create bigger array
  126.                 for (int i = 0; i < p.length; i++)
  127.                     {
  128.                         temp[i] = p[i];
  129.                     }
  130.                 temp[(temp.length - 1)] = p1; //add the new product at the last position
  131.                 supplies = temp;
  132.             }
  133.  
  134.         public double calculateTotalInventory() //sorting the array using Bubble Sort
  135.             {
  136.                 double total = 0.0;
  137.                 for (int i = 0; i < supplies.length; i++)
  138.                     {
  139.                         total = total + supplies[i].calculateInventoryValue();
  140.                     }
  141.                 return total;
  142.             }
  143.  
  144.         public void showInventory()
  145.         {
  146.             System.out.println(toString()); //call our toString method
  147.         }
  148.  
  149.     } //end Class Inventory2
  150.  
Mar 23 '08 #7

100+
P: 539
Let me ask you this I'm working on two different programs. below is code from my second program and I am trying to get the director to show. I have the code in correctly and it's appended the string but it's not pulling itemDirector and displaying it. Is my problem similar to my other one?

Expand|Select|Wrap|Line Numbers
  1. class Product implements Comparable
  2. {
  3.     private long itemNumber;    // class variable that stores the item number
  4.     private String itemName;    // class variable that stores the item name
  5.     private long invQuantity;   // class variable that stores the quantity in stock
  6.     private double itemPrice;   // class variable that stores the item price
  7.  
  8.         public Product(long number, String name, long quantity, double price) // Constructor for the Supplies class
  9.             {
  10.                 itemNumber = number;
  11.                 itemName = name;
  12.                 invQuantity = quantity;
  13.                 itemPrice = price;
  14.             }
  15.  
  16.  
  17.  
  18. class DVD extends Product
  19. {
  20.     private String itemDirector;
  21.     public DVD(String itemDirector,int itemNumber, String itemName, long invQuantity, double itemPrice) 
  22.         {
  23.             super(itemNumber, itemName, invQuantity, itemPrice);
  24.             //itemDirector = director;
  25.         }

you've send the values at DVD Constructor, John Cato was also carried to the DVD... BUT, when you pass it to the Product Constructor, no itemDirector was passed.... And you have no itemDirector variable initialized at global....

Set the itemDirector first.... after Passing DVD constructor....
Then use it for showing after a String Director:

Or just get the value of itemDirector @ DVD class....

i've test it....
You can do methods in just a class....

It is nice to use getter method....

Update us,
sukatoa
Mar 23 '08 #8

100+
P: 539
To avoid confusions, your problem is only at DVD constructor and the method toString() under it....

After receiving data from the DVD constructor, you forgot to initialize the itemDirector, and that parameter is also literally the same as your global variable in DVD class...You can change it... and assign that to itemDirector..

@ Your toString() method: in DVD class: Use concat method to emerge those strings....

And, "Director: \n" --- How would you print John Cato beside it, if you added newline on it, maybe after itemDirector....

I hope you got it now....

Update us
sukatoa
Mar 23 '08 #9

P: 9
To avoid confusions, your problem is only at DVD constructor and the method toString() under it....

After receiving data from the DVD constructor, you forgot to initialize the itemDirector, and that parameter is also literally the same as your global variable in DVD class...You can change it... and assign that to itemDirector..

@ Your toString() method: in DVD class: Use concat method to emerge those strings....

And, "Director: \n" --- How would you print John Cato beside it, if you added newline on it, maybe after itemDirector....

I hope you got it now....

Update us
sukatoa
Sukatoa,

I know you are helping me and I thank you but I"m still a little lost, I've done what I think you are talking about and I get an error, below is my code and the error.
Expand|Select|Wrap|Line Numbers
  1. class DVD extends Product
  2. {
  3.     private String itemDirector;
  4.  
  5.     public DVD(String itemDirector,int itemNumber, String itemName, long invQuantity, double itemPrice) 
  6.         {
  7.             super(itemNumber, itemName, invQuantity, itemPrice);
  8.             itemDirector = itemDirector;
  9.         }
  10.  
  11.     public String getItemDirector() { return itemDirector; } // Method to set item number
  12.  
  13.     public String toString() 
  14.         {
  15.             String s = String.format("Director: " + itemDirector());
  16.             s = s + super.toString();
  17.             return s;
  18.         }
  19.  
  20. }
  21.  
Error
Inventory2.java:64: cannot find symbol
symbol : method itemDirector()
location: class DVD
String s = String.format("Director: " + itemDirector());
^
1 error
Mar 23 '08 #10

P: 9
Alright I think i'm getting closer now if someone could point out why i'm getting a null value I think I have this part solved..

Expand|Select|Wrap|Line Numbers
  1. class DVD extends Product
  2. {
  3.     public String itemDirector;
  4.  
  5.     public DVD(String itemDirector,int itemNumber, String itemName, long invQuantity, double itemPrice) 
  6.         {
  7.             super(itemNumber, itemName, invQuantity, itemPrice);
  8.             itemDirector = itemDirector;
  9.             //itemNumber = number;
  10.             //itemName = name;
  11.             //invQuantity = quantity;
  12.             //itemPrice = price;
  13.         }
  14.     private String getItemDirector() { return itemDirector; } // Method to set item number
  15.  
  16.     public String toString() 
  17.         {
  18.             String s = String.format("Director: " + getItemDirector());
  19.             s = s + super.toString();
  20.             return s;
  21.         }
  22.  
  23. }
  24.  
Display:
Welcome to DVD Inventory 1.0

Director: null
Item #: 502
Name: Abyss
Quantity: 25
Price: $12.95
Value: $323.75

Director: null
Item #: 1003
Name: Deep Impact
Quantity: 65
Price: $21.95
Value: $1426.75

Director: null
Item #: 750
Name: Forest Gump
Quantity: 28
Price: $7.95
Value: $222.6

Director: null
Item #: 1001
Name: Megaforce
Quantity: 10
Price: $18.95
Value: $189.5


Total Value is: $2162.6
Mar 23 '08 #11

100+
P: 539
Alright I think i'm getting closer now if someone could point out why i'm getting a null value I think I have this part solved..

Expand|Select|Wrap|Line Numbers
  1. class DVD extends Product
  2. {
  3.     public String itemDirector;
  4.  
  5.     public DVD(String itemDirector,int itemNumber, String itemName, long invQuantity, double itemPrice) 
  6.         {
  7.             super(itemNumber, itemName, invQuantity, itemPrice);
  8.             itemDirector = itemDirector;
  9.             //itemNumber = number;
  10.             //itemName = name;
  11.             //invQuantity = quantity;
  12.             //itemPrice = price;
  13.         }
  14.     private String getItemDirector() { return itemDirector; } // Method to set item number
  15.  
  16.     public String toString() 
  17.         {
  18.             String s = String.format("Director: " + getItemDirector());
  19.             s = s + super.toString();
  20.             return s;
  21.         }
  22.  
  23. }
  24.  
Display:
Welcome to DVD Inventory 1.0

Director: null
Item #: 502
Name: Abyss
Quantity: 25
Price: $12.95
Value: $323.75

Director: null
Item #: 1003
Name: Deep Impact
Quantity: 65
Price: $21.95
Value: $1426.75

Director: null
Item #: 750
Name: Forest Gump
Quantity: 28
Price: $7.95
Value: $222.6

Director: null
Item #: 1001
Name: Megaforce
Quantity: 10
Price: $18.95
Value: $189.5


Total Value is: $2162.6
It is better to use a unique variable for storing itemDirector value....

itemDirector = tempitemDirector;

I don't know if JVM will absolutely pass the value from the parameter itemDirector to your global variable itemDirector... They are the same...

Maybe the JVM will assign like this,

itemDirector in global = itemDirector in global

That is why you got a null value...

try to have an experiment on it, try to initialize your global itemDirector any value... "I am null"....

What will happen?!! the output i mean!!....

Update us,
sukatoa
Mar 23 '08 #12

P: 9
It is better to use a unique variable for storing itemDirector value....

itemDirector = tempitemDirector;

I don't know if JVM will absolutely pass the value from the parameter itemDirector to your global variable itemDirector... They are the same...

Maybe the JVM will assign like this,

itemDirector in global = itemDirector in global

That is why you got a null value...

try to have an experiment on it, try to initialize your global itemDirector any value... "I am null"....

What will happen?!! the output i mean!!....

Update us,
sukatoa
i've tried itemDirector = getItemDirector; and even putting hard values in there and I error out, i can remark the line out and it still complies and gives me a null value. I know i'm missing the return value to carry it over to Inventory3 I just don't know what I'm missing.
Mar 24 '08 #13

P: 9
So I finally got it working !!!

Expand|Select|Wrap|Line Numbers
  1. class DVD extends Product
  2. {
  3.     private String itemDirector;
  4.  
  5.     public DVD(int itemNumber, String itemName, String itemDirector,
  6.             long invQuantity, double itemPrice) {
  7.         super(itemNumber, itemName, invQuantity, itemPrice);
  8.         this.itemDirector = itemDirector;
  9.     }
  10.  
  11.     public String getItemDirector() {
  12.         return itemDirector;
  13.     }
  14. }
  15.  
And here is the line I added to my Inventory3 class
Expand|Select|Wrap|Line Numbers
  1. System.out.println("Item Director:          " + ((DVD) product[i]).getItemDirector());
  2.  
It's taken me all weekend but you guy's did help me out
Mar 24 '08 #14

Post your reply

Sign in to post your reply or Sign up for a free account.