473,326 Members | 2,168 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Inventory Program - Won't complie

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
13 2053
sukatoa
539 512MB
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
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
sukatoa
539 512MB
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
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
sukatoa
539 512MB
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
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
sukatoa
539 512MB
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
sukatoa
539 512MB
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
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
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
sukatoa
539 512MB
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
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
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

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

Similar topics

109
by: zaidalin79 | last post by:
I have a java class that goes for another week or so, and I am going to fail if I can't figure out this simple program. I can't get anything to compile to at least get a few points... Here are the...
0
by: south622 | last post by:
I'm taking a beginning Java course and I'm stuck in week eight of a nine week course. If anyone could help me I would greatly appreciate it. This assignment was due yesterday and each day I go past...
4
nexcompac
by: nexcompac | last post by:
Ok, I posted a similar post but now need to jump back into it. Here is what I have been able to clean up. I am using textpad and jbuilder. Still getting used to the whole java world and I am...
9
by: xxplod | last post by:
I am suppose to modify the Inventory Program so the application can handle multiple items. Use an array to store the items. The output should display the information one product at a time, including...
3
by: cblank | last post by:
I need some help if someone could help me. I know everyone is asking for help in java. But for some reason I'm the same as everyone else when it comes to programming in java. I have an inventory...
2
by: pinkf24 | last post by:
I cannot figure out how to add the following: Modify the Inventory Program to include an Add button, a Delete button, and a Modify button on the GUI. These buttons should allow the user to perform...
1
by: jcato77 | last post by:
I need help with a class project I'm working on, Below is my assignment and the code I have currently created. Assignment: Modify the Inventory Program by creating a subclass of the product class...
3
by: 100grand | last post by:
Modify the Inventory Program to use a GUI. The GUI should display the information one product at a time, including the item number, the name of the product, the number of units in stock, the price...
2
by: blitz1989 | last post by:
Hello all, I'm new to this forum and Java and having a alot of problems understanding this language. I am working on an invetory program part 4. The assignment requirements are listed but the...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.