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: Help Newbie in trouble

  1. #1
    Junior Member
    Join Date
    Mar 2014
    Posts
    12
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Help Newbie in trouble

    Ok, I am new to programming and this site I have been working on fixing ths for a week and every time I just create more errors. I am not asking for some one to do the work, I am just completely lost. I Can not seem to get this array to work. If someone could point me in the right direction it would be awesome.

    Errors:
    > "C:\Program Files\Java\jdk1.7.0_51\bin\javac.exe" InventoryProgram.java
    InventoryProgram.java:31: error: illegal start of expression
    Arrays.sort(Supplies[);
    ^
    InventoryProgram.java:31: error: ')' expected
    Arrays.sort(Supplies[);
    ^
    InventoryProgram.java:31: error: ';' expected
    Arrays.sort(Supplies[);
    ^
    InventoryProgram.java:32: error: ')' expected
    for (int i=0; i<100; i++);{
    ^
    InventoryProgram.java:32: error: illegal start of type
    for (int i=0; i<100; i++);{
    ^
    InventoryProgram.java:32: error: not a statement
    for (int i=0; i<100; i++);{
    ^
    InventoryProgram.java:32: error: ';' expected
    for (int i=0; i<100; i++);{
    ^
    7 errors

    > Terminated with exit code 1.

    import java.util.Scanner;
    import java.util.Arrays;
    import java.lang.String;
     
    public class InventoryProgram
    {
     
         // main method begins program execution
         public static void main(String args[] )
         {
     
     
              // display a welcome message to the InventoryProgram to user
              System.out.println( "Welcome to Inventory Program!" );
     
              // work supplies (names of chemicals used pirces are made up cause I don't know them.
     
              Supplies[] Supplies = new Supplies[100]; // an array of 100 supplies
              Supplies Maverick = new Supplies( 001, "Maverick", 60, 2.75 );          
              Supplies Termidor = new Supplies( 002, "Termidor", 75, 1.25 );
              Supplies Bithor = new Supplies( 003, "Bithor", 30, 4.75 );
              Supplies Demon = new Supplies( 004, "Demon", 15, 5.25 );
              Supplies DeltaDust = new Supplies( 005, "Delta Dust", 45, 3.50 );
     
              for (int i=0; i<100; i++){
    	          System.out.println("Supplies" +0+ ":" +Supplies[0]);
              }
              Arrays.sort(Supplies[);
              for (int i=0; i<100; i++);{
    	          System.out.println("Supplies" +100+ ":" +Supplies[0]);
              }
     
              // display the inventories one at a time
              Maverick.showInventory();
              Termidor.showInventory();
              Bithor.showInventory();
              Demon.showInventory();
              DeltaDust.showInventory();
     
              // sort supplies by name
              for ( int i = 0; i < args.length; i++ )
              System.out.println( args[i] + ", " );
     
              double array[] = { 78.75, 142.50, 157.50, 165.00, 93.75 };
              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 Inventory Program!\n" );
     
         } // end method main
     
    } // end class InventoryProgram     
     
    // Office Supplies
    class Supplies
    {
         private int SuppliesNumber;
         private String SuppliesName = new String();
         private int SuppliesUnits;
         private double SuppliesPrice;
     
         // set supplies number
         public void setSuppliesNumber( int number )
         {
              this.SuppliesNumber = number;
         } // end method set supplies number
     
         // return supplies number
         public float 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( "Number of Units:  "+SuppliesUnits );
              System.out.printf( "Unit Price:  $%.2f", SuppliesPrice );
     
              // 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 "Supplies[f],SuppliesName " is = $%.2f\n",
              //     getRestockingFee())    
     
        } // end method display inventory
     
        }// end class manufacturer


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,420
    Thanks
    49
    Thanked 2,215 Times in 2,188 Posts

    Default Re: Help Newbie in trouble

    The code violates coding conventions by having the same symbol for a class and a variable: Supplies.
    Variables should start with lowercase.

    What is this supposed to mean: Supplies[
    If you don't understand my answer, don't ignore it, ask a question.

  3. The Following User Says Thank You to Norm For This Useful Post:

    Jarheadprogrammer (March 2nd, 2014)

  4. #3
    Junior Member
    Join Date
    Mar 2014
    Posts
    12
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help Newbie in trouble

    That is a error on my part I was trying to fix it myself and took out too much on that line thanks for pointing it out.
    That fixed almost everything Thanks, But I still have this error. I'm not sure what the issue is as I copied the format and syntax directly from my book!
    ---------- Capture Output ----------
    > "C:\Program Files\Java\jdk1.7.0_51\bin\javac.exe" InventoryProgram.java
    InventoryProgram.java:31: error: '.class' expected
    Arrays.sort(supplies[]);
    ^
    1 error

    > Terminated with exit code 1.

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,420
    Thanks
    49
    Thanked 2,215 Times in 2,188 Posts

    Default Re: Help Newbie in trouble

    When you pass a variable to a method don't add []s. Just code the variable name.
    If you don't understand my answer, don't ignore it, ask a question.

  6. #5
    Junior Member
    Join Date
    Mar 2014
    Posts
    12
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help Newbie in trouble

    Dang it, Now I'm back to the original problem. I know what this error means, but I cannot figure out how my values are null did I not put the values in the right place? or is this because I listed the array as 100 but only have 5 entries?
    ---------- Capture Output ----------
    > "C:\Program Files\Java\jre7\bin\java.exe" InventoryProgram
    Welcome to Inventory Program!
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Supplies0:null
    Exception in thread "main" java.lang.NullPointerException
    at java.util.ComparableTimSort.countRunAndMakeAscendi ng(Unknown Source)
    at java.util.ComparableTimSort.sort(Unknown Source)
    at java.util.ComparableTimSort.sort(Unknown Source)
    at java.util.Arrays.sort(Unknown Source)
    at InventoryProgram.main(InventoryProgram.java:31)

    > Terminated with exit code 1.

  7. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,420
    Thanks
    49
    Thanked 2,215 Times in 2,188 Posts

    Default Re: Help Newbie in trouble

    Until the code doesn't product 0:null, change the array size to a small number like 5.

    Trace the code to see how values get into variables and then to where the contents of those variables are printed.

    Add some comments to the code, something like:
    var1 = aValue; // Give var1 aValue
    so that it is possible to scan the code and see where variables are given values
    If you don't understand my answer, don't ignore it, ask a question.

  8. #7
    Junior Member
    Join Date
    Mar 2014
    Posts
    12
    My Mood
    Confused
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Help Newbie in trouble

    You were right it took some fooling around but I finally got it to compile and run, now I just hope it is what the instructor wanted.
    Thank you for the help.

  9. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    SW Missouri
    Posts
    20,420
    Thanks
    49
    Thanked 2,215 Times in 2,188 Posts

    Default Re: Help Newbie in trouble

    Good luck.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Newbie Needs Help
    By DJMS in forum Loops & Control Statements
    Replies: 1
    Last Post: October 30th, 2012, 03:24 PM
  2. BlueJ trouble or program trouble (Combining Arraylists)
    By star12345645 in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 11th, 2012, 12:15 PM
  3. newbie help
    By willmeister in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 1st, 2011, 05:30 PM
  4. Newbie help please
    By RIB in forum Member Introductions
    Replies: 3
    Last Post: August 16th, 2011, 02:29 PM
  5. another newbie..
    By xdigg in forum Member Introductions
    Replies: 0
    Last Post: February 15th, 2010, 06:51 AM