Results 1 to 8 of 8
  1. #1
    booter4429 is offline Member
    Join Date
    Jul 2008
    Posts
    20
    Rep Power
    0

    Post Can someone tell me what I did wrong??

    Java Code:
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    package javaapplication50;
    
    /**
     *
     * @author A
     */
    public class Main {
    
        /**
         * @param args the command line arguments
         */
      
            // TODO code application logic here
       public class inventorysupplystock implements Comparable{
             protected  int count;
             protected  int quantity;
             protected  String productName;
             protected  String productGenre;
             protected  double itemNumber;
             protected  double quantityNumber;
             protected  double unitPrice;
             protected  double unitValue;
             protected  double restockingFee;
     
            public inventorysupplystock() {
     
        }
     
        public int compareTo(Object o) {
        return productName.compareTo(((inventorysupplystock) o).getName());
        }
     
        public void displayItems(){
            System.out.printf( "%-2s           %-2s          %-2s         %-2s        %.2f        %.2f       %.2f\n",
                    itemNumber, productGenre, productName,
                    quantityNumber, unitPrice, unitValue, restockingFee);
        }
        
        public void setValue(double value){
            unitValue = value;
     
        }
     
        public double getValue(){
     
              return unitValue;
        }
     
     public void setRestockingFee(double restockingfee)
         {
        restockingFee = (restockingfee * 1.05);
         } 
     
         
         public double getRestockingFee()
         {
        return restockingFee;
         } 
     
         
         public double total()
         {
        return restockingFee * 1.05;
         } 
     
        public void setCount( int a ){
            count = a;
        }
     
     
        
        public void setName( String name ) {
     
            productName = name;
        }
        public String getName() {
     
            return productName;
           }
           
        public void setGenre( String genre ) {
     
            productGenre = genre;
        }
        public String getGenre() {
     
            return productGenre;
           }
     
        
        public void setNumber( double number ) {
     
            itemNumber = number;
        }
        public double getNumber() {
     
            return itemNumber;
        }
        
        public void setquantity( double quantity ) {
     
            quantityNumber = quantity;
        }
        public double getquantity() {
     
            return quantityNumber;
        }
        
        public void setPrice( double price ) {
     
            unitPrice = price;
        }
        public double getPrice(){
     
            return unitPrice;
        }
        
       }
    }
    *******************************************************
    package javaapplication50;
    
    
    /**
     *
     * @author A
     */
    
            
    import java.util.Scanner;
    import javaapplication50.Main.inventorysupplystock;
     
    public class Main2 { 
     
     
        public static void main(String[] args) { 
     
            Scanner input = new Scanner( System.in );
            int c;
            System.out.printf( "\n\nHow many new movies do you want to enter? ");
            c = input.nextInt();
            input.nextLine();
            inventorysupplystock[] supply = new inventorysupplystock[c];
     
     
            String name;              
            String genre;             
            double number;            
            double quantity;          
            double fee;
            double price;             
            double value = 0;         
            double totalValue = 0;    
            double restockingFee = 0; 
            int a = 0;
            int b = 0;
            while (a < c){ 
     
                supply[a] = new inventorysupplystock();
                supply[b] = new inventorysupplystock();
     
                System.out.printf( "What is the name of the movie being entered: ");
                name = input.nextLine();
                supply[a].setName(name);
     
                System.out.printf( "What is the genre of the movie being entered: ");
                genre = input.nextLine();
                supply[b].setGenre(genre);
     
                System.out.printf( "What will be this movie's item number: ");
                number = input.nextDouble();
                input.nextLine();
                supply[a].setNumber(number);
     
                System.out.printf( "How many are you entering into stock: ");
                quantity = input.nextDouble();
                input.nextLine();
                supply[a].setquantity(quantity);
     
                System.out.printf( "How much did this movie cost: ");
                price = input.nextDouble();
                input.nextLine();
                supply[a].setPrice(price);
     
                System.out.printf( "How much is the restocking fee: ");
                fee = input.nextDouble();
                input.nextLine();
     
     
                value = supply[a].getquantity() * supply[a].getPrice();
     
                supply[a].setValue(value);
     
                supply[a].setCount(a);
                
                a++;
     
            } 
     
            java.util.Arrays.sort(supply); 
            System.out.printf( "Item number  Genre   Name   Quantity  Price  Value restockingFee\n");
     
            a = 0;
            while (a < c){ 
            supply[a].displayItems();
     
            totalValue += supply[a].getValue();
     
            a++;
            }
     
     
     
            // total value
            System.out.printf( "The total value of the inventory is: %.2f", totalValue );
        } // end of program
     
    } // end of class


    Created dir: C:\Users\A\Documents\NetBeansProjects\JavaApplicat ion Week 6B\build\classes
    Compiling 2 source files to C:\Users\A\Documents\NetBeansProjects\JavaApplicat ion Week 6B\build\classes
    C:\Users\A\Documents\NetBeansProjects\JavaApplicat ion Week 6B\src\javaapplication50\Main2.java:44: an enclosing instance that contains javaapplication50.Main.inventorysupplystock is required
    supply[a] = new inventorysupplystock();
    C:\Users\A\Documents\NetBeansProjects\JavaApplicat ion Week 6B\src\javaapplication50\Main2.java:45: an enclosing instance that contains javaapplication50.Main.inventorysupplystock is required
    supply[b] = new inventorysupplystock();
    2 errors
    BUILD FAILED (total time: 1 second)


    I'm getting 2 errors and I don't know how to fix them....

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,306
    Rep Power
    25

    Default

    public class Main {

    /**
    * @param args the command line arguments
    */

    // TODO code application logic here
    public class inventorysupplystock implements Comparable{
    Make the inventorysupplystock, etc an external class, not an internal to the Main class.

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    More specifically something like this.

    Java Code:
    public class Main {
         /**
         * @param args the command line arguments
         */
    }
    
    class inventorysupplystock implements Comparable { 
         // Class body goes here
    }
    Note that carefully how the access modifiers are change, this is because working on a single *.java file.

  4. #4
    booter4429 is offline Member
    Join Date
    Jul 2008
    Posts
    20
    Rep Power
    0

    Default

    I'm getting the same 2 errors.

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

    Default

    If you've changed your code, we need to see it with the FULL text of the error messages.

    Your original code had classes inside of classes. When something is inside of a class it is hidden to another class that is outside.
    Make all your classes be peers. Don't put any inside of others.
    Later you'll learn how to do that, but for now put them all outside of each other.
    Only ONE of the classes will be public and that one will have the same name as the source file.

  6. #6
    booter4429 is offline Member
    Join Date
    Jul 2008
    Posts
    20
    Rep Power
    0

    Default

    Java Code:
    package javaapplication50;
    
    /**
     *
     * @author A
     */
    public class Main {
    
        /**
         * @param args the command line arguments
         */
      
            // TODO code application logic here
      class inventorysupplystock implements Comparable {
             protected  int count;
             protected  int quantity;
             protected  String productName;
             protected  String productGenre;
             protected  double itemNumber;
             protected  double quantityNumber;
             protected  double unitPrice;
             protected  double unitValue;
             protected  double restockingFee;
     
            public inventorysupplystock() {
     
        }
     
        public int compareTo(Object o) {
        return productName.compareTo(((inventorysupplystock) o).getName());
        }
     
        public void displayItems(){
            System.out.printf( "%-2s           %-2s          %-2s         %-2s        %.2f        %.2f       %.2f\n",
                    itemNumber, productGenre, productName,
                    quantityNumber, unitPrice, unitValue, restockingFee);
        }
        
        public void setValue(double value){
            unitValue = value;
     
        }
     
        public double getValue(){
     
              return unitValue;
        }
     
     public void setRestockingFee(double restockingfee)
         {
        restockingFee = (restockingfee * 1.05);
         } 
     
         
         public double getRestockingFee()
         {
        return restockingFee;
         } 
     
         
         public double total()
         {
        return restockingFee * 1.05;
         } 
     
        public void setCount( int a ){
            count = a;
        }
     
     
        
        public void setName( String name ) {
     
            productName = name;
        }
        public String getName() {
     
            return productName;
           }
           
        public void setGenre( String genre ) {
     
            productGenre = genre;
        }
        public String getGenre() {
     
            return productGenre;
           }
     
        
        public void setNumber( double number ) {
     
            itemNumber = number;
        }
        public double getNumber() {
     
            return itemNumber;
        }
        
        public void setquantity( double quantity ) {
     
            quantityNumber = quantity;
        }
        public double getquantity() {
     
            return quantityNumber;
        }
        
        public void setPrice( double price ) {
     
            unitPrice = price;
        }
        public double getPrice(){
     
            return unitPrice;
        }
        
       }
    }
    **********************************
    package javaapplication50;
    
    
    /**
     *
     * @author A
     */
    
            
    import java.util.Scanner;
    import javaapplication50.Main.inventorysupplystock;
     
    public class Main2 { 
     
     
        public static void main(String[] args) { 
     
            Scanner input = new Scanner( System.in );
            int c;
            System.out.printf( "\n\nHow many new movies do you want to enter? ");
            c = input.nextInt();
            input.nextLine();
            inventorysupplystock[] supply = new inventorysupplystock[c];
     
     
            String name;              
            String genre;             
            double number;            
            double quantity;          
            double fee;
            double price;             
            double value = 0;         
            double totalValue = 0;    
            double restockingFee = 0; 
            int a = 0;
            int b = 0;
            while (a < c){ 
     
                supply[a] = new inventorysupplystock();
                supply[b] = new inventorysupplystock();
     
                System.out.printf( "What is the name of the movie being entered: ");
                name = input.nextLine();
                supply[a].setName(name);
     
                System.out.printf( "What is the genre of the movie being entered: ");
                genre = input.nextLine();
                supply[b].setGenre(genre);
     
                System.out.printf( "What will be this movie's item number: ");
                number = input.nextDouble();
                input.nextLine();
                supply[a].setNumber(number);
     
                System.out.printf( "How many are you entering into stock: ");
                quantity = input.nextDouble();
                input.nextLine();
                supply[a].setquantity(quantity);
     
                System.out.printf( "How much did this movie cost: ");
                price = input.nextDouble();
                input.nextLine();
                supply[a].setPrice(price);
     
                System.out.printf( "How much is the restocking fee: ");
                fee = input.nextDouble();
                input.nextLine();
     
     
                value = supply[a].getquantity() * supply[a].getPrice();
     
                supply[a].setValue(value);
     
                supply[a].setCount(a);
                
                a++;
     
            } 
     
            java.util.Arrays.sort(supply); 
            System.out.printf( "Item number  Genre   Name   Quantity  Price  Value restockingFee\n");
     
            a = 0;
            while (a < c){ 
            supply[a].displayItems();
     
            totalValue += supply[a].getValue();
     
            a++;
            }
     
     
     
            // total value
            System.out.printf( "The total value of the inventory is: %.2f", totalValue );
        } // end of program
     
    } // end of class

    init:
    deps-jar:
    Compiling 2 source files to C:\Users\A\Documents\NetBeansProjects\JavaApplicat ion Week 6B\build\classes
    C:\Users\A\Documents\NetBeansProjects\JavaApplicat ion Week 6B\src\javaapplication50\Main2.java:44: an enclosing instance that contains javaapplication50.Main.inventorysupplystock is required
    supply[a] = new inventorysupplystock();
    C:\Users\A\Documents\NetBeansProjects\JavaApplicat ion Week 6B\src\javaapplication50\Main2.java:45: an enclosing instance that contains javaapplication50.Main.inventorysupplystock is required
    supply[b] = new inventorysupplystock();
    2 errors
    BUILD FAILED (total time: 0 seconds)

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

    Default

    Make all your classes be peers. Don't put any inside of others.
    Later you'll learn how to do that, but for now put them all outside of each other.
    Only ONE of the classes will be public and that one will have the same name as the source file.
    You have class inventorysupplystock
    inside of class Main

    You need to move it outside:
    public class Main {
    ....
    } // end of Main
    // Next class definition follows:
    class inventorysupplystock {
    ...
    } // end class inventorysupplystock

    And the same for all your classes

  8. #8
    booter4429 is offline Member
    Join Date
    Jul 2008
    Posts
    20
    Rep Power
    0

Similar Threads

  1. What's wrong with my codes?
    By ayoood in forum New To Java
    Replies: 16
    Last Post: 09-01-2008, 03:57 AM
  2. Replies: 2
    Last Post: 07-11-2008, 09:41 AM
  3. what is wrong with this program ?
    By Poor Bee in forum New To Java
    Replies: 1
    Last Post: 05-07-2008, 07:23 PM
  4. wrong values
    By mark-mlt in forum New To Java
    Replies: 8
    Last Post: 04-25-2008, 11:11 AM
  5. I am Doing Something Wrong But Don't Know What?
    By BHCluster in forum New To Java
    Replies: 3
    Last Post: 04-16-2008, 01:16 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
  •