Results 1 to 19 of 19
  1. #1
    ljk8950 is offline Member
    Join Date
    Jul 2008
    Posts
    43
    Rep Power
    0

    Red face Java Inventory Program Part 3

    Hello everyone,

    This is my first post to this forum and I am hoping someone out there can help me. I am an online student and the teachers are never available to help students on the weekend. I have been working steadily on an assignment form my Java class for the past 5 days. This assignment is due tomorrow 7/28/08. Below is the requirements of the assignment:

    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 that the new feature and restocking fee do not display when the program compiles. Can anyone please help me figure this out? Thanks in advance!:)

    Here is my program:

    // CheckPoint: InventoryProgramPart3.java
    // Week 6
    // This program calculates inventory value

    import java.util.Scanner;
    import java.util.Arrays;

    public class InventoryProgramPart3
    {

    // 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 Inventory Program Part 3!" );

    // office supplies

    supplies[] supplies = new supplies[100]; // an array of 100 supplies

    supplies notepads = new supplies( 4000, "notepads", 60, 2.75, "Ampad" );
    supplies pencils = new supplies( 5000, "pencils", 75, 1.25 );
    supplies folders = new supplies( 2000, "folders", 30, 4.75 );
    supplies envelopes = new supplies( 1000, "envelopes", 15, 5.25 );
    supplies markers = new supplies( 3000, "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 Inventory Program Part 3!\n" );

    } // end method main

    } // end class InventoryProgramPart3

    // 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( "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()

    } // end class manufacturer

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,563
    Rep Power
    25

    Default

    My problem is that the new feature and restocking fee do not display when the program compiles.
    Do you mean when the program executes?
    Are there any errors in the compile?
    What is output when the program executes?
    If nothing is being displayed, add println() statements to various methods until you see the output from them. Then copy that here with your questions and comments.

  3. #3
    ljk8950 is offline Member
    Join Date
    Jul 2008
    Posts
    43
    Rep Power
    0

    Default Reply to Norm

    Norm,

    Below is what displays when the program executes.

    Welcome to Inventory Program Part 3!

    Product Number: 1000
    Product Name: envelopes
    Number of Units: 15
    Unit Price: $5.25
    Inventory value of envelopes is = $78.75

    Product Number: 2000
    Product Name: folders
    Number of Units: 30
    Unit Price: $4.75
    Inventory value of folders is = $142.50

    Product Number: 3000
    Product Name: markers
    Number of Units: 45
    Unit Price: $3.50
    Inventory value of markers is = $157.50

    Product Number: 4000
    Product Name: notepads
    Number of Units: 60
    Unit Price: $2.75
    Inventory value of notepads is = $165.00

    Product Number: 5000
    Product Name: pencils
    Number of Units: 75
    Unit Price: $1.25
    Inventory value of pencils is = $93.75

    Total inventory value is: $637.50

    Thank you for using Inventory Program Part 3!


    I am not gettting any error messages. However, the new feature, which is "manufacturer", and the restocking fee do not display. Any ideas of what I can do to fix this?

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,563
    Rep Power
    25

    Default

    Where are the new features supposed to display?
    Where in your program is the code to println() them?
    toString() appears to build a String with the values, but where is that String printed?

  5. #5
    ljk8950 is offline Member
    Join Date
    Jul 2008
    Posts
    43
    Rep Power
    0

    Default Reply to Norm

    Norm,

    I am sorry I have done so many revisions to this program, I posted the wrong version. Below is the current version. At the end of the subclass I have the println() for the program. I really appreciate your help. Please let me know what you think I am doing wrong. Thanks!:)

    // CheckPoint: InventoryProgramPart3.java
    // Week 6
    // This program calculates inventory value

    import java.util.Scanner;
    import java.util.Arrays;

    public class InventoryProgramPart3
    {

    // 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 Inventory Program Part 3!" );

    // office supplies

    supplies[] supplies = new supplies[100]; // an array of 100 supplies

    supplies notepads = new supplies( 4000, "notepads", 60, 2.75 );
    supplies pencils = new supplies( 5000, "pencils", 75, 1.25 );
    supplies folders = new supplies( 2000, "folders", 30, 4.75 );
    supplies envelopes = new supplies( 1000, "envelopes", 15, 5.25 );
    supplies markers = new supplies( 3000, "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 Inventory Program Part 3!\n" );

    } // end method main

    } // end class InventoryProgramPart3

    // 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( "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() );
    System.out.println( "Manufacturer: "+suppliesManufacturer );

    // value() method and display the value
    System.out.printf( "\nInventory value of "+suppliesName+ " is = $%.2f\n",
    getRestockingFee() );

    } // end method display inventory

    } // end class manufacturer

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

    Default

    Hi ljk8950, please use the code tags when you posting your codes next time here in the forum. It's really helpful to read your code for others and replying to you. I think you know hoe to do it.

  7. #7
    ljk8950 is offline Member
    Join Date
    Jul 2008
    Posts
    43
    Rep Power
    0

    Default Reply to Eranga

    Eranga,

    Today is the first day I have ever posted to this forum. What are the code tags and how do I use them?

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

    Default

    On the message replay are you can see some text editing tools, like bold, italic, copy, paste, etc... On that menu area you can find the [CODE] tags. Just keep your cursor on top of those icons for a while. Tool tip explain what it means. After find the [CODE] tags, just lick on it and see what happened.

    You have a pair of code tags, one for opening and the other for closing. In between those two paste your code. Then it look like this.

    Java Code:
    Your code goes here.

  9. #9
    ljk8950 is offline Member
    Join Date
    Jul 2008
    Posts
    43
    Rep Power
    0

    Default Reply to Eranga

    Eranga,

    Thanks for the info. I am going to post my code again to see if it displays betters. Please let me know if I did it right. By the way, I am still looking for help with this code. If anyone out there can help me, I would very much appreciate it. Thank you!:)

    Java Code:
    // CheckPoint:  InventoryProgramPart3.java
    // Week 6
    // This program calculates inventory value
    
    import java.util.Scanner;
    import java.util.Arrays;
    
    public class InventoryProgramPart3
    {
    
         // 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 Inventory Program Part 3!" );
    
              // office supplies
              
              supplies[] supplies = new supplies[100]; // an array of 100 supplies
          
              supplies notepads = new supplies( 4000, "notepads", 60, 2.75 );          
              supplies pencils = new supplies( 5000, "pencils", 75, 1.25 );
              supplies folders = new supplies( 2000, "folders", 30, 4.75 );
              supplies envelopes = new supplies( 1000, "envelopes", 15, 5.25 );
              supplies markers = new supplies( 3000, "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 Inventory Program Part 3!\n" );
              
         } // end method main
    
    } // end class InventoryProgramPart3     
    
    // 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( "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() );
              System.out.println( "Manufacturer:  "+suppliesManufacturer );
    
              // Display value plus restocking fee
              System.out.printf( "\nInventory value of "+suppliesName+ " is = $%.2f\n",
                   getRestockingFee() );     
    
         } // end method display inventory
    
    } // end class manufacturer

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

    Default

    Yes, now it's better. :)

    Lets go to your question. You want to display manufacture details in showInventory() method, right? But I can't see that you have call the manufacture class instance with the required member you want.

  11. #11
    ljk8950 is offline Member
    Join Date
    Jul 2008
    Posts
    43
    Rep Power
    0

    Default Reply to Eranga

    Eranga,

    Can you show me an example of what you mean by call the manufacturer call instance? My brain is fried right now. I have been working on this for 12 hours straight. Thank you for your help!:)

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

    Default

    Ok, at the time just forget what I said.

    From where you call the showInventory() method in the manufacture class? Did you call it? No, right?

    SO how did you call that function?

  13. #13
    ljk8950 is offline Member
    Join Date
    Jul 2008
    Posts
    43
    Rep Power
    0

    Default Reply to Eranga

    Eranga,

    Isn't this my call of the manufacturer function?

    Java Code:
    // 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

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

    Default

    Yes that's right. You have set the values for manufacture and implement the get method there too, it's fine. Now what I'm asking is where you call the getManufacture() method to get values? Is that clear?

  15. #15
    ljk8950 is offline Member
    Join Date
    Jul 2008
    Posts
    43
    Rep Power
    0

    Default Reply to Eranga

    Is this what you are referring to? Currently, I have this located in the supplies class. I don't think this is right. However, I am able to get the word manufacturer to display when the program is executed. Unfortunately, the manufacturer for this single product displays with all products when executed. I think I am close but so tired right now that I am missing something. Do you hava any idea what that might be?

    Java Code:
    manufacturer supplies = new manufacturer
                   ( 4000, "notepads", 60, 2.75, "Ampad" );    
              
              System.out.println( "\nManufacturer:  "+supplies.getManufacturer() );

  16. #16
    ljk8950 is offline Member
    Join Date
    Jul 2008
    Posts
    43
    Rep Power
    0

    Default Reply to Everyone

    I have been working at this project for hours and have made some changes. Therefore, I have posted the changes I have made and what displays when the program is executed as an update. I am going to go to bed now and hopefully I will have a fresh perspective in the morning. The deadline for this assignment is midnight tomorrow night (7/28/08). Therefore, I need to have this resolved sometime tomorrow. If anyone out there can help me with this, I would be forever grateful. I really want to learn this. I don't feel I can go on to future assignments until I have this mastered. I will be getting up early tomorrow to start on this and will be rechecking any post in this forum that is made late tonight. Again, many thanks to everyone who replies to this post.


    Java Code:
    This is my updated code:
    
    // CheckPoint:  InventoryProgramPart3.java
    // Week 6
    // This program calculates inventory value
    
    import java.util.Scanner;
    import java.util.Arrays;
    
    public class InventoryProgramPart3
    {
    
         // 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 Inventory Program Part 3!" );
    
              // office supplies
              
              supplies[] supplies = new supplies[100]; // an array of 100 supplies
                    
              supplies notepads = new supplies( 4000, "notepads", 60, 2.75);          
              supplies pencils = new supplies( 5000, "pencils", 75, 1.25 );
              supplies folders = new supplies( 2000, "folders", 30, 4.75 );
              supplies envelopes = new supplies( 1000, "envelopes", 15, 5.25 );
              supplies markers = new supplies( 3000, "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 Inventory Program Part 3!\n" );
              
         } // end method main
    
    } // end class InventoryProgramPart3     
    
    // 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
                   ( 4000, "notepads", 60, 2.75, "Ampad" );    
              
              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

    Java Code:
    This is what is currently displayed when the program executes:
    
    Welcome to Inventory Program Part 3!
    
    Product Number:  1000
    Product Name:  envelopes
    Units in Stock:  15
    Unit Price:  $5.25
    Manufacturer:  Ampad
    
    Inventory value of envelopes is = $78.75
    
    Product Number:  2000
    Product Name:  folders
    Units in Stock:  30
    Unit Price:  $4.75
    Manufacturer:  Ampad
    
    Inventory value of folders is = $142.50
    
    Product Number:  3000
    Product Name:  markers
    Units in Stock:  45
    Unit Price:  $3.50
    Manufacturer:  Ampad
    
    Inventory value of markers is = $157.50
    
    Product Number:  4000
    Product Name:  notepads
    Units in Stock:  60
    Unit Price:  $2.75
    Manufacturer:  Ampad
    
    Inventory value of notepads is = $165.00
    
    Product Number:  5000
    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 Inventory Program Part 3!

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

    Default

    Hmm, you are in the correct way actually. But why did you use other data in manufacture class, like product number, product name and so on. Seems to me, you don't need to use them in the manufacture class. It can be, depend on your implementation you want to take.

  18. #18
    ljk8950 is offline Member
    Join Date
    Jul 2008
    Posts
    43
    Rep Power
    0

    Default Reply to Eranga

    Eranga,

    I am not sure I know what you mean by other data in the manufacture class. Can you show me?

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

    Default

    In manufacture class you use all details like product number and so on, is that right? But actually you need there is only the manufacture details, is it? So, do you really need to interact product details and manufacture details.

    There at the time you can display some text. So what you have to do is depend on the product change the manufacture details and display it.

Similar Threads

  1. Payroll Part 2, Java
    By lplopez92 in forum New To Java
    Replies: 2
    Last Post: 03-24-2008, 01:55 PM
  2. Inventory Program modification help
    By badness in forum Java Applets
    Replies: 1
    Last Post: 01-17-2008, 05:24 AM
  3. Inventory part 3 program problems
    By badness in forum New To Java
    Replies: 1
    Last Post: 12-17-2007, 07:00 AM
  4. Inventory part 2 help please
    By badness in forum New To Java
    Replies: 1
    Last Post: 12-12-2007, 07:51 AM
  5. Inventory program
    By Nexcompac in forum New To Java
    Replies: 3
    Last Post: 07-27-2007, 05:51 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •