13 Replies - 517 Views - Last Post: 16 February 2012 - 10:44 PM Rate Topic: -----

#1 Kaosuvls  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 14-February 12

Help With Inventory Program

Posted 14 February 2012 - 10:10 PM

This is my assignment guys: Modify the Inventory Program by creating a subclass of the product class that uses one additional unique feature of the product you chose (for the DVDs subclass, you could use movie title, for example). In the subclass, create a method to calculate the value of the inventory of a product with the same name as the method previously created for the product class. The subclass method should also add a 5% restocking fee to the value of the inventory of that product.

Modify the output to display this additional feature you have chosen and the restocking fee.

My problem is I cannot get my code to display the restocking fee or the manufacturer properly. Can any one see something I am missing and explain in laymens terms please. I got it to display one manufacturer for notepads but it shows on all the others also and if I try to put more than one manufacturer it gives error.

This is what I have:

Java Code:

// InventoryProgram.java
//
// This program calculates inventory value
  
package inventory.project;
import java.util.Scanner;
/**
 *
 * @author Curtis Criff
 */
public class InventoryProject {
  
     // 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 InventoryProgramPart3 user
          System.out.println( "Welcome to the Inventory Program!" );
  
          // office supplies
            
          supplies[] supplies = new supplies[100]; // an array of 100 supplies
          manufacturer[] manufacturer = new manufacturer[100];
                  
          supplies notepads = new supplies( 04, "notepads", 60, 2.75 );
          supplies pencils = new supplies( 05, "pencils", 75, 1.25 );
          supplies folders = new supplies( 02, "folders", 30, 4.75 );
          supplies envelopes = new supplies( 01, "envelopes", 15, 5.25 );
          supplies markers = new supplies( 03, "markers", 45, 3.50 );
                               
          // display the inventories one at a time
          envelopes.showInventory();
          folders.showInventory();
          markers.showInventory();
          notepads.showInventory();
          pencils.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 the Inventory Program!\n" );
            
     } // end method main
  
} // end class InventoryProgram   
  
// Office 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
               ( 04, "notepads", 60, 2.75, "Ampad" );  
            
          System.out.println( "\nManufacturer:  "+supplies.getSuppliesManufacturer() );
                      
          // 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 setSuppliesManufacturer( String manufacturer )
     {
          this.suppliesManufacturer = manufacturer;
     } // end method set supplies manufacturer
  
     // return supplies manufacturer
     public String getSuppliesManufacturer()
     {
         return suppliesManufacturer;
     } // end method get supplies manufacturer
  
     // add 5% restocking fee
    @Override
     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
    @Override
     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
    @Override
     public void showInventory()
     {
          super.showInventory();
          System.out.println( toString() );
          System.out.println( "\nManufacturer:  "+getSuppliesManufacturer() );
  
          // Display value plus restocking fee
          System.out.printf( "\nInventory value of "+suppliesName+ " is = $%.2f\n",
               getRestockingFee() );   
  
     } // end method display inventory
  
} // end class manufacturer



Is This A Good Question/Topic? 0
  • +

Replies To: Help With Inventory Program

#2 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: Help With Inventory Program

Posted 14 February 2012 - 10:14 PM

// Display value plus restocking fee
          System.out.printf( "\nInventory value of "+suppliesName+ " is = $%.2f\n",
               getRestockingFee() );


Going by the comments there should it be getRestockingFee() + getValue() Since you are wanting the value AND the restocking fee totaled together.
Was This Post Helpful? 0
  • +
  • -

#3 Kaosuvls  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 14-February 12

Re: Help With Inventory Program

Posted 14 February 2012 - 11:41 PM

Yeah, I have tried that also but nothing changed. Output still the same. The Restocking Fee does not even show up on the Inventory list. And Ampad should only appear on the Notebook part instead of all the products as per my code. Any other suggestions guys.

This is the output from NetBeans 7.1

Welcome to the Inventory Program!

Product Number: 1
Product Name: envelopes
Units in Stock: 15
Unit Price: $5.25
Manufacturer: Ampad

Inventory value of envelopes is = $78.75

Product Number: 2
Product Name: folders
Units in Stock: 30
Unit Price: $4.75
Manufacturer: Ampad

Inventory value of folders is = $142.50

Product Number: 3
Product Name: markers
Units in Stock: 45
Unit Price: $3.50
Manufacturer: Ampad

Inventory value of markers is = $157.50

Product Number: 4
Product Name: notepads
Units in Stock: 60
Unit Price: $2.75
Manufacturer: Ampad

Inventory value of notepads is = $165.00

Product Number: 5
Product Name: pencils
Units in Stock: 75
Unit Price: $1.25
Manufacturer: Ampad

Inventory value of pencils is = $93.75

Total inventory value is: $637.50

Thank you for using the Inventory Program!
Was This Post Helpful? 0
  • +
  • -

#4 Sheph  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 432
  • View blog
  • Posts: 1,020
  • Joined: 12-October 11

Re: Help With Inventory Program

Posted 15 February 2012 - 12:32 AM

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
          ( 04, "notepads", 60, 2.75, "Ampad" );  
       
     System.out.println( "\nManufacturer:  "+supplies.getSuppliesManufacturer() );
                 
     // value() method and display the value
     System.out.printf( "\nInventory value of "+suppliesName+ " is = $%.2f\n",
          getValue() );   

} // end display inventory
Here is your problem. You output the supplies.getSuppliesManufacturer() of a variable that you set the manufacturer to Ampad every single time you call showInventory(), no matter what the object is. It doesn't care that it's a notepads with 60 and 2.75.. you never use that information. If manufacturer extends supplies, you should be able to use that class instead of creating supplies objects. I think that was what you were supposed to do.
Was This Post Helpful? 0
  • +
  • -

#5 Kaosuvls  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 14-February 12

Re: Help With Inventory Program

Posted 15 February 2012 - 01:10 PM

Thanks for the help but I am fairly new to this so I am sort of lost here. Are you saying I need to take lines 10 - 13 and put them under manufacturer extended class. If so I have tried that but every time I move those lines then I cant get the program to even show Manufacturer. Can you compile the code and see if you can spot anything else that may be a problem. Meanwhile I am going to copy the code over step by step to see what I find.

Thanks
Was This Post Helpful? 0
  • +
  • -

#6 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: Help With Inventory Program

Posted 15 February 2012 - 01:36 PM

     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
               ( 04, "notepads", 60, 2.75, "Ampad" ); 
          System.out.println( "\nManufacturer:  "+supplies.getSuppliesManufacturer() );


Change the System.out.println("\n ... ) to System.out.println(supplies.toString());
Was This Post Helpful? 0
  • +
  • -

#7 Kaosuvls  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 14-February 12

Re: Help With Inventory Program

Posted 15 February 2012 - 02:24 PM

Thanks guys. That solved two problems and also brought another one. I still have to set the manufacturer for each item. Can any one provide a simple example and I'll go from there.

The updated code is now
// InventoryProgram.java
// 
// This program calculates inventory value
 
package inventory.project;
import java.util.Scanner;
/**
 *
 * @author Curtis Criff
 */
public class InventoryProject {
 
     // 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 InventoryProgramPart3 user
          System.out.println( "Welcome to the Inventory Program!" );
 
          // office supplies
           
          supplies[] supplies = new supplies[100]; // an array of 100 supplies
          manufacturer [] manufacturer = new manufacturer [100];
                 
          supplies notepads = new supplies( 04, "notepads", 60, 2.75 );
          supplies pencils = new supplies( 05, "pencils", 75, 1.25 );
          supplies folders = new supplies( 02, "folders", 30, 4.75 );
          supplies envelopes = new supplies( 01, "envelopes", 15, 5.25 );
          supplies markers = new supplies( 03, "markers", 45, 3.50 );
           
          
          // display the inventories one at a time
          envelopes.showInventory();
          folders.showInventory();
          markers.showInventory();
          notepads.showInventory();
          pencils.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 the Inventory Program!\n" );
           
     } // end method main
 
} // end class InventoryProgram    
 
// Office 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
               ( 04, "", 60, 2.75, "" );
           
         System.out.println( supplies.toString() );  
    
                     
          // 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 = "manufacturer";
     
       
     // five-argument constructor
      public manufacturer( int number, String name, int units,
          double price, String manufacturer )
     {
          super( number, name, units, price );
          this.suppliesManufacturer = manufacturer;
     } // end five-argument constructor
 
     // set supplies manufacturer
     public void setSuppliesManufacturer( String manufacturer )
     {
          suppliesManufacturer = manufacturer;
     } // end method set supplies manufacturer
 
     // return supplies manufacturer
     public String getSuppliesManufacturer()
     {
         return suppliesManufacturer;
     } // end method get supplies manufacturer
 
     // add 5% restocking fee
    @Override
     public double getValue()
     {
          return suppliesUnits * suppliesPrice;
     } // end method return supplies manufacturer
 
     // calculate restocking fee
     public double getRestockingFee()
     {
          return 0.05 * suppliesUnits * suppliesPrice;
     } //end method calculate restocking fee
           
     //return String representation of suppliesManufacturer
    @Override
     public String toString()
     {
          String formatString = "\nManufacturer:  %s";
          formatString += "\nRestocking Fee:  $%.2f";
          formatString = String.format( formatString, suppliesManufacturer,
               super.getValue() * 0.05 );
          return( formatString + super.toString() );
     } // end toString()
 
     // display inventory
    @Override
     public void showInventory()
     {
          super.showInventory();
          System.out.println( toString() );
          System.out.println( "\nManufacturer:  "+getSuppliesManufacturer() );
 
          // Display value plus restocking fee
          System.out.printf( "\nInventory value of "+suppliesName+ " is = $%.2f\n",
               getRestockingFee() );    
 
     } // end method display inventory
 
} // end class manufacturer


And it outputs:

Welcome to the Inventory Program!

Product Number: 1
Product Name: envelopes
Units in Stock: 15
Unit Price: $5.25
Manufacturer:
Restocking Fee: $8.25inventory.project.manufacturer@cc5436

Inventory value of envelopes is = $78.75

Product Number: 2
Product Name: folders
Units in Stock: 30
Unit Price: $4.75
Manufacturer:
Restocking Fee: $8.25inventory.project.manufacturer@11d2066

Inventory value of folders is = $142.50

Product Number: 3
Product Name: markers
Units in Stock: 45
Unit Price: $3.50
Manufacturer:
Restocking Fee: $8.25inventory.project.manufacturer@1fc25e5

Inventory value of markers is = $157.50

Product Number: 4
Product Name: notepads
Units in Stock: 60
Unit Price: $2.75
Manufacturer:
Restocking Fee: $8.25inventory.project.manufacturer@b655a

Inventory value of notepads is = $165.00

Product Number: 5
Product Name: pencils
Units in Stock: 75
Unit Price: $1.25
Manufacturer:
Restocking Fee: $8.25inventory.project.manufacturer@caf083

Inventory value of pencils is = $93.75

Total inventory value is: $637.50

Thank you for using the Inventory Program!

I need to get rid of the stuff on the Restocking fee line and properly set and get the restocking fee, which i think i have figured out.

Thanks again guys.
Was This Post Helpful? 0
  • +
  • -

#8 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: Help With Inventory Program

Posted 15 February 2012 - 02:30 PM

return( formatString + super.toString() );

Remove the .toString() portion of that.
Was This Post Helpful? 0
  • +
  • -

#9 Sheph  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 432
  • View blog
  • Posts: 1,020
  • Joined: 12-October 11

Re: Help With Inventory Program

Posted 15 February 2012 - 02:30 PM

This one is getting tricky because your professor said to extend the product class (I'm assuming the supplies class) and override methods. You seem to be changing the supplies class to get what output you want. Are you allowed to do this? Why don't you try creating manufacturer objects instead of supplies objects in your main method, then call showInventory() on those to see what you get.
Was This Post Helpful? 0
  • +
  • -

#10 Kaosuvls  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 14-February 12

Re: Help With Inventory Program

Posted 15 February 2012 - 02:35 PM

Good advice guys I'll try it out
Was This Post Helpful? 0
  • +
  • -

#11 Kaosuvls  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 14-February 12

Re: Help With Inventory Program

Posted 15 February 2012 - 03:03 PM

Ok guys I think I nailed it with your help of course.

This is my final code:

// InventoryProgram.java
// 
// This program calculates inventory value
 
package inventory.project;
import java.util.Scanner;
/**
 *
 * @author Curtis Criff
 */
public class InventoryProject {
 
     // 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 InventoryProgramPart3 user
          System.out.println( "Welcome to the Inventory Program!" );
 
          // office supplies
           
          supplies[] supplies = new supplies[100]; // an array of 100 supplies
          manufacturer [] manufacturer = new manufacturer [100];
                 
          manufacturer notepads = new manufacturer ( 04, "notepads", 60, 2.75, "Rapid" );
          manufacturer pencils = new manufacturer( 05, "pencils", 75, 1.25, "Ampad" );
          manufacturer folders = new manufacturer( 02, "folders", 30, 4.75, "Rapid" );
          manufacturer envelopes = new manufacturer( 01, "envelopes", 15, 5.25, "Rapid" );
          manufacturer markers = new manufacturer( 03, "markers", 45, 3.50, "Ampad" );
          
          
          // display the inventories one at a time
          envelopes.showInventory();
          folders.showInventory();
          markers.showInventory();
          notepads.showInventory();
          pencils.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 the Inventory Program!\n" );
           
     } // end method main
 
} // end class InventoryProgram    
 
// Office 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 );
 
          
          System.out.println();    
             
    
                     
          // 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 = "manufacturer";
     
       
     // five-argument constructor
      public manufacturer( int number, String name, int units,
          double price, String manufacturer )
     {
          super( number, name, units, price );
          this.suppliesManufacturer = manufacturer;
     } // end five-argument constructor
 
     // set supplies manufacturer
     public void setSuppliesManufacturer( String manufacturer )
     {
          suppliesManufacturer = manufacturer;
     } // end method set supplies manufacturer
 
     // return supplies manufacturer
     public String getSuppliesManufacturer()
     {
         return suppliesManufacturer;
     } // end method get supplies manufacturer
 
     // add 5% restocking fee
    @Override
     public double getValue()
     {
          return suppliesUnits * suppliesPrice;
     } // end method return supplies manufacturer
 
     // calculate restocking fee
     public double getRestockingFee()
     {
          return 0.05 * suppliesUnits * suppliesPrice;
     } //end method calculate restocking fee
           
     //return String representation of suppliesManufacturer
    @Override
     public String toString()
     {
          String formatString = "\nManufacturer:  %s";
          formatString += "\nRestocking Fee:  $%.2f";
          formatString = String.format( formatString, suppliesManufacturer,
               super.getValue() * 0.05 );
          return( formatString );
     } // end toString()
 
     // display inventory
    @Override
     public void showInventory()
     {
          super.showInventory();
          System.out.println( toString() );
          
     } // end method display inventory
 
} // end class manufacturer


It outputs:

Welcome to the Inventory Program!

Product Number: 1
Product Name: envelopes
Units in Stock: 15
Unit Price: $5.25

Inventory value of envelopes is = $78.75

Manufacturer: Rapid
Restocking Fee: $3.94

Product Number: 2
Product Name: folders
Units in Stock: 30
Unit Price: $4.75

Inventory value of folders is = $142.50

Manufacturer: Rapid
Restocking Fee: $7.13

Product Number: 3
Product Name: markers
Units in Stock: 45
Unit Price: $3.50

Inventory value of markers is = $157.50

Manufacturer: Ampad
Restocking Fee: $7.88

Product Number: 4
Product Name: notepads
Units in Stock: 60
Unit Price: $2.75

Inventory value of notepads is = $165.00

Manufacturer: Rapid
Restocking Fee: $8.25

Product Number: 5
Product Name: pencils
Units in Stock: 75
Unit Price: $1.25

Inventory value of pencils is = $93.75

Manufacturer: Ampad
Restocking Fee: $4.69

Total inventory value is: $637.50

Thank you for using the Inventory Program!

It looks like I did everything right.
Thanks again
And tell me if yall see any other problems....
Was This Post Helpful? 0
  • +
  • -

#12 Kaosuvls  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 14-February 12

Re: Help With Inventory Program

Posted 16 February 2012 - 09:18 PM

Thanks for the help so far guys.

I have gotten past my first post and now need a little constructive help with my GUI:

I know where the errors are which consist of lines 266 - 300 and line 411.

If anyone can point me in the right direction, that would be great

Here is the code

// InventoryProgram.java
// 
// This program calculates inventory values
 
package inventory.project;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;
import javax.swing.*;

/**
 *
 * @author Curtis Criff
 */
public class InventoryProject {
 
     // 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 InventoryProgramPart3 user
          System.out.println( "Welcome to the Inventory Program!" );
 
          // office supplies
           
          supplies[] supplies = new supplies[100]; // an array of 100 supplies
          manufacturer [] manufacturer = new manufacturer [100];
                 
          manufacturer notepads = new manufacturer ( 04, "notepads", 60, 2.75, "Rapid" );
          manufacturer pencils = new manufacturer( 05, "pencils", 75, 1.25, "Ampad" );
          manufacturer folders = new manufacturer( 02, "folders", 30, 4.75, "Rapid" );
          manufacturer envelopes = new manufacturer( 01, "envelopes", 15, 5.25, "Rapid" );
          manufacturer markers = new manufacturer( 03, "markers", 45, 3.50, "Ampad" );
          
          
          // display the inventories one at a time
          envelopes.showInventory();
          folders.showInventory();
          markers.showInventory();
          notepads.showInventory();
          pencils.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 the Inventory Program!\n" );
           
     } // end method main
 
} // end class InventoryProject 

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 );
          
          System.out.println(); // outputs blank line    
                             
          // 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 = "manufacturer";
     
       
     // five-argument constructor
      public manufacturer( int number, String name, int units,
          double price, String manufacturer )
     {
          super( number, name, units, price );
          this.suppliesManufacturer = manufacturer;
     } // end five-argument constructor
 
     // set supplies manufacturer
     public void setSuppliesManufacturer( String manufacturer )
     {
          suppliesManufacturer = manufacturer;
     } // end method set supplies manufacturer
 
     // return supplies manufacturer
     public String getSuppliesManufacturer()
     {
         return suppliesManufacturer;
     } // end method get supplies manufacturer
 
     // add 5% restocking fee
    @Override
     public double getValue()
     {
          return suppliesUnits * suppliesPrice;
     } // end method return supplies manufacturer
 
     // calculate restocking fee
     public double getRestockingFee()
     {
          return 0.05 * suppliesUnits * suppliesPrice;
     } //end method calculate restocking fee
           
     //return String representation of suppliesManufacturer
    @Override
     public String toString()
     {
          String formatString = "\nManufacturer:  %s";
          formatString += "\nRestocking Fee:  $%.2f";
          formatString = String.format( formatString, suppliesManufacturer,
               super.getValue() * 0.05 );
          return( formatString );
     } // end toString()
 
     // display inventory
    @Override
     public void showInventory()
     {
          super.showInventory();
          System.out.println( toString() );
          
     } // end method display inventory
 
} // end class manufacturer

 // GUI

 
 class Manufacturer  extends JFrame
{
      NumberFormat nf = NumberFormat.getCurrencyInstance();
      private JPanel gridPanel = new JPanel();
	 
      private JPanel panel = new JPanel();
	 
	       
	      JButton nextButton;
	 
	       
	      JTextField suppliesNumberField;
	      JTextField suppliesNameField;
	      JTextField suppliesUnitsField;
	      JTextField suppliesPriceField;
	      JTextField ValueofunitsField;
	      JTextField suppliesManufacturerField;
	      JTextField RestockingFeeField;
	      JTextField TotalinventoryvalueField;
	       
	      JLabel lblsuppliesNumber;
	      JLabel lblsuppliesName;
     	      JLabel lblsuppliesUnits;
	      JLabel lblsuppliesPrice;
	      JLabel lblValueofunits;
	      JLabel lblsuppliesManufacturer;
	      JLabel lblRestockingFee;
	      JLabel lblTotalinventoryvalue;

	       
	      manufacturer envelopes;
	      manufacturer folders;
	      manufacturer markers;
	      manufacturer notepads;
	      manufacturer pencils;
	 
	 
      public static final int MAX_manufacturer = 100; // set maximum size for Supplies Array
	      manufacturer[] manufacturer = new manufacturer[MAX_manufacturer]; // create Supplies Array object
	      static int ArrayIndex = 0; // array index
	 
      public Manufacturer() // constructor
	      {
	            
            envelopes = new ();                    
            envelopes.setsuppliesNumber("01");
            envelopes.setsuppliesName("envelopes");
            envelopes.suppliesUnits(15);
            envelopes.setsuppliesPrice(5.25);
            envelopes.setsuppliesManufacturer("Rapid");
	             
	             
            folders = new  ();           
            folders.setsuppliesNumber("02");
            folders.setsuppliesName("folders");
            folders.suppliesUnits(30);
            folders.setsuppliesPrice(4.75);
            folders.setsuppliesManufacturer("Rapid");
	 
            markers = new  ();           
            markers.setsuppliesNumber("03");
            markers.setsuppliesName("markers");
            markers.suppliesUnits(45);
            markers.setsuppliesPrice(3.50);
            markers.setsuppliesManufacturer("Ampad");;
	 
            notepads = new  ();           
            notepads.setsuppliesNumber("04");
            notepads.setsuppliesName("notepads");
            notepads.suppliesUnits(60);
            notepads.setsuppliesPrice(2.75);
            notepads.setsuppliesManufacturer("Rapid");
	 
            pencils = new  ();           
            pencils.setsuppliesNumber("05");
            pencils.setsuppliesName("pencils");
            pencils.suppliesUnits(75);
            pencils.setsuppliesPrice(1.25);
            pencils.setsuppliesManufacturer("Ampad");
	 
	             
            manufacturer[0] = envelopes;
	    manufacturer[1] = folders;
	    manufacturer[2] = markers;
	    manufacturer[3] = notepads;
	    manufacturer[4] = pencils;
 
	 
            gridPanel.setLayout(new BorderLayout()); // create a border layout
            gridPanel.add(this.createLabelPanel(), BorderLayout.WEST); // add label panel
            gridPanel.add(this.createTextPanel(), BorderLayout.CENTER); // add field panel
            gridPanel.add(this.createButtonPanel(), BorderLayout.SOUTH); // add button panel
            add(gridPanel);
      }
	       
      private JPanel createButtonPanel()
      {
            ActionListener btnListen = new ButtonListener();
	             
            nextButton = new JButton("Next Product"); 
            nextButton.setActionCommand("Next"); 
            nextButton.addActionListener(btnListen);
	             
            JPanel panel = new JPanel();
            panel.add(nextButton);
            return panel;
      }
      private JPanel createLabelPanel()
      {
            
            lblsuppliesNumber = new JLabel("Product Number: ");
            lblsuppliesName = new JLabel("Product Name: ");
            lblsuppliesUnits = new JLabel("Units in Stock: ");
            lblsuppliesPrice = new JLabel("Unit Price: ");
            lblValueofunits = new JLabel("Value Of Units In Stock: ");
            
             
            lblsuppliesManufacturer = new JLabel("Manufacturer: ");
            lblRestockingFee = new JLabel("Restocking Fee: ");
            lblTotalinventoryvalue = new JLabel("Total Inventory Value: ");
 
            panel = new JPanel();
            panel.setLayout(new GridLayout(8, 1, 5 , 5));
	             
            panel.add(lblsuppliesNumber);
            panel.add(lblsuppliesName);
            panel.add(lblsuppliesUnits);
            panel.add(lblsuppliesPrice);
            panel.add(lblValueofunits);
            panel.add(lblsuppliesManufacturer);
            panel.add(lblRestockingFee);
            panel.add(lblTotalinventoryvalue);
            return panel;// return the panel
      }
      private JPanel createTextPanel()
      {
             
            suppliesNumberField = new JTextField();
            suppliesNumberField.setEditable(false);
	             
 
            suppliesNameField = new JTextField();
            suppliesNameField.setEditable(false); 
 
 
            suppliesPriceField = new JTextField();
            suppliesPriceField.setEditable(false); 
	 
	 
            suppliesUnitsField = new JTextField();  
            suppliesUnitsField.setEditable(false);
	 
            ValueofunitsField = new JTextField();
            ValueofunitsField.setEditable(false);
	 
            suppliesManufacturerField = new JTextField();  
            suppliesManufacturerField.setEditable(false);  
	 
            RestockingFeeField = new JTextField();
            RestockingFeeField.setEditable(false);
	 
            TotalinventoryvalueField = new JTextField();
            TotalinventoryvalueField.setEditable(false);
	 
	 
            panel = new JPanel();
            panel.setLayout(new GridLayout(8, 1 , 5 , 5));
            panel.add(suppliesNumberField);
            panel.add(suppliesNameField);
            panel.add(suppliesPriceField);
            panel.add(suppliesUnitsField);
            panel.add(ValueofunitsField);
            panel.add(suppliesManufacturerField);
            panel.add(RestockingFeeField);
            panel.add(TotalinventoryvalueField);
 
	 
	 
	 
	 
            return panel; // return the panel
      } // end createTextPanel method
        // nested ButtonListener class
      class ButtonListener implements ActionListener
      {
        @Override
            public void actionPerformed(ActionEvent e)
            {
                 
                  Arrays.sort(manufacturer, new suppliesComparator();
                  if (e.getActionCommand().equals("Next"))
                        if (ArrayIndex < manufacturer.length)
                        {
                              suppliesNumberField.setText(nf.format(manufacturer[ArrayIndex].getSuppliesNumber()));
                               
                              suppliesNameField.setText(manufacturer[ArrayIndex].getSuppliesName());
                               
                              suppliesPriceField.setText(nf.format(manufacturer[ArrayIndex].getSuppliesPrice()));
	                               
                              suppliesUnitsField.setText(String.valueOf(manufacturer[ArrayIndex].getSuppliesUnits()));
	                               
                              ValueofunitsField.setText(nf.format(manufacturer[ArrayIndex].getValue()));
	                               
                              suppliesManufacturerField.setText(String.valueOf(manufacturer[ArrayIndex].getSuppliesManufacturer()));
	                               
                              RestockingFeeField.setText(nf.format(manufacturer[ArrayIndex].getRestockingFee()));
	                               
                              TotalinventoryvalueField.setText(nf.format(manufacturer[ArrayIndex].getValue()));
	 
                              ArrayIndex = ArrayIndex + 1;
                        } // end if
            } // end actionPerformed
      } // end class ButtonListener
} // end FrameHelperClass



	 
class suppliesComparator<T> implements Comparator<T>
{
	 
    @Override
    public int compare (Object suppliesOne , Object suppliesTwo)
	             
	 
    {
	 
        String SuppliesName1 = ((supplies)suppliesOne).getSuppliesName().toUpperCase();
        String SuppliesName2 = ((supplies)suppliesTwo).getSuppliesName().toUpperCase();
	 
	 
	         
        if (!(SuppliesName1.equals(SuppliesName2)))
                  return SuppliesName1.compareTo(SuppliesName2);
            else
                  return SuppliesName2.compareTo(SuppliesName1);
	 
    }
}

Was This Post Helpful? 0
  • +
  • -

#13 Fuzzyness  Icon User is offline

  • Comp Sci Student
  • member icon

Reputation: 669
  • View blog
  • Posts: 2,438
  • Joined: 06-March 09

Re: Help With Inventory Program

Posted 16 February 2012 - 09:25 PM

Could you be a bit more descriptive with the error that you are receiving? Is it throwing a compilation error or is there some sort of logical error going on?
Was This Post Helpful? 0
  • +
  • -

#14 Kaosuvls  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 14-February 12

Re: Help With Inventory Program

Posted 16 February 2012 - 10:44 PM

this is the output of the code.

Welcome to the Inventory Program!
Exception in thread "main" java.lang.NoClassDefFoundError: inventory/project/manufacturer (wrong name: inventory/project/Manufacturer)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at inventory.project.InventoryProject.main(InventoryProject.java:36)
Java Result: 1

It does not compile because of the above mentioned lines and maybe other problems...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1