Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 8 of 8

Thread: I am having a hard time fixing this error

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I am having a hard time fixing this error

    This assignment is due in about an hour or so and I cannot restructure everything. I worked so hard on this and cannot figure out how in the world to fix this error. The error code isesktop\Inventory Program\Printer.java:28: not a statement
    Colorink;showInventory();

    My code is as follows
    import java.util.Scanner;
    import java.util.Arrays;
     
    public class Printer
    {
     
         // main method begins program execution
         public static void main(String args[] )
         {
              // create Scanner to obtain input from command window
              Scanner input = new Scanner( System.in );
     
              // display a welcome message to the Printer user
              System.out.println( "Welcome to Printer R Us" );
     
              // printer supplies
     
              supplies[] supplies = new supplies[10]; // an array of 10 supplies
     
              supllies printer = new supplies( 20, "Black ink", 60, 19.99);
              supplies printer = new supplies( 10, "Color ink", 75, 29.99);
              supplies printer = new supplies( 30, "Epson", 30, 40.00 );
              supplies printer = new supplies( 10, "Hewlitt packard", 15, 90.00 );
              supplies printer = new supplies( 40, "Polaroid", 45, 120.00 );
     
     
              Blackink.showInventory();
              Colorink;showInventory();
              Epson.showInventory();
              Hewlitt packard;showInventory();
              Polaroid.showInventory();
     
              // sort supplies by name
              for ( int i = 0; i < args.length; i++ )
              System.out.println( args[i] + ", " );
     
              double array[] = { 1,199.40, 2,249.25, 1,200.00, 1,350.00, 5,400.00 };
              double total = 0;
     
              // add each element's value to total
              for ( int counter = 0; counter < array.length; counter++)
                   total += array[ counter ];
              System.out.printf( "\nTotal inventory value is: $%.2f\n", total );
     
              System.out.println( "\nThank you for using Printer R Us!\n" );
     
         } // end method main
     
    } // end class Printer
     
    // Printer Supplies
    class supplies
    {
         public int suppliesNumber;
         public String suppliesName = new String();
         public int suppliesUnits;
         public double suppliesPrice;
     
         // set supplies number
         public void setSuppliesNumber( int number )
         {
              this.suppliesNumber = number;
         } // end method set supplies number
     
         // return supplies number
         public int getSuppliesNumber()
         {
              return suppliesNumber;
         } // end method get supplies number
     
         // set supplies name
         public void setSuppliesName( String name )
         {
              this.suppliesName = name;
         } // end method set supplies name
     
         // return supplies name
         public String getSuppliesName()
         {
              return suppliesName;
         } // end method get supplies name
     
         // set supplies in stock
         public void setSuppliesUnits( int units )
         {
              this.suppliesUnits = units;
         } // end method set supplies units
     
         // return supplies units
         public int getSuppliesUnits()
         {
              return suppliesUnits;
         } // end method get supplies units
     
         // set supplies price
         public void setSuppliesPrice( double price )
         {
              this.suppliesPrice = price;
         } // end method set supplies price
     
         // return supplies price
         public double getSuppliesPrice()
         {
              return suppliesPrice;
         } // end method get supplies price
     
         // calculate supplies inventory value
         public double getValue()
         {
              return suppliesUnits * suppliesPrice;
         } // end method supplies inventory value
     
        // four-argument constructor
         supplies( int number, String name, int units, double price )
         {
              suppliesNumber = number;
              suppliesName = name;
              suppliesUnits = units;
              suppliesPrice = price;
         } // end four-argument constructor
     
        // display inventory
         public void showInventory()
         {
              System.out.println(); // outputs blank line
     
              System.out.println( "Product Number:  "+suppliesNumber );
              System.out.println( "Product Name:  "+suppliesName );
              System.out.println( "Units in Stock:  "+suppliesUnits );
              System.out.printf( "Unit Price:  $%.2f", suppliesPrice );
     
              manufacturer supplies = new manufacturer
                   ( 20, "Black ink", 60, 19.99, "HP" );
     
              System.out.println( "\nManufacturer:  "+supplies.getManufacturer() );
     
              // value() method and display the value
              System.out.printf( "\nInventory value of "+suppliesName+ " is = $%.2f\n",
                   getValue() );
     
        } // end display inventory
     
    } // end class supplies
     
    class manufacturer extends supplies
    {
         // holds the supplies manufacturer
         private String suppliesManufacturer;
     
         // five-argument constructor
         manufacturer( int number, String name, int units,
              double price, String manufacturer )
         {
              super( number, name, units, price );
              suppliesManufacturer = manufacturer;
         } // end five-argument constructor
     
         // set supplies manufacturer
         public void setManufacturer( String manufacturer )
         {
              this.suppliesManufacturer = manufacturer;
         } // end method set supplies manufacturer
     
         // return supplies manufacturer
         public String getManufacturer()
         {
             return suppliesManufacturer;
         } // end method get supplies manufacturer
     
         // add 5% restocking fee
         public double getValue()
         {
              return super.getValue() * 1.05;
         } // end method return supplies manufacturer
     
         // calculate restocking fee
         public double getRestockingFee()
         {
              return super.getValue() * .05;
         } //end method calculate restocking fee
     
         //return String representation of suppliesManufacturer
         public String toString()
         {
              String formatString = "Manufacturer:  %s";
              formatString += "Restocking Fee:  $%.2f";
              formatString = String.format( formatString, suppliesManufacturer,
                   super.getValue() * 0.05 );
              return( formatString + super.toString() );
         } // end toString()
     
         // display inventory
         public void showInventory()
         {
              super.showInventory();
              System.out.println( toString() );
     
              // Display value plus restocking fee
              System.out.printf( "\nInventory value of "+suppliesName+ " is = $%.2f\n",
                   getRestockingFee() );
     
         } // end method display inventory
     
    } // end class manufacturer


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: I am having a hard time fixing this error

    Colorink;showInventory();
    In all the examples on the web and in text books have you ever seen code written with that notation? I sure haven't. What exactly is the semicolon after Colorink supposed to do?
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Aug 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I am having a hard time fixing this error

    I'm not sure, but there are semi-colons in other places and there are no problems. The place that there is a problem is in that one spot.

  4. #4
    Junior Member
    Join Date
    Aug 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I am having a hard time fixing this error

    If I change it all it does is create 7 new errors in the code

  5. #5
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: I am having a hard time fixing this error

    Quote Originally Posted by KuruptingYou View Post
    there are semi-colons in other places and there are no problems.
    Semicolons are used to designate the end of a statement. The "other places" are fine if it is the end of a statement. Whereas your code doesn't make sense. What are you trying to do?
    Blackink.showInventory();
    Colorink;showInventory();
    Compare those 2 lines. The second has an error but the first is ok. Why?
    Improving the world one idiot at a time!

  6. #6
    Junior Member
    Join Date
    Aug 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I am having a hard time fixing this error

    Like I said if I put the . instead of the ; it creates 7 new errors

  7. #7
    Junior Member
    Join Date
    Aug 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I am having a hard time fixing this error

    I am going to change it and show the new errors I get the new errors areesktop\Inventory Program\Printer.java:20: cannot find symbol
    symbol : class supllies
    location: class Printer
    supllies printer = new supplies( 20, "Black ink", 60, 19.99);
    ^
    C:\Users\Colby and Erin\Desktop\Inventory Program\Printer.java:27: cannot find symbol
    symbol : variable Blackink
    location: class Printer
    Blackink.showInventory();
    ^
    C:\Users\Colby and Erin\Desktop\Inventory Program\Printer.java:28: cannot find symbol
    symbol : variable Colorink
    location: class Printer
    Colorink.showInventory();
    ^
    C:\Users\Colby and Erin\Desktop\Inventory Program\Printer.java:29: cannot find symbol
    symbol : variable Epson
    location: class Printer
    Epson.showInventory();
    ^
    C:\Users\Colby and Erin\Desktop\Inventory Program\Printer.java:30: cannot find symbol
    symbol : class Hewlitt
    location: class Printer
    Hewlitt packard;showInventory();
    ^
    C:\Users\Colby and Erin\Desktop\Inventory Program\Printer.java:30: cannot find symbol
    symbol : method showInventory()
    location: class Printer
    Hewlitt packard;showInventory();
    ^
    C:\Users\Colby and Erin\Desktop\Inventory Program\Printer.java:31: cannot find symbol
    symbol : variable Polaroid
    location: class Printer
    Polaroid.showInventory();
    ^
    7 errors and the new code is:
    import java.util.Scanner;
    import java.util.Arrays;
     
    public class Printer
    {
     
         // main method begins program execution
         public static void main(String args[] )
         {
              // create Scanner to obtain input from command window
              Scanner input = new Scanner( System.in );
     
              // display a welcome message to the Printer user
              System.out.println( "Welcome to Printer R Us" );
     
              // printer supplies
     
              supplies[] supplies = new supplies[10]; // an array of 10 supplies
     
              supllies printer = new supplies( 20, "Black ink", 60, 19.99);
              supplies printer = new supplies( 10, "Color ink", 75, 29.99);
              supplies printer = new supplies( 30, "Epson", 30, 40.00 );
              supplies printer = new supplies( 50, "Hewlitt packard", 15, 90.00 );
              supplies printer = new supplies( 40, "Polaroid", 45, 120.00 );
     
     
              Blackink.showInventory();
              Colorink.showInventory();
              Epson.showInventory();
              Hewlitt packard;showInventory();
              Polaroid.showInventory();
     
              // sort supplies by name
              for ( int i = 0; i < args.length; i++ )
              System.out.println( args[i] + ", " );
     
              double array[] = { 1,199.40, 2,249.25, 1,200.00, 1,350.00, 5,400.00 };
              double total = 0;
     
              // add each element's value to total
              for ( int counter = 0; counter < array.length; counter++)
                   total += array[ counter ];
              System.out.printf( "\nTotal inventory value is: $%.2f\n", total );
     
              System.out.println( "\nThank you for using Printer R Us!\n" );
     
         } // end method main
     
    } // end class Printer
     
    // Printer Supplies
    class supplies
    {
         public int suppliesNumber;
         public String suppliesName = new String();
         public int suppliesUnits;
         public double suppliesPrice;
     
         // set supplies number
         public void setSuppliesNumber( int number )
         {
              this.suppliesNumber = number;
         } // end method set supplies number
     
         // return supplies number
         public int getSuppliesNumber()
         {
              return suppliesNumber;
         } // end method get supplies number
     
         // set supplies name
         public void setSuppliesName( String name )
         {
              this.suppliesName = name;
         } // end method set supplies name
     
         // return supplies name
         public String getSuppliesName()
         {
              return suppliesName;
         } // end method get supplies name
     
         // set supplies in stock
         public void setSuppliesUnits( int units )
         {
              this.suppliesUnits = units;
         } // end method set supplies units
     
         // return supplies units
         public int getSuppliesUnits()
         {
              return suppliesUnits;
         } // end method get supplies units
     
         // set supplies price
         public void setSuppliesPrice( double price )
         {
              this.suppliesPrice = price;
         } // end method set supplies price
     
         // return supplies price
         public double getSuppliesPrice()
         {
              return suppliesPrice;
         } // end method get supplies price
     
         // calculate supplies inventory value
         public double getValue()
         {
              return suppliesUnits * suppliesPrice;
         } // end method supplies inventory value
     
        // four-argument constructor
         supplies( int number, String name, int units, double price )
         {
              suppliesNumber = number;
              suppliesName = name;
              suppliesUnits = units;
              suppliesPrice = price;
         } // end four-argument constructor
     
        // display inventory
         public void showInventory()
         {
              System.out.println(); // outputs blank line
     
              System.out.println( "Product Number:  "+suppliesNumber );
              System.out.println( "Product Name:  "+suppliesName );
              System.out.println( "Units in Stock:  "+suppliesUnits );
              System.out.printf( "Unit Price:  $%.2f", suppliesPrice );
     
              manufacturer supplies = new manufacturer
                   ( 20, "Black ink", 60, 19.99, "HP" );
     
              System.out.println( "\nManufacturer:  "+supplies.getManufacturer() );
     
              // value() method and display the value
              System.out.printf( "\nInventory value of "+suppliesName+ " is = $%.2f\n",
                   getValue() );
     
        } // end display inventory
     
    } // end class supplies
     
    class manufacturer extends supplies
    {
         // holds the supplies manufacturer
         private String suppliesManufacturer;
     
         // five-argument constructor
         manufacturer( int number, String name, int units,
              double price, String manufacturer )
         {
              super( number, name, units, price );
              suppliesManufacturer = manufacturer;
         } // end five-argument constructor
     
         // set supplies manufacturer
         public void setManufacturer( String manufacturer )
         {
              this.suppliesManufacturer = manufacturer;
         } // end method set supplies manufacturer
     
         // return supplies manufacturer
         public String getManufacturer()
         {
             return suppliesManufacturer;
         } // end method get supplies manufacturer
     
         // add 5% restocking fee
         public double getValue()
         {
              return super.getValue() * 1.05;
         } // end method return supplies manufacturer
     
         // calculate restocking fee
         public double getRestockingFee()
         {
              return super.getValue() * .05;
         } //end method calculate restocking fee
     
         //return String representation of suppliesManufacturer
         public String toString()
         {
              String formatString = "Manufacturer:  %s";
              formatString += "Restocking Fee:  $%.2f";
              formatString = String.format( formatString, suppliesManufacturer,
                   super.getValue() * 0.05 );
              return( formatString + super.toString() );
         } // end toString()
     
         // display inventory
         public void showInventory()
         {
              super.showInventory();
              System.out.println( toString() );
     
              // Display value plus restocking fee
              System.out.printf( "\nInventory value of "+suppliesName+ " is = $%.2f\n",
                   getRestockingFee() );
     
         } // end method display inventory
     
    } // end class manufacturer

  8. #8
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: I am having a hard time fixing this error

    Just because you changed something and it generated more errors does not mean that the change was wrong. All those errors you see were already in your code, it was just that the previous error was so wrong that the compiler basically gave up as it didn't know how to continue. Now you have removed the really bad error the compiler can now assess the rest of the code and find all the other errors.

    Your code is still very very wrong. You are trying to use variables or classes that do not exist.
    Blackink.showInventory();
    For me reading that line of code it suggests that you are trying to call a static method showInventory in the class Blackink. Do you have a class called Blackink? Does that class have a static method called showInventory? Or maybe Blackink is a variable. Have you declared a variable called Blackink? If it is a variable then it should be lowercase: blackink. What class is the variable Blackink? Does that class have a method called showInventory?

    All your other errors are similar.
    supllies printer = new supplies( 20, "Black ink", 60, 19.99);
    supplies printer = new supplies( 10, "Color ink", 75, 29.99);
    supplies printer = new supplies( 30, "Epson", 30, 40.00 );
    supplies printer = new supplies( 50, "Hewlitt packard", 15, 90.00 );
    supplies printer = new supplies( 40, "Polaroid", 45, 120.00 );
    Do you have a class called supllies? Do you have a class called supplies? For class names it os the opposite of variable names, they should be uppercase so it should be Supplies. The above code is trying to declare 5 variables all called printer. You cannot do this. You must give all variables in the same scope a different name.

    There are so many problems with your code that you need to go back and review the basics.
    Improving the world one idiot at a time!

Similar Threads

  1. Help with run time error
    By white97 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: August 11th, 2011, 12:35 PM
  2. Run Time Error.
    By seymour001 in forum What's Wrong With My Code?
    Replies: 4
    Last Post: August 10th, 2011, 12:10 PM
  3. new to java.... having a hard time trying to read code
    By Newbie_96 in forum Java Theory & Questions
    Replies: 2
    Last Post: August 6th, 2011, 01:51 AM
  4. [SOLVED] Run time error
    By moodycrab3 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 7th, 2011, 11:05 AM
  5. [SOLVED] Experiencing a run time error, don't know what the problem is
    By scooty199 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 3rd, 2010, 10:21 AM