Page 2 of 2 FirstFirst 12
Results 21 to 30 of 30
Like Tree2Likes

Thread: Desperate, Can not figure it out!

  1. #21
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,816
    Rep Power
    25

    Default Re: Desperate, Can not figure it out!

    Where is the statement with the error? Could you put a comment on it and then describe the comment in the text so it is easy to find? For example: // HERE IS THE ERROR

    Is the statement with the error 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.
    Mshelly likes this.
    If you don't understand my response, don't ignore it, ask a question.

  2. #22
    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 fixed my indents and {} and added the //ERROR HERE

    Hope this helps:

    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); //ERROR HERE CANNOT FIND SYMBOL
    System.out.println("The Genre: "+Genre.MovieGenre()+"Has a restock fee:"+Genre.super.Fee());//ERROR HERE CAN NOT FIND SYMBOL
    }//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;//ERROR HERE NON STATIC VARIABLE CANNOT REFERENCED FROM STATIC
            Genre.Fee=0;//ERROR HERE SAME
        }
        public void setMovieGenre(String genre)
        {
            Genre.MovieGenre=genre;//ERROR HERE SAME
        }
        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);
        }
    }
    If you have a suggestion on better formatting please let me know I am always up for suggestions to improve.
    Last edited by Mshelly; 07-11-2014 at 05:19 PM.

  3. #23
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,031
    Rep Power
    4

    Default Re: Desperate, Can not figure it out!

    If you remove static from the variables in Genre, you should also make the references at line 17 and 18 non-static. Genre.MovieGenre and Genre.Fee are references to static variables, which you made non-static. Use the keyword "this" instead: this.MovieGenre and this.Fee.

    While you're editing, variables and methods always start with a lowercase letter, classes with an uppercase one.

    Also, study the static-documentation link I posted a few posts ago. It appears that you have issues with understanding static.
    Mshelly likes this.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  4. #24
    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
    If you remove static from the variables in Genre, you should also make the references at line 17 and 18 non-static. Genre.MovieGenre and Genre.Fee are references to static variables, which you made non-static. Use the keyword "this" instead: this.MovieGenre and this.Fee.

    While you're editing, variables and methods always start with a lowercase letter, classes with an uppercase one.

    Also, study the static-documentation link I posted a few posts ago. It appears that you have issues with understanding static.
    I am reading that now. The teacher posted the main program as an example. He had everything as static, and when I wrote my own, and made it not as static nothing works with the calculate and print. So I figured it all needed to be static since that was how he did it.

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

    Default Re: Desperate, Can not figure it out!

    So I made some changes and now the errors are not so bad, but still doesn't work. Nothing from the subclass prints. I added the constructor to line 33 and print 34.
    I then added print to string in the subclass.


    No errors in here now:
    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;
            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);
    Genre g =new Genre ("Horror", 0);
    System.out.println("The Genre: "+g.getMovieGenre()+"Has a restock fee:"+g.getFee());
    }//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


    Errors here:
    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(MovieGenre, Fee);//ERROR HERE "CONSTRUCTOR PRODUCT IN CLASS PRODUCTS CANNOT BE APPLIED TO GIVE TYPES REQUIRED STRING INT INT INT STRING FOUND STING INT
            this.MovieGenre=genre;
            this.Fee=0;
        }
    
        Genre(String horror, int i) //ERROR HERE SAME AS ABOVE
        {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
        public void setMovieGenre(String genre)
        {
            this.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);
        }
        @Override
        public String toString()
        {
            return String.format("Genre:" + getMovieGenre()+"Has a Restock Fee: "+getFee());
        }
    }

    OUTPUT:
    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
    Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: inventoryprogram3.Product.<init>
    Name: Star Wars, UPC: 567890, QTY: 5, Price: $30 DVD Value: $150Genre: Scifi at inventoryprogram3.Genre.<init>(Genre.java:21)
    at inventoryprogram3.Inventoryprogram3.main(Inventory program3.java:33)

    Java Result: 1
    BUILD SUCCESSFUL (total time: 1 second)
    Last edited by Mshelly; 07-11-2014 at 06:37 PM.

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

    Default Re: Desperate, Can not figure it out!

    YEAH!!!! I got it. Thank you for all your help and letting me talk it out!! What do you think?


    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;
            DVD[0] = new Product("Dawn of the Dead", 123456, 10, 10,"Horror");
            DVD[1] = new Product("Walking Dead S1", 234567, 10, 20,"TV");
            DVD[2] = new Product("Tinkerbell", 345678, 10, 12,"Kids");
            DVD[3] = new Product("My Sisters Keeper", 456789, 10, 15,"Drama");
            DVD[4] = new Product("Star Wars", 567890, 5, 30,"Scifi");
            Calculate(DVD);
            print(DVD);
            sort(DVD);
    Genre g;
        g = new Genre ("Dawn of the Dead", 123456, 10, 10,"Horror");
    System.out.println("\nGenre: "+g.getMovieGenre()+" Has a restock fee:"+g.getFee());
    
        g = new Genre ("Walking Dead S1", 234567, 10, 20,"TV");
    System.out.println("\nGenre: "+g.getMovieGenre()+" Has a restock fee:"+g.getFee());
    
        g = new Genre ("Tinkerbell", 345678, 10, 12,"Kids");
    System.out.println("\nGenre: "+g.getMovieGenre()+" Has a restock fee:"+g.getFee());
    
        g = new Genre ("My Sisters Keeper", 456789, 10, 15,"Drama");
    System.out.println("\nGenre: "+g.getMovieGenre()+" Has a restock fee:"+g.getFee()); 
    
        g = new Genre ("Star Wars", 567890, 5, 30,"Scifi");
    System.out.println("\nGenre: "+g.getMovieGenre()+" Has a restock fee:"+g.getFee()); 
    }//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:
    /*
     * 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);
            this.MovieGenre=genre;
            this.Fee=0;
        }
        
        public void setMovieGenre(String genre)
        {
            this.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);
        }
        @Override
        public String toString()
        {
            return String.format("Genre:" + getMovieGenre()+"Has a Restock Fee: "+getFee());
        }
    }
    Output:
    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: TV
    Name: Tinkerbell, UPC: 345678, QTY: 10, Price: $12 DVD Value: $120Genre: Kids
    Name: My Sisters Keeper, UPC: 456789, QTY: 10, Price: $15 DVD Value: $150Genre: Drama
    Name: Star Wars, UPC: 567890, QTY: 5, Price: $30 DVD Value: $150Genre: Scifi
    Genre: Horror Has a restock fee:5

    Genre: TV Has a restock fee:10

    Genre: Kids Has a restock fee:6

    Genre: Drama Has a restock fee:7

    Genre: Scifi Has a restock fee:7
    BUILD SUCCESSFUL (total time: 0 seconds)

  7. #27
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,031
    Rep Power
    4

    Default Re: Desperate, Can not figure it out!

    Congratulations!! I'm am thrilled to see you got it working. I hope you understood all the problems you encountered. For example, the constructor that should match the one of the super class. These exercises tend to learn you a lot of things. Make sure you understand what happens when you "fix" things, i.e. remove the keyword "static". (See my signature)

    Again, well done. Please come back when you're stuck (or even to help others ;)).

    Next!
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

  8. #28
    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 definitely learned a lot through this issue. That is what I want. I want to learn. I love this, I think its fun, even when I have problems. I can spend hours on it and it feels like minutes. I am know I will be back.

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

    Default Re: Desperate, Can not figure it out!

    I found some issues in compilation.
    No method with name MovieGenere if it is typo error,another issue is its a instance method.But ,you are calling with class name why?

    You have to streamline so many things in your code.First put down what you want to do and start writing the code.
    Ramya:cool:

  10. #30
    SurfMan's Avatar
    SurfMan is offline Godlike
    Join Date
    Nov 2012
    Location
    The Netherlands
    Posts
    1,031
    Rep Power
    4

    Default Re: Desperate, Can not figure it out!

    Quote Originally Posted by RamyaSivakanth View Post
    I found some issues in compilation.
    No method with name MovieGenere if it is typo error,another issue is its a instance method.But ,you are calling with class name why?
    You are probably looking at old code. She already solved it. Check the code above.

    Quote Originally Posted by RamyaSivakanth View Post
    You have to streamline so many things in your code.First put down what you want to do and start writing the code.
    Unless you give some practical advice, this comment is useless.
    "It's not fixed until you stop calling the problem weird and you understand what was wrong." - gimbal2 2013

Page 2 of 2 FirstFirst 12

Similar Threads

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