Page 1 of 2 12 LastLast
Results 1 to 20 of 30
Like Tree2Likes

Thread: Desperate, Can not figure it out!

  1. #1
    Mshelly is offline Member
    Join Date
    Jul 2014
    Location
    New Jersey
    Posts
    21
    Rep Power
    0

    Default Desperate, Can not figure it out!

    HI
    I do not get any error but I am trying to sort the array, and also I can not get anything from the sub class to work I am having trouble creating the object. .. No matter where I do any print commands I get nothing. I have been trying this for days, and I am losing my mind. I need a push in the right direction please. I know I have something not right. It is for school I don't want someone to do it, I just want advise please. I want to learn.

    Java Code:
    package pkg3.inventory.program;
    import java.util.Scanner;
    
    /**
     *
     * @author michelle
     */
    public class InventoryProgram 
    {
    
        /**
         * @param args the command line arguments
         */
        
        static int max = 5;
        static final Product[] DVD = new Product[max];
    //create array
         public static void main(String[] args) 
    {
       Scanner input = new Scanner(System.in);
       Product Pro;
       Genre g;
             DVD[0] = new Product("Dawn of the Dead", 123456, 10, 10,"Horror");
             DVD[1] = new Product("Walking Dead S1", 234567, 10, 20,"Horror");
             DVD[2] = new Product("Tinkerbell", 345678, 10, 12,"Kids");
             DVD[3] = new Product("Spongebob", 456789, 10, 15,"Kids");
             DVD[4] = new Product("Star Wars", 567890, 5, 30,"Scifi");
             Calculate(DVD);
             print(DVD);
             sort(DVD);
    }//end array
         //count and print
        static void print(Product[] DVD) 
    {
              System.out.println();
              for (int i = 0; i < max; i++) 
              {
    System.out.printf("\nName: " + DVD[i].Name + ", UPC: " + DVD[i].UPC + ", QTY: " + DVD[i].Stock + ", Price: $"+DVD[i].Price+" DVD Value: $" + DVD[i].Value +"Genre: " + DVD[i].genre);
              }
    }
        //calculate the value of DVD stock
        static void Calculate(Product[] DVD) 
         {
              int ttlvalue = 0;      
              for (int i = 0; i < max; i++) 
              {
                   ttlvalue += DVD[i].Value;
              }
    
         System.out.println("Total Inventory Value is: $" + ttlvalue);
     
         }
     
        static void sort(Product[] DVD) 
         {
              java.util.Arrays.sort(DVD);
         }
     
    }//end InventoryProgram
    //create class
    class Product implements Comparable< Product> 
    {
         int Stock, UPC, Price,Value;
         String Name, genre;
        int Fee;
    
         public Product(String DVDName, int UPCNum, int StockQty, int Retail,String MovieGenre) 
         {
              this.Name = DVDName;
              this.UPC = UPCNum;
              this.Stock = StockQty;
              this.Price = Retail;
              this.genre=MovieGenre;
              this.Value=Stock*Price;
         }
      
    //sort array
         @Override
           public int compareTo(Product sortProduct) 
         {
              return this.genre.compareTo(sortProduct.genre);
         }
           
    }//end product class
    Java Code:
    package pkg3.inventory.program;
    
    
    public class Genre extends Product 
    {
        public static String MovieGenre;
        public  static int Fee;
    
        public Genre(String DVDName, int UPCNum, int StockQty, int Retail, String MovieGenre) {
            super(DVDName, UPCNum, StockQty, Retail, MovieGenre);
            Genre.MovieGenre=genre;
            Genre.Fee=0;
        }
        public void setMovieGenre(String genre)
        {
            Genre.MovieGenre=genre;
        }
        public String getMovieGenre()
        {
            return genre;
        }
        public int setFee()
        {
            super.Fee= (int) (Value *.05);
            return super.Fee;
        }
        public int getFee()
        {
            return super.Fee=(int) (Value*.05);
        }
    
    }

  2. #2
    anjibman is offline Member
    Join Date
    Dec 2010
    Posts
    46
    Rep Power
    0

    Default Re: Desperate, Can not figure it out!

    Remove final from line 16

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,454
    Rep Power
    25

    Default Re: Desperate, Can not figure it out!

    Are you getting any error messages? Copy the full text of the error messages and paste it here.
    If you don't understand my response, don't ignore it, ask a question.

  4. #4
    Mshelly is offline Member
    Join Date
    Jul 2014
    Location
    New Jersey
    Posts
    21
    Rep Power
    0

    Default Re: Desperate, Can not figure it out!

    Okay I have done this Thank you, but I still can't figure out why I can not create the object or call from the sub class. Am I putting it in the wrong place or missing something?
    This is what happens when I put it in (line 58 & 60) the entire thing will not run.
    Java.lang.ClassFormatError: Method "<error>" in class pkg3/inventory/program/InventoryProgram has illegal signature "(Ljava/lang/Object;)Ljava/lang/System$out$println;"
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :760)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader .java:455)
    at java.net.URLClassLoader.access$100(URLClassLoader. java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 367)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:4 24)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 57)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Launc herHelper.java:495)
    Exception in thread "main" Java Result: 1
    BUILD SUCCESSFUL (total time: 1 second)
    Java Code:
    package pkg3.inventory.program;
    import java.util.Scanner;
    
    /**
     *
     * @author michelle
     */
    public class InventoryProgram 
    {
    
        /**
         * @param args the command line arguments
         */
        
        static int max = 5;
        static Product[] DVD = new Product[max];
    //create array
         public static void main(String[] args) 
    {
       Scanner input = new Scanner(System.in);
       Product Pro;
       Genre g;
             DVD[0] = new Product("Dawn of the Dead", 123456, 10, 10,"Horror");
             DVD[1] = new Product("Walking Dead S1", 234567, 10, 20,"Horror");
             DVD[2] = new Product("Tinkerbell", 345678, 10, 12,"Kids");
             DVD[3] = new Product("Spongebob", 456789, 10, 15,"Kids");
             DVD[4] = new Product("Star Wars", 567890, 5, 30,"Scifi");
             Calculate(DVD);
             print(DVD);
             sort(DVD);
    }//end array
         //count and print
        static void print(Product[] DVD) 
    {
              System.out.println();
              for (int i = 0; i < max; i++) 
              {
    System.out.printf("\nName: " + DVD[i].Name + ", UPC: " + DVD[i].UPC + ", QTY: " + DVD[i].Stock + ", Price: $"+DVD[i].Price+" DVD Value: $" + DVD[i].Value +"Genre: " + DVD[i].genre);
              }
    }
        //calculate the value of DVD stock
        static void Calculate(Product[] DVD) 
         {
              int ttlvalue = 0;      
              for (int i = 0; i < max; i++) 
              {
                   ttlvalue += DVD[i].Value;
              }
    
         System.out.println("Total Inventory Value is: $" + ttlvalue);
     
         }
     
        static void sort(Product[] DVD) 
         {
              java.util.Arrays.sort(DVD);
         }
        Genre g =new Genre();
                
     System.out.println("Genre: "+g.getMovieGenre()+"Fee: "+g.getFee());
    }//end InventoryProgram
    //create class
    class Product implements Comparable< Product> 
    {
         int Stock, UPC, Price,Value;
         String Name, genre;
        int Fee;
    
         public Product(String DVDName, int UPCNum, int StockQty, int Retail,String MovieGenre) 
         {
              this.Name = DVDName;
              this.UPC = UPCNum;
              this.Stock = StockQty;
              this.Price = Retail;
              this.genre=MovieGenre;
              this.Value=Stock*Price;
         }
      
    //sort array
         @Override
           public int compareTo(Product sortProduct) 
         {
              return this.genre.compareTo(sortProduct.genre);
         }
           
    }//end product class

  5. #5
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,454
    Rep Power
    25

    Default Re: Desperate, Can not figure it out!

    Java.lang.ClassFormatError: Method "<error>" in class pkg3/inventory/program/InventoryProgram has illegal signature "(Ljava/lang/Object;)Ljava/lang/System$out$println;"
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :760)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader .java:455)
    at java.net.URLClassLoader.access$100(URLClassLoader. java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 367)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:4 24)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 57)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Launc herHelper.java:495)
    The error message does not have the source line number. How are you compiling the source?
    I haven't seen that error message before.
    If you don't understand my response, don't ignore it, ask a question.

  6. #6
    Mshelly is offline Member
    Join Date
    Jul 2014
    Location
    New Jersey
    Posts
    21
    Rep Power
    0

    Default Re: Desperate, Can not figure it out!

    I am using Netbeans. This is what comes up on the output. Is there another way to get errors?

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,454
    Rep Power
    25

    Default Re: Desperate, Can not figure it out!

    The javac compiler that comes with the JDK gives good error messages.
    If you don't understand my response, don't ignore it, ask a question.

  8. #8
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    836
    Rep Power
    6

    Default Re: Desperate, Can not figure it out!

    some other issue might be in your IDE.i have compiled and executed your code.
    Below is the output
    Total Inventory Value is: $720


    Name: Dawn of the Dead, UPC: 123456, QTY: 10, Price: $10 DVD Value: $100Genre: Horror
    Name: Walking Dead S1, UPC: 234567, QTY: 10, Price: $20 DVD Value: $200Genre: Horror
    Name: Tinkerbell, UPC: 345678, QTY: 10, Price: $12 DVD Value: $120Genre: Kids
    Name: Spongebob, UPC: 456789, QTY: 10, Price: $15 DVD Value: $150Genre: Kids
    Name: Star Wars, UPC: 567890, QTY: 5, Price: $30 DVD Value: $150Genre: Scifi
    Ramya:cool:

  9. #9
    Mshelly is offline Member
    Join Date
    Jul 2014
    Location
    New Jersey
    Posts
    21
    Rep Power
    0

    Default Re: Desperate, Can not figure it out!

    Quote Originally Posted by RamyaSivakanth View Post
    some other issue might be in your IDE.i have compiled and executed your code.
    Below is the output
    Total Inventory Value is: $720


    Name: Dawn of the Dead, UPC: 123456, QTY: 10, Price: $10 DVD Value: $100Genre: Horror
    Name: Walking Dead S1, UPC: 234567, QTY: 10, Price: $20 DVD Value: $200Genre: Horror
    Name: Tinkerbell, UPC: 345678, QTY: 10, Price: $12 DVD Value: $120Genre: Kids
    Name: Spongebob, UPC: 456789, QTY: 10, Price: $15 DVD Value: $150Genre: Kids
    Name: Star Wars, UPC: 567890, QTY: 5, Price: $30 DVD Value: $150Genre: Scifi
    Good Morning,

    I can get this to work, but when I want to get information from the Subclass, that's when it all breaks. I don't know what I am doing wrong. How do I get the sub class information to print?

    Any push, or suggestion would be great.

  10. #10
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    947
    Rep Power
    2

    Default Re: Desperate, Can not figure it out!

    Quote Originally Posted by Mshelly View Post
    Good Morning,

    I can get this to work, but when I want to get information from the Subclass, that's when it all breaks. I don't know what I am doing wrong. How do I get the sub class information to print?

    Any push, or suggestion would be great.
    Stop making everything static in Genre. It's absolutely not necessary. Read about what "static" does to avoid "adding it because it works".
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  11. #11
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: Desperate, Can not figure it out!

    Number one reason for people to static everything: because if they remove the static keyword the compiler starts to complain. What people fail to realize is that the compiler complains with good reason and not understanding what that reason is, is the true problem that needs to be solved.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  12. #12
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,454
    Rep Power
    25

    Default Re: Desperate, Can not figure it out!

    How do I get the sub class information to print?
    Does the code compile and execute now?
    If you don't understand my response, don't ignore it, ask a question.

  13. #13
    Mshelly is offline Member
    Join Date
    Jul 2014
    Location
    New Jersey
    Posts
    21
    Rep Power
    0

    Default Re: Desperate, Can not figure it out!

    Quote Originally Posted by SurfMan View Post
    Stop making everything static in Genre. It's absolutely not necessary. Read about what "static" does to avoid "adding it because it works".
    When I remove the static in the subclass, I then get the errors "Non-Static Variable MovieGenre cannot be referenced from a static context". If I remove static all together nothing works at all.
    Even with those errors in the subclass I still get no errors when I run.

    This is the output. I need to somehow get the Genre and Restock fee, which I can not get at all.


    run:
    Total Inventory Value is: $720


    Name: Dawn of the Dead, UPC: 123456, QTY: 10, Price: $10 DVD Value: $100Genre: Horror
    Name: Walking Dead S1, UPC: 234567, QTY: 10, Price: $20 DVD Value: $200Genre: Horror
    Name: Tinkerbell, UPC: 345678, QTY: 10, Price: $12 DVD Value: $120Genre: Kids
    Name: Spongebob, UPC: 456789, QTY: 10, Price: $15 DVD Value: $150Genre: Kids
    Name: Star Wars, UPC: 567890, QTY: 5, Price: $30 DVD Value: $150Genre: ScifiBUILD SUCCESSFUL (total time: 0 seconds)

  14. #14
    Mshelly is offline Member
    Join Date
    Jul 2014
    Location
    New Jersey
    Posts
    21
    Rep Power
    0

    Default Re: Desperate, Can not figure it out!

    Hi
    I can get the program to compile, however when I try and call any information from the subclass it doesn't work. I don't know if I am doing it wrong or I have something wrong. I cannot figure it out. I uninstalled and reinstalled Netbeans I am going to give this a shot.

  15. #15
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,454
    Rep Power
    25

    Default Re: Desperate, Can not figure it out!

    when I try and call any information from the subclass it doesn't work
    Please explain what "doesn't work" means.
    Copy the program's output and paste it here to show what it does when it is executed.
    If you don't understand my response, don't ignore it, ask a question.

  16. #16
    Mshelly is offline Member
    Join Date
    Jul 2014
    Location
    New Jersey
    Posts
    21
    Rep Power
    0

    Default Re: Desperate, Can not figure it out!

    I want to thank you for your help.

    My out put is:

    run:
    Total Inventory Value is: $720


    Name: Dawn of the Dead, UPC: 123456, QTY: 10, Price: $10 DVD Value: $100Genre: Horror
    Name: Walking Dead S1, UPC: 234567, QTY: 10, Price: $20 DVD Value: $200Genre: Horror
    Name: Tinkerbell, UPC: 345678, QTY: 10, Price: $12 DVD Value: $120Genre: Kids
    Name: Spongebob, UPC: 456789, QTY: 10, Price: $15 DVD Value: $150Genre: Kids
    Name: Star Wars, UPC: 567890, QTY: 5, Price: $30 DVD Value: $150Genre: ScifiBUILD SUCCESSFUL (total time: 1 second)


    What I would like to know how to do correctly, is how do I get information from the subclass to print?
    I want print the Restock Fee (Fee) by Genre (MovieGenre).
    I can not get this to work. If I put code in to print the calculated restock fee by genre the entire thing will stop working, or it will ignore it and just not print. I don't know if I am putting the print command in the wrong places, I have tried in the main, the class and in the subclass. I know I am missing something.

  17. #17
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,454
    Rep Power
    25

    Default Re: Desperate, Can not figure it out!

    the entire thing will stop working,
    What does "stop working" mean? If there are errors, solve them, don't ignore them.

    Post the full text of any error messages and the code that is causing the error.
    If you don't understand my response, don't ignore it, ask a question.

  18. #18
    Mshelly is offline Member
    Join Date
    Jul 2014
    Location
    New Jersey
    Posts
    21
    Rep Power
    0

    Default Re: Desperate, Can not figure it out!

    I get an error on the line I type
    Java Code:
    System.out.println("The Genre: "+Genre.MovieGenre()+"Has a restock fee:"+Genre.super.Fee());
    I get:
    (cannot find symbol class out location class system <identifier> expected illegal start of type)

    When I run, the output is:
    run:
    java.lang.ClassFormatError: Method "<error>" in class inventoryprogram3/Inventoryprogram3 has illegal signature "(Ljava/lang/Object;)Ljava/lang/System$out$println;"
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java :760)
    at java.security.SecureClassLoader.defineClass(Secure ClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader .java:455)
    at java.net.URLClassLoader.access$100(URLClassLoader. java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 367)
    at java.net.URLClassLoader$1.run(URLClassLoader.java: 361)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.j ava:360)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:4 24)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launche r.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:3 57)
    at sun.launcher.LauncherHelper.checkAndLoadMain(Launc herHelper.java:495)
    Exception in thread "main" Java Result: 1
    BUILD SUCCESSFUL (total time: 4 seconds)


    Errors open in classloader.java:

    Java Code:
    package java.security;
    
    import java.util.HashMap;
    import java.util.ArrayList;
    import java.net.URL;
    
    import sun.security.util.Debug;
    
    /**
     * This class extends ClassLoader with additional support for defining
     * classes with an associated code source and permissions which are
     * retrieved by the system policy by default.
     *
     * @author  Li Gong
     * @author  Roland Schemers
     */
    public class SecureClassLoader extends ClassLoader {
        /*
         * If initialization succeed this is set to true and security checks will
         * succeed. Otherwise the object is not initialized and the object is
         * useless.
         */
        private final boolean initialized;
    
        // HashMap that maps CodeSource to ProtectionDomain
        // @GuardedBy("pdcache")
        private final HashMap<CodeSource, ProtectionDomain> pdcache =
                            new HashMap<>(11);
    
        private static final Debug debug = Debug.getInstance("scl");
    
        static {
            ClassLoader.registerAsParallelCapable();
        }
    
        /**
         * Creates a new SecureClassLoader using the specified parent
         * class loader for delegation.
         *
         * <p>If there is a security manager, this method first
         * calls the security manager's {@code checkCreateClassLoader}
         * method  to ensure creation of a class loader is allowed.
         * <p>
         * @param parent the parent ClassLoader
         * @exception  SecurityException  if a security manager exists and its
         *             {@code checkCreateClassLoader} method doesn't allow
         *             creation of a class loader.
         * @see SecurityManager#checkCreateClassLoader
         */
        protected SecureClassLoader(ClassLoader parent) {
            super(parent);
            // this is to make the stack depth consistent with 1.1
            SecurityManager security = System.getSecurityManager();
            if (security != null) {
                security.checkCreateClassLoader();
            }
            initialized = true;
        }
    
        /**
         * Creates a new SecureClassLoader using the default parent class
         * loader for delegation.
         *
         * <p>If there is a security manager, this method first
         * calls the security manager's {@code checkCreateClassLoader}
         * method  to ensure creation of a class loader is allowed.
         *
         * @exception  SecurityException  if a security manager exists and its
         *             {@code checkCreateClassLoader} method doesn't allow
         *             creation of a class loader.
         * @see SecurityManager#checkCreateClassLoader
         */
        protected SecureClassLoader() {
            super();
            // this is to make the stack depth consistent with 1.1
            SecurityManager security = System.getSecurityManager();
            if (security != null) {
                security.checkCreateClassLoader();
            }
            initialized = true;
        }
    
        /**
         * Converts an array of bytes into an instance of class Class,
         * with an optional CodeSource. Before the
         * class can be used it must be resolved.
         * <p>
         * If a non-null CodeSource is supplied a ProtectionDomain is
         * constructed and associated with the class being defined.
         * <p>
         * @param      name the expected name of the class, or {@code null}
         *                  if not known, using '.' and not '/' as the separator
         *                  and without a trailing ".class" suffix.
         * @param      b    the bytes that make up the class data. The bytes in
         *             positions {@code off} through {@code off+len-1}
         *             should have the format of a valid class file as defined by
         *             <cite>The Java&trade; Virtual Machine Specification</cite>.
         * @param      off  the start offset in {@code b} of the class data
         * @param      len  the length of the class data
         * @param      cs   the associated CodeSource, or {@code null} if none
         * @return the {@code Class} object created from the data,
         *         and optional CodeSource.
         * @exception  ClassFormatError if the data did not contain a valid class
         * @exception  IndexOutOfBoundsException if either {@code off} or
         *             {@code len} is negative, or if
         *             {@code off+len} is greater than {@code b.length}.
         *
         * @exception  SecurityException if an attempt is made to add this class
         *             to a package that contains classes that were signed by
         *             a different set of certificates than this class, or if
         *             the class name begins with "java.".
         */
        protected final Class<?> defineClass(String name,
                                             byte[] b, int off, int len,
                                             CodeSource cs)
        {
            return defineClass(name, b, off, len, getProtectionDomain(cs));
        }
    
        /**
         * Converts a {@link java.nio.ByteBuffer ByteBuffer}
         * into an instance of class {@code Class}, with an optional CodeSource.
         * Before the class can be used it must be resolved.
         * <p>
         * If a non-null CodeSource is supplied a ProtectionDomain is
         * constructed and associated with the class being defined.
         * <p>
         * @param      name the expected name of the class, or {@code null}
         *                  if not known, using '.' and not '/' as the separator
         *                  and without a trailing ".class" suffix.
         * @param      b    the bytes that make up the class data.  The bytes from positions
         *                  {@code b.position()} through {@code b.position() + b.limit() -1}
         *                  should have the format of a valid class file as defined by
         *                  <cite>The Java&trade; Virtual Machine Specification</cite>.
         * @param      cs   the associated CodeSource, or {@code null} if none
         * @return the {@code Class} object created from the data,
         *         and optional CodeSource.
         * @exception  ClassFormatError if the data did not contain a valid class
         * @exception  SecurityException if an attempt is made to add this class
         *             to a package that contains classes that were signed by
         *             a different set of certificates than this class, or if
         *             the class name begins with "java.".
         *
         * @since  1.5
         */
        protected final Class<?> defineClass(String name, java.nio.ByteBuffer b,
                                             CodeSource cs)
        {
            return defineClass(name, b, getProtectionDomain(cs));
        }
    
        /**
         * Returns the permissions for the given CodeSource object.
         * <p>
         * This method is invoked by the defineClass method which takes
         * a CodeSource as an argument when it is constructing the
         * ProtectionDomain for the class being defined.
         * <p>
         * @param codesource the codesource.
         *
         * @return the permissions granted to the codesource.
         *
         */
        protected PermissionCollection getPermissions(CodeSource codesource)
        {
            check();
            return new Permissions(); // ProtectionDomain defers the binding
        }
    
        /*
         * Returned cached ProtectionDomain for the specified CodeSource.
         */
        private ProtectionDomain getProtectionDomain(CodeSource cs) {
            if (cs == null)
                return null;
    
            ProtectionDomain pd = null;
            synchronized (pdcache) {
                pd = pdcache.get(cs);
                if (pd == null) {
                    PermissionCollection perms = getPermissions(cs);
                    pd = new ProtectionDomain(cs, perms, this, null);
                    pdcache.put(cs, pd);
                    if (debug != null) {
                        debug.println(" getPermissions "+ pd);
                        debug.println("");
                    }
                }
            }
            return pd;
        }
    
        /*
         * Check to make sure the class loader has been initialized.
         */
        private void check() {
            if (!initialized) {
                throw new SecurityException("ClassLoader object not initialized");
            }
        }
    
    }

  19. #19
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,454
    Rep Power
    25

    Default Re: Desperate, Can not figure it out!

    Can you post the code showing where the statement with the problem is located? The statement by itself does not show its context.

    The error sounds like the statement could be located outside of a method.
    Make sure the statement is inside of a method.

    BTW The formatting of the code makes it hard to read and understand. The indentations and placing of the {}s are not consistent.
    If you don't understand my response, don't ignore it, ask a question.

  20. #20
    Mshelly is offline Member
    Join Date
    Jul 2014
    Location
    New Jersey
    Posts
    21
    Rep Power
    0

    Default Re: Desperate, Can not figure it out!

    Sure, again thank you for your time.

    Java Code:
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package inventoryprogram3;
    import java.util.Scanner;
    /**
     *
     * @author michelle
     */
    public class Inventoryprogram3 {
    
        /**
         * @param args the command line arguments
         */
      static int max = 5;
        static final Product[] DVD = new Product[max];
    //create array
         public static void main(String[] args)
    {
       Scanner input = new Scanner(System.in);
       Product Pro;
       Genre g;
             DVD[0] = new Product("Dawn of the Dead", 123456, 10, 10,"Horror");
             DVD[1] = new Product("Walking Dead S1", 234567, 10, 20,"Horror");
             DVD[2] = new Product("Tinkerbell", 345678, 10, 12,"Kids");
             DVD[3] = new Product("Spongebob", 456789, 10, 15,"Kids");
             DVD[4] = new Product("Star Wars", 567890, 5, 30,"Scifi");
             Calculate(DVD);
             print(DVD);
             sort(DVD);
    }//end array
         //count and print
        static void print(Product[] DVD)
    {
              System.out.println();
              for (int i = 0; i < max; i++)
              {
    System.out.printf("\nName: " + DVD[i].Name + ", UPC: " + DVD[i].UPC + ", QTY: " + DVD[i].Stock 
            + ", Price: $"+DVD[i].Price+" DVD Value: $" + DVD[i].Value +"Genre: " + DVD[i].genre);
              }
    }
        //calculate the value of DVD stock
        static void Calculate(Product[] DVD)
         {
              int ttlvalue = 0;     
              for (int i = 0; i < max; i++)
              {
                   ttlvalue += DVD[i].Value;
              }
     
         System.out.println("Total Inventory Value is: $" + ttlvalue);
      
         }
      
        static void sort(Product[] DVD)
         {
              java.util.Arrays.sort(DVD);
         }
        Genre g = new Genre(DVDName, UPCNum, StockQty,Retail,MovieGenre);
    System.out.println("The Genre: "+Genre.MovieGenre()+"Has a restock fee:"+Genre.super.Fee());
    }//end InventoryProgram
    //create class
    class Product implements Comparable< Product>
    {
         int Stock, UPC, Price,Value;
         String Name, genre;
        int Fee;
     
         public Product(String DVDName, int UPCNum, int StockQty, int Retail,String MovieGenre)
         {
              this.Name = DVDName;
              this.UPC = UPCNum;
              this.Stock = StockQty;
              this.Price = Retail;
              this.genre=MovieGenre;
              this.Value=Stock*Price;
         }
       
    //sort array
         @Override
           public int compareTo(Product sortProduct)
         {
              return this.genre.compareTo(sortProduct.genre);
         }
            
    }//end product class
    Java Code:
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package inventoryprogram3;
    
    
    public class Genre extends Product
    {
        public  String MovieGenre;
        public   int Fee;
     
        public Genre(String DVDName, int UPCNum, int StockQty, int Retail, String MovieGenre) {
            super(DVDName, UPCNum, StockQty, Retail, MovieGenre);
            Genre.MovieGenre=genre;
            Genre.Fee=0;
        }
        public void setMovieGenre(String genre)
        {
            Genre.MovieGenre=genre;
        }
        public String getMovieGenre()
        {
            return genre;
        }
        public int setFee()
        {
            super.Fee= (int) (Value *.05);
            return super.Fee;
        }
        public int getFee()
        {
            return super.Fee=(int) (Value*.05);
        }
    }

Page 1 of 2 12 LastLast

Similar Threads

  1. I'm new and in desperate need of help
    By Bdufty in forum Introductions
    Replies: 4
    Last Post: 04-30-2012, 06:18 AM
  2. Desperate: How do I fix this error?
    By pondwire in forum New To Java
    Replies: 4
    Last Post: 07-19-2011, 08:25 AM
  3. Replies: 1
    Last Post: 01-20-2011, 04:59 PM
  4. help i'm desperate
    By AniMaind in forum New To Java
    Replies: 17
    Last Post: 01-08-2011, 01:05 AM
  5. Desperate for some help if possible :(
    By SBOSlayer in forum New To Java
    Replies: 1
    Last Post: 11-30-2010, 10:44 PM

Posting Permissions

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