Results 1 to 17 of 17
  1. #1
    Exether is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default PLEASE HELP! Inventory program part 3

    I have been working on this program nonstop and keep deleting everything I add because it keeps compiling errors ugh.

    Here are the requirements.
    Modify the Inventory Program by creating a subclass of the product class that uses one additional unique feature of the product you chose (for the DVDs subclass, you could use movie title, for example).
    In the subclass, create a method to calculate the value of the inventory of a product with the same name as the method previously created for the product class.
    The subclass method should also add a 5% restocking fee to the value of the inventory of that product.
    Modify the output to display this additional feature you have chosen and the restocking fee.
    Post as an attachment

    Here is what I have so far and it compiles ok except a couple odd outputs but still runs.

    PHP Code:
    package javaapplication6;
    
    
        public class Inventory2 {
    
            Inventory2() {   
    
                VG[] vgame =  new VG[4];
    
                vgame[0] = new VG("Final Fantasy 7", 2000, 16, 12.0,"Rpg");
               vgame[1] = new VG("Modern Warfare 2", 60000, 49.99, 900.0,"First person shooter");
                vgame[2] = new VG("Super Street Fighter ", 40000, 39.99,400.0,"Fighter");
               vgame[3] = new VG("Halo Reach",20000,59.99,600.0,"First person shooter");
    
               for(int i = 0; i < 4; i++) {
    
                   
                   System.out.println(vgame[i]);
                   System.out.println();
                   System.out.println("Product Title is : " + vgame[i].getVgametitle());
                   System.out.println();
                   System.out.println("The number of units in stock is " + vgame[i].getVgamestock());
                   System.out.println();
                   System.out.println("The price of each game is: " + vgame[i].getVgameprice());
                   System.out.println();
                   System.out.println("The item number is : " + vgame[i].getVgameitem());
                   System.out.println();
                   System.out.println("The value of the inventory is : " + vgame[i].Vgamevalue());
                   System.out.println();
                  
               }
    
           }
    
           public static void main(String args []) {
    
               new Inventory2();
    
           }
    
    
    
           class VG {
    
               private String Vgametitle;
               private double Vgamestock;
               private double Vgameprice;
               private double Vgameitem;
               private double Vgamevalue;
               VG(String title, double stock, double price, double item) {
                   Vgametitle = title;
                   Vgamestock = stock;
                   Vgameprice = price;
                   Vgameitem  = item;
    
               }
    
               public void setVgametitle(String title) {
                   Vgametitle = title;
               } 
    
               
               public String getVgametitle() {
                   return Vgametitle;
               } 
    
               
               public void setVgamestock(double stock) {
                   Vgamestock = stock;
               } 
    
              
               public double getVgamestock() {
                   return Vgamestock;
               } 
    
    
    
               public void setVgameprice(double price) {
    
                   Vgameprice = price;
               } 
    
               
               public double getVgameprice() {
                   return Vgameprice;
               } 
    
               public void setVgameitem(double item) {
                   Vgameitem = item;
               } 
    
               
               public double getVgameitem() {
                   return Vgameitem;
               } 
    
               
               public double Vgamevalue() {
                   return Vgameprice * Vgamestock;
                   
             
               }
                   
              public class VGG extends Inventory2 {
    
                    
                    private String Vgamegenre;
                    
                 
                 
                    
           public void setVgamegenre(String genre) {
                Vgamegenre = genre;
            }        
    
            public String getVgamegenre() {
                return Vgamegenre;
            }        
                   
                   
                   
               }
                   
               }
    Last edited by Exether; 07-26-2010 at 05:32 AM.

  2. #2
    Exether is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default

    Just a hour ago I added a subclass: public class Videogamefuture extends VG {....... and it compiled errors?

    I am using NetBeans if this helps at all. Thanks.

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  4. #4
    Exether is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default

    PHP Code:
    ERROR START HERE>>> public class VGG extends Inventory2 {
    
                    
                    private String Vgamegenre;
                    
        
                  } 
                    
           public void setVgamegenre(String genre) {
                Vgamegenre = genre;
            }        
    
            public String getVgamegenre() {
                return Vgamegenre;
            }
    I just added this to make a subclass.
    The errors are "illegal start of expression".

    I am doing 1 step at a time and right now I am trying to create the extra item within the instructions and then the 5% restocking fee. Thanks.
    Last edited by Exether; 07-26-2010 at 04:37 AM.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    You appear to have an end curly bracket in the wrong place:
    Java Code:
                    private String Vgamegenre;
                    
        
                  } //  **** what is this closing curly brace doing here?? ****
                    
           public void setVgamegenre(String genre) {
                Vgamegenre = genre;
            }        
    
            public String getVgamegenre() {
                return Vgamegenre;
            }

  6. #6
    Exether is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default

    I apologize that is not there, I forgot to delete that in the forum but it is not in the netbeans.

  7. #7
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    OK, show the corrected code and the location for the error as well as any code or declarations before the error. Also, do you happen to have the code to more than one class in one file?

  8. #8
    Exether is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default

    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol
    symbol: constructor VG(java.lang.String,int,int,double,java.lang.Strin g)
    location: class javaapplication6.Inventory2.VG
    at javaapplication6.Inventory2.<init>(Inventory2.java :10)
    at javaapplication6.Inventory2.main(Inventory2.java:3 7)
    Java Result: 1

    Um thats all I come up with after executing. The program ran fine before I tried starting to create a subclass so any problems have to be stemming from that. I am by no means advanced with java so most of the errors such as the ones above I can barely understand. This is my first java class ever so I am sorry for the lack of knowledge.

  9. #9
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    The error is telling you exactly what's wrong, and it's not cryptic, not at all. It's saying that it can't find a constructor in the VG class that takes a String, int, int, double, String as a parameter, and if you look through the class code, you won't be able to find one either.

    You haven't posted the line causing the code, line 2 of Inventory2.

  10. #10
    Exether is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default

    I don't understand what you mean by writing line 2 causing code of inventory 2.

    I added this to my code but then took it out, it was placed right after where the error starts and it starts another error.

    PHP Code:
     public VGG(String title, double stock, double price, double item) {
                      super(title, stock, price, item);

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Sorry, I meant line 10 of the class. The exception states:
    Default
    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - cannot find symbol
    symbol: constructor VG(java.lang.String,int,int,double,java.lang.Strin g)
    location: class javaapplication6.Inventory2.VG
    at javaapplication6.Inventory2.<init>(Inventory2.java :10)
    and this line here:
    at javaapplication6.Inventory2.<init>(Inventory2.java :10)
    tells you that the exception is being tripped by line 10 of the Inventory2 class. So what line is on line 10?

  12. #12
    Exether is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default

    PHP Code:
    ERROR LINE 10_____ vgame[0] = new VG("Final Fantasy 7", 2000, 16, 12.0);
               vgame[1] = new VG("Modern Warfare 2", 60000, 49.99, 900.0);
                vgame[2] = new VG("Super Street Fighter ", 40000, 39.99,400.0);
               vgame[3] = new VG("Halo Reach",20000,59.99,600.0);
    It is saying something is wrong with the "VG" " Cannot find symbol". It is declared later on in a class? I don't understand why its saying it cannot find it because I added a subclass but nowhere in the subclass is VG stated? It has something to do with the subclass but idk what since I just started using subclasses today.

  13. #13
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  14. #14
    Exether is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default

    The error for line 10 is : cannot find symbol
    symbol: constructor VG(java.lang.String,int,int,double,java.lang.Strin g)
    location: class javaapplication6.Inventory2.VG

    I posted all of my code above?

  15. #15
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    I don't remember the original code having the Strings as the last parameter of these constructor calls:
    Java Code:
          vgame[0] = new VG("Final Fantasy 7", 2000, 16, 12.0, "Rpg");
          vgame[1] = new VG("Modern Warfare 2", 60000, 49.99, 900.0, "First person shooter");
          vgame[2] = new VG("Super Street Fighter ", 40000, 39.99, 400.0, "Fighter");
          vgame[3] = new VG("Halo Reach", 20000, 59.99, 600.0, "First person shooter");
    I mean the Strings "Rpg", "First person shooter", "Fighter", "First person shooter". And in fact you must have changed the code as it was not present before and isn't present in your latest post here:
    Java Code:
    ERROR LINE 10_____ vgame[0] = new VG("Final Fantasy 7", 2000, 16, 12.0);
               vgame[1] = new VG("Modern Warfare 2", 60000, 49.99, 900.0);
                vgame[2] = new VG("Super Street Fighter ", 40000, 39.99,400.0);
               vgame[3] = new VG("Halo Reach",20000,59.99,600.0);
    But regardless, the problem is your constructor can't handle these Strings as there is no constructor that takes a String as the last parameter. Your solution is to either remove the last parameter in the constructor calls or change your constructor so that it can handle an extra parameter that is a String, simple as that. Again, the error message is telling you what is wrong.

  16. #16
    Exether is offline Member
    Join Date
    Jul 2010
    Posts
    11
    Rep Power
    0

    Default

    What can I add to the constructor so it can handle strings?
    Last edited by Exether; 07-26-2010 at 06:02 AM.

  17. #17
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Exether View Post
    What can I add to the instructor so it can handle strings?
    It's "constructor" not "instructor", and you would do well to read up about these babies because if you're going to be doing any Java coding at all, you'll need to know about them. The bottom line here is that number, type, and order of the arguments passed to a constructor or method must match exactly those in the declared constructor or method. For instance, if you have a class called Patient that looks like this:

    Java Code:
    public class Patient {
       String lastName;
       String firstName;
       String dateOfBirth;
    
       public Patient(String lastName, String firstName, String dateOfBirth) {
          this.lastName = lastName;
          this.firstName = firstName;
          this.dateOfBirth = dateOfBirth;
       }
    }

    If you create new Patient objects with its constructor, you'd better pass three and only three Strings into it since that's how you've defined the constructor. So this is kosher:
    Java Code:
       public static void main(String[] args) {
          Patient patient1 = new Patient("Smith", "John", "2/15/45");
       }

    but this isn't:
    Java Code:
       public static void main(String[] args) {
          int numberOfKids = 4;
          Patient patient1 = new Patient("Smith", "John", "2/15/45", numberOfKids);
       }
    because there is no constructor that will accept three Strings and an int. For the latter constructor call to work, you'll need to create a constructor that will accept this:

    Java Code:
    public class Patient {
       String lastName;
       String firstName;
       String dateOfBirth;
       int numberOfChildren;
    
       // note the change in this constructor
       public Patient(String lastName, String firstName, String dateOfBirth, int kids) {
          this.lastName = lastName;
          this.firstName = firstName;
          this.dateOfBirth = dateOfBirth;
          this.numberOfChildren = kids;
       }
    
       public static void main(String[] args) {
          int numberOfKids = 4;
          Patient patient1 = new Patient("Smith", "John", "2/15/45", numberOfKids);
       }
    }

Similar Threads

  1. Inventory Program Part 2 of 6
    By tlouvierre in forum New To Java
    Replies: 2
    Last Post: 05-28-2009, 02:30 AM
  2. Inventory Program Part 3 ~ please help!
    By marMcD in forum New To Java
    Replies: 13
    Last Post: 02-25-2009, 06:57 AM
  3. Java Inventory Program Part 3
    By ljk8950 in forum New To Java
    Replies: 18
    Last Post: 07-28-2008, 06:47 AM
  4. Inventory Program Part 3 - DUE TODAY (7/28/08)
    By ljk8950 in forum New To Java
    Replies: 7
    Last Post: 07-27-2008, 11:28 PM
  5. Inventory part 3 program problems
    By badness in forum New To Java
    Replies: 1
    Last Post: 12-17-2007, 08:00 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •