Inventory Program Part3

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lilsugaman
    New Member
    • Jul 2008
    • 12

    #1

    Inventory Program Part3

    I now have to 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.


    Any suggestion on a simple code to start the subclass?
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Yep, extend your original class and override that method and make it do what
    your assignment text tells you what it should do. It's your homework.

    kind regards,

    Jos

    Comment

    • lilsugaman
      New Member
      • Jul 2008
      • 12

      #3
      I have tried to create a subclass called premiumProduce that will add a 5% fee to the totalvalue, this is what I have but is not compiling. Please tell me what I'm doing wrong.

      1. import java.util.*;
      2. import java.text.Numbe rFormat;
      3.
      4. public class Produce {
      5.
      6. //initialize and load array with values
      7.
      8. private static int[] produceNumber = new int[] {2015, 2016, 2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024};
      9.
      10. private static String[] produceName = new String[] {"carrots","pot atoe", "bananas", "tomatoe", "lettuce", "apples", "oranges", "grapes", "cherrie", "celery"};
      11.
      12. private static int[] produceStock = new int[] {20, 50, 12, 15, 10, 30, 40, 6, 75, 8};
      13.
      14. private static double[] producePrice = new double[] {.50,2.75,.60,1 .00,1.50,2.50,3 .00,1.89,2.50,1 .48};
      15.
      16.
      17. public static void DisplayOutput()
      18.
      19. { //Displays inventory and totals
      20.
      21. System.out.prin tln("Item Number\tProduce Name\tStock\tPr ice\tTotal Price\n");
      22.
      23. NumberFormat numForm = NumberFormat.ge tCurrencyInstan ce();//Displays double values as currency
      24.
      25. double totalValue = 0;
      26.
      27. for (int i=0; i<10; i++){
      28.
      29. // String price = numform.format( producePrice[i]);
      30.
      31. System.out.prin tln(produceNumb er[i]+"\t\t"+ produceName[i]+"\t\t"+produce Stock[i]+"\t"+numForm.f ormat(producePr ice[i])+
      32.
      33. "\t"+(numForm.f ormat(produceSt ock[i]*producePrice[i])));
      34.
      35. totalValue=tota lValue+(produce Stock[i]*producePrice[i]);
      36. }
      37. System.out.prin tln("\n\nTotal Stock Value: "+numForm.forma t(totalValue));
      38. }
      39.}
      40.
      41. // Inventory Part 3 July 20, 2008
      42.
      43.
      44.
      45. class premiumProduce extends Produce
      46. {
      47.
      48.
      49. private double restockFee;
      50.
      51. public premiumProduce( String name, String number, String Stock, Double price)
      52. {
      53.
      54. super(name, number, stock);
      55. setRestockFee( fee);
      56.
      57. }
      58.
      59. public void setRestockFee( totalValue+0.05 price)
      60.
      61. {
      62.
      63. restockFee = fee < 0.0 ? 0.0 : price);
      64.
      65. }
      66.
      67. public double getRestockFee()
      68.
      69.{
      70. return restockFee;
      71.
      72. }
      73.
      74. public double totalValue()
      75.
      76. {
      77. return getRestockFee() ;
      78.
      79. }
      80.
      81. public String toString()
      82.
      83. {
      84. return String.format(" Premium Produce: %s\n%s: $%,.2f",
      85.
      86. super.toString( ), "Restock Fee", getRestockFee() );
      87.
      88.}
      89.
      90. }
      91.}
      92. }

      Comment

      • BigDaddyLH
        Recognized Expert Top Contributor
        • Dec 2007
        • 1216

        #4
        Do you ever plan on getting rid of those parallel arrays and coding this correctly? You have been told about this several times, I just want to know if it will ever sink in?

        Comment

        • JosAH
          Recognized Expert MVP
          • Mar 2007
          • 11453

          #5
          Originally posted by BigDaddyLH
          Do you ever plan on getting rid of those parallel arrays and coding this correctly? You have been told about this several times, I just want to know if it will ever sink in?
          I'm afraid not; this is one of the cases of "it seems to work, don't touch it anymore".
          Which is quite sad actually because the little deformed class keeps on living and
          spreading more of a mess than it deserves.

          kind regards,

          Jos

          Comment

          • lilsugaman
            New Member
            • Jul 2008
            • 12

            #6
            Well this is the example my instructor gave this is why their still there. If you have another way give me an example so I can understand, I learn by example and visual. Thanks for your help

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by lilsugaman
              Well this is the example my instructor gave this is why their still there. If you have another way give me an example so I can understand, I learn by example and visual. Thanks for your help
              Read my reply #16 in your previous thread.

              kind regards,

              Jos

              Comment

              • chaarmann
                Recognized Expert Contributor
                • Nov 2007
                • 785

                #8
                Originally posted by JosAH
                Read my reply #16 in your previous thread.

                kind regards,

                Jos
                And please read my reply there, too.
                I already gave some sample code there to start with.

                Comment

                Working...