Misplaced bracket error in code

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gina777416
    New Member
    • Oct 2007
    • 6

    Misplaced bracket error in code

    I cannot figure out why my main is not identifying my classes, is there a bracket misplaced or something? Here are the errors I am getting

    Code:
    C:\Documents and Settings\Regina Denson\My Documents\JCreator LE\MyProjects\Inventory6.java:37: cannot find symbol
    symbol  : class GUI
    location: class Inventory6
            GUI gui = new GUI(inventory); // Start the GUI
            ^
    C:\Documents and Settings\Regina Denson\My Documents\JCreator LE\MyProjects\Inventory6.java:37: cannot find symbol
    symbol  : class GUI
    location: class Inventory6
            GUI gui = new GUI(inventory); // Start the GUI
                          ^
    C:\Documents and Settings\Regina Denson\My Documents\JCreator LE\MyProjects\Inventory6.java:39: cannot find symbol
    symbol  : class OutputDVD
    location: class Inventory6
            OutputDVD output = new OutputDVD(inventory);
            ^
    C:\Documents and Settings\Regina Denson\My Documents\JCreator LE\MyProjects\Inventory6.java:39: cannot find symbol
    symbol  : class OutputDVD
    location: class Inventory6
            OutputDVD output = new OutputDVD(inventory);
                                   ^
    And Here is my code

    [CODE=java]import java.util.*; // using java libraries

    public class Inventory6 {

    public static void main(String[] args)
    {

    FeatDVD dvd;
    Inventory inventory = new Inventory();

    dvd = new FeatDVD(0, "Hitch", 5, 12.99, "Columbia Pictures");
    inventory.add(d vd);

    dvd = new FeatDVD(1, "Unleashed" , 7, 14.99, "Universal Studios");
    inventory.add(d vd);

    dvd = new FeatDVD(2, "Batman Forever", 6, 13.99, "Warner Bros");
    inventory.add(d vd);

    dvd = new FeatDVD(3, "Taxi", 3, 15.99, "20TH Century Fox");
    inventory.add(d vd);

    dvd = new FeatDVD(4, "Free Willy", 8, 11.99, "Warner Bros");
    inventory.add(d vd);

    dvd = new FeatDVD(5, "Cliffhange r", 2, 12.99, "Columbia Tristar");
    inventory.add(d vd);

    dvd = new FeatDVD(6, "A Christmas Story", 7, 15.99, "Warner Bros");
    inventory.add(d vd);

    dvd = new FeatDVD(7, "Stir of Echos", 7, 11.99, "Artisan");
    inventory.add(d vd);

    inventory.displ ay();
    GUI gui = new GUI(inventory); // Start the GUI

    OutputDVD output = new OutputDVD(inven tory);

    } // end main

    } // end class Inventory6



    /**** Class decribes DVD while demostrating polymorphism and inheritance**/

    class DVD implements Comparable
    {
    private int dvditem;
    private String dvdtitle;
    private int dvdstock;
    private double dvdprice;

    // Constructor
    DVD()
    {
    dvditem = 0;
    dvdtitle = "";
    dvdstock = 0;
    dvdprice = 0;
    }// end constructor

    //constructor initializes variables
    DVD(int item, String title, int stock, double price)
    {
    this.dvditem = item;
    this.dvdtitle = title;
    this.dvdstock = stock;
    this.dvdprice = price;
    }

    private void setTitle( String title )
    {
    this.dvdtitle = title;
    }

    public String getdvdTitle()
    {
    return dvdtitle;
    }

    private void setdvdItem( int item )
    {
    this.dvditem = item;
    }

    public int getdvdItem()
    {
    return dvditem;
    }

    private void setdvdStock( int stock )
    {
    this.dvdstock = stock;
    }

    public int getdvdStock()
    {
    return dvdstock;
    }

    private void setdvdPrice (double price )
    {
    this.dvdprice = price;
    }

    public double getdvdPrice()
    {
    return dvdprice;
    }

    public double getValue()
    {
    double value = dvdstock * dvdprice;
    return value;
    }

    // This method tells the sort method what is to be sorted
    public int compareTo(Objec t o)
    {
    return dvdtitle.compar eTo(((DVD) o).getdvdTitle( ));
    }

    // This method passes the format for the string
    public String toString()
    {
    return String.format(" Unit number:%d %12s Units:%2d Price: $%5.2f Movie value: $%6.2f",
    dvditem, dvdtitle, dvdstock, dvdprice, getValue());
    }
    } // end class DVD


    /**** This is a subclass that adds 5% restocking fee and new feature genres***/

    class FeatDVD extends DVD
    {
    private String genres;

    // class constructor
    FeatDVD(int item, String title, int stock, double price, String genres)
    {
    super(item, title, stock, price);
    this.genres = genres;
    }
    public String getGenres()
    {
    return genres;
    }

    public double getValue()
    {// getvalue method overrides
    // getvalue method in the superclass
    double value = 1.05F * super.getValue( );
    return value;
    }// end getValue method

    public String toString()
    {//toString method overrides the superclass toString method
    //adding another fields
    return super.toString( ) + "Genre:" + genres;
    }// end toString method

    } // end class FeatDVD


    /*****class has inventory of DVDs.
    * This class has methods to add and display dvds****/

    class Inventory
    {
    private DVD[] dvds;
    private int nCount;

    // constructor
    Inventory()
    {
    dvds = new DVD[8];
    nCount = 0;
    }


    public int getNcount()
    {
    return nCount;
    }

    // method adds DVD to inventory
    public void add(DVD dvd)
    {
    dvds[nCount] = dvd;
    ++nCount;
    sort();
    }

    public void delete(int n)
    {
    if (nCount > 0)
    {
    dvds[n] = dvds[nCount-1];
    --nCount;
    sort();
    }
    }
    public int search(String seek)
    {

    int n = -1;
    for (int i = 0; i < nCount; i++) {
    if (seek.equalsIgn oreCase(dvds[i].getdvdTitle()) ) {
    n = i;
    break;

    }
    }
    return n;
    }

    public FeatDVD getFeatDVD(int n)
    {
    return (FeatDVD) dvds[n];
    }
    // method calculates total value of inventory
    public double getTotalValue()
    {

    double totalValue = 0;
    for (int i = 0; i < nCount; i++)
    totalValue = dvds[i].getValue();
    return totalValue;
    } // end getTotalValue

    public DVD getDVD(int n) //use in GUI
    {// protects n and keep in range
    if (n<0)
    n = 0;
    else if (n >= nCount)
    n = nCount - 1;
    return (n >= 0) ? dvds[n] : null;
    }


    // sorts the DVDs
    private void sort()
    {

    if (nCount > 0)
    Arrays.sort(dvd s, 0, nCount);
    }// end sort method

    public void display()
    {
    for (int i = 0; i < nCount; i++)
    System.out.prin tf("%2d: %s\n", i, getFeatDVD(i));
    }


    } // end class Inventory

    Please HELP[/CODE]
    Last edited by Ganon11; Nov 30 '07, 05:29 AM. Reason: Please use the [CODE] tags provided.
  • Creature
    New Member
    • Dec 2006
    • 1

    #2
    Hi, Gina!

    I do not see where you declare the class GUI. If it is in a different package, you will need to import it before using it.

    import packagename.GUI ;

    kind of like you're importing the java.util package contents.

    Comment

    • samido
      New Member
      • Oct 2007
      • 52

      #3
      dude, make sure the class GUI is compiled successfully, this is why you getting this problem, chaww...

      Comment

      • Gina777416
        New Member
        • Oct 2007
        • 6

        #4
        Originally posted by Creature
        Hi, Gina!

        I do not see where you declare the class GUI. If it is in a different package, you will need to import it before using it.

        import packagename.GUI ;

        kind of like you're importing the java.util package contents.

        Thanks so much!! So I add that import line under the first import line?

        Comment

        • Gina777416
          New Member
          • Oct 2007
          • 6

          #5
          Originally posted by Creature
          Hi, Gina!

          I do not see where you declare the class GUI. If it is in a different package, you will need to import it before using it.

          import packagename.GUI ;

          kind of like you're importing the java.util package contents.
          Well now I get these errors
          C:\Program Files\Java\jdk1 .6.0_03\bin\Inv entory6.java:3: package packagename does not exist
          import packagename.GUI ;
          ^
          C:\Program Files\Java\jdk1 .6.0_03\bin\Inv entory6.java:38 : cannot find symbol
          symbol : class GUI
          location: class Inventory6
          GUI gui = new GUI(inventory); // Start the GUI
          ^
          C:\Program Files\Java\jdk1 .6.0_03\bin\Inv entory6.java:38 : cannot find symbol
          symbol : class GUI
          location: class Inventory6
          GUI gui = new GUI(inventory); // Start the GUI
          ^
          C:\Program Files\Java\jdk1 .6.0_03\bin\Inv entory6.java:40 : cannot find symbol
          symbol : class OutputDVD
          location: class Inventory6
          OutputDVD output = new OutputDVD(inven tory);
          ^
          C:\Program Files\Java\jdk1 .6.0_03\bin\Inv entory6.java:40 : cannot find symbol
          symbol : class OutputDVD
          location: class Inventory6
          OutputDVD output = new OutputDVD(inven tory);
          ^

          HMMMMM brain pain

          Comment

          • Gina777416
            New Member
            • Oct 2007
            • 6

            #6
            Originally posted by samido
            dude, make sure the class GUI is compiled successfully, this is why you getting this problem, chaww...
            I am still learning and I don't know how but thanks so much for your reply!!

            Comment

            • Gina777416
              New Member
              • Oct 2007
              • 6

              #7
              Originally posted by Creature
              Hi, Gina!

              I do not see where you declare the class GUI. If it is in a different package, you will need to import it before using it.

              import packagename.GUI ;

              kind of like you're importing the java.util package contents.
              So I tried it a little different and I only get one error
              C:\Program Files\Java\jdk1 .6.0_03\bin\Inv entory6.java:38 : cannot find symbol
              symbol : constructor Inventory(Inven tory)
              location: class Inventory
              Inventory output = new Inventory(inven tory);
              ^

              Here is te code

              import java.util.*; // using java libraries


              public class Inventory6 {

              public static void main(String[] args)
              {

              FeatDVD dvd;
              Inventory inventory = new Inventory();

              dvd = new FeatDVD(0, "Bad Boys", 5, 12.99, "Comedy");
              inventory.add(d vd);

              dvd = new FeatDVD(1, "Color Purple", 7, 14.99, "Drama");
              inventory.add(d vd);

              dvd = new FeatDVD(2, "Madea Family Reunion", 6, 13.99, "Drama");
              inventory.add(d vd);

              dvd = new FeatDVD(3, "Diary of a Mad Black Woman", 3, 15.99, "Drama");
              inventory.add(d vd);

              dvd = new FeatDVD(4, "Forest Gump", 8, 11.99, "Comedy");
              inventory.add(d vd);

              dvd = new FeatDVD(5, "How Stella Got Her Groove Back", 2, 12.99, "Drama");
              inventory.add(d vd);

              dvd = new FeatDVD(6, "What's love Got to do With it", 7, 15.99, "Drama");
              inventory.add(d vd);

              dvd = new FeatDVD(7, "Purple Rain", 7, 11.99, "Drama");
              inventory.add(d vd);


              Inventory output = new Inventory(inven tory);

              } // end main

              } // end class Inventory6



              /**** Class decribes DVD while demostrating polymorphism and inheritance**/

              class DVD implements Comparable
              {
              private int dvditem;
              private String dvdtitle;
              private int dvdstock;
              private double dvdprice;

              // Constructor
              DVD()
              {
              dvditem = 0;
              dvdtitle = "";
              dvdstock = 0;
              dvdprice = 0;
              }// end constructor

              //constructor initializes variables
              DVD(int item, String title, int stock, double price)
              {
              this.dvditem = item;
              this.dvdtitle = title;
              this.dvdstock = stock;
              this.dvdprice = price;
              }

              private void setTitle( String title )
              {
              this.dvdtitle = title;
              }

              public String getdvdTitle()
              {
              return dvdtitle;
              }

              private void setdvdItem( int item )
              {
              this.dvditem = item;
              }

              public int getdvdItem()
              {
              return dvditem;
              }

              private void setdvdStock( int stock )
              {
              this.dvdstock = stock;
              }

              public int getdvdStock()
              {
              return dvdstock;
              }

              private void setdvdPrice (double price )
              {
              this.dvdprice = price;
              }

              public double getdvdPrice()
              {
              return dvdprice;
              }

              public double getValue()
              {
              double value = dvdstock * dvdprice;
              return value;
              }

              // This method tells the sort method what is to be sorted
              public int compareTo(Objec t o)
              {
              return dvdtitle.compar eTo(((DVD) o).getdvdTitle( ));
              }

              // This method passes the format for the string
              public String toString()
              {
              return String.format(" Unit number:%d %12s Units:%2d Price: $%5.2f Movie value: $%6.2f",
              dvditem, dvdtitle, dvdstock, dvdprice, getValue());
              }
              } // end class DVD


              /**** This is a subclass that adds 5% restocking fee and new feature genres***/

              class FeatDVD extends DVD
              {
              private String genres;

              // class constructor
              FeatDVD(int item, String title, int stock, double price, String genres)
              {
              super(item, title, stock, price);
              this.genres = genres;
              }
              public String getGenres()
              {
              return genres;
              }

              public double getValue()
              {// getvalue method overrides
              // getvalue method in the superclass
              double value = 1.05F * super.getValue( );
              return value;
              }// end getValue method

              public String toString()
              {//toString method overrides the superclass toString method
              //adding another fields
              return super.toString( ) + "Genre:" + genres;
              }// end toString method

              } // end class FeatDVD


              /*****class has inventory of DVDs.
              * This class has methods to add and display dvds****/

              class Inventory
              {
              private DVD[] dvds;
              private int nCount;

              // constructor
              Inventory()
              {
              dvds = new DVD[8];
              nCount = 0;
              }


              public int getNcount()
              {
              return nCount;
              }

              // method adds DVD to inventory
              public void add(DVD dvd)
              {
              dvds[nCount] = dvd;
              ++nCount;
              sort();
              }

              public void delete(int n)
              {
              if (nCount > 0)
              {
              dvds[n] = dvds[nCount-1];
              --nCount;
              sort();
              }
              }
              public int search(String seek)
              {

              int n = -1;
              for (int i = 0; i < nCount; i++) {
              if (seek.equalsIgn oreCase(dvds[i].getdvdTitle()) ) {
              n = i;
              break;

              }
              }
              return n;
              }

              public FeatDVD getFeatDVD(int n)
              {
              return (FeatDVD) dvds[n];
              }
              // method calculates total value of inventory
              public double getTotalValue()
              {

              double totalValue = 0;
              for (int i = 0; i < nCount; i++)
              totalValue = dvds[i].getValue();
              return totalValue;
              } // end getTotalValue

              public DVD getDVD(int n) //use in GUI
              {// protects n and keep in range
              if (n<0)
              n = 0;
              else if (n >= nCount)
              n = nCount - 1;
              return (n >= 0) ? dvds[n] : null;
              }


              // sorts the DVDs
              private void sort()
              {

              if (nCount > 0)
              Arrays.sort(dvd s, 0, nCount);
              }// end sort method

              public void display()
              {
              for (int i = 0; i < nCount; i++)
              System.out.prin tf("%2d: %s\n", i, getFeatDVD(i));
              }


              } // end class Inventory

              Comment

              • Laharl
                Recognized Expert Contributor
                • Sep 2007
                • 849

                #8
                The compiler is complaining because you have no constructor written for the Inventory class that takes an Inventory parameter, which I would assume is a copy constructor, which would assign the member values of the input Inventory to the newly constructed Inventory object.

                Eg:
                [CODE=java]
                public class Foo {
                private int a;
                public Foo(Foo other){//Takes a parameter of a Foo object
                a = other.a; //Assigns a to the input object's a value
                }
                ...
                }
                [/CODE]

                Comment

                • Gina777416
                  New Member
                  • Oct 2007
                  • 6

                  #9
                  Originally posted by Laharl
                  The compiler is complaining because you have no constructor written for the Inventory class that takes an Inventory parameter, which I would assume is a copy constructor, which would assign the member values of the input Inventory to the newly constructed Inventory object.

                  Eg:
                  [CODE=java]
                  public class Foo {
                  private int a;
                  public Foo(Foo other){//Takes a parameter of a Foo object
                  a = other.a; //Assigns a to the input object's a value
                  }
                  ...
                  }
                  [/CODE]
                  I am so new at this I guess I just don't understand the whole "Foo" thing. But thank you so much for your reply

                  Comment

                  • Laharl
                    Recognized Expert Contributor
                    • Sep 2007
                    • 849

                    #10
                    The Foo class was an example to give you an idea of what this needs to look like. The type of constructor I mentioned is called a "copy constructor" because it makes the new object a copy of the old one.

                    Comment

                    Working...