Welcome to Dream.In.Code
Become a Java Expert!

Join 149,614 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 1,849 people online right now. Registration is fast and FREE... Join Now!




Inventory Part 3

 
Reply to this topicStart new topic

Inventory Part 3

cmymazda
20 Sep, 2007 - 12:59 PM
Post #1

New D.I.C Head
*

Joined: 27 Aug, 2007
Posts: 13


My Contributions
crying.gif
Hello Everyone,

I need help very bad. Everytime i submit this code my instructor tears it back down and i dont know what to do in order to get it to do what is require. Please help me. I am new to Java and have no idea on how to make this code do what it needs to. Here is the what is expected.
• 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.

Here is the code i currently have that the instructor says is incomplete.

CODE



// Inventory3 program for DVD

class DVD {

    private double dvdStock;
    ///private double restockingfee;
    
    // Constructor  
    DVD(int item, String title, int stock, double price) {
    }


    // dvdStock variable plus a 5% restocking fee
    public void setdvdStock(double dvdStock)
    {
        /// restockingfee = dvdStock * .05;
        this.dvdStock = dvdStock * 1.05;
    }// end setdvdStock

  
    // returns the dvdStock value
    public double getdvdStock() {
        return dvdStock;
    }//end getdvdStock


    public double getDvdValue() {
        return 0;
    }

    // returns the restockingfee value
    public double getRestockingfee()
    {
        return dvdStock * 1.05;    
    }//end getRestockingfee

} //end class DVD


class Inventory
{
    private DVD[] dvd;    

    int dvdItem;
    String dvdTitle;
    int dvdStock;
    double dvdPrice;
    
    public Inventory(int item, String title, int stock, double price) {
        dvdItem  = item;
        dvdTitle = title;
        dvdStock = stock;
        dvdPrice = price;
    }

    // set title
    public void setdvdTitle(String title)
    {
       dvdTitle = title;      
    }

    // set item number
    public void setdvdItem(int item)
    {
       dvdItem = item;  
    }

    public void setdvdStock(int stock)
    {
       dvdStock = stock;
    }
    
    public void setdvdPrice(double price)
    {
       dvdPrice = price;
    }
    
    public String gettitle()
    {  
       return dvdTitle;
    }
    
    public int getitem()
    {  
       return dvdItem;
    }
    
    public int getstock()
    {
       return dvdStock;
    }
    
    public Double getprice()
    {
       return dvdPrice;
    }
    
    public Double getInventoryValue()
    {
       return dvdStock * dvdPrice;
    }
    
    ///Dvd [] dvd = new dvd[number in stock];

    public double getTotalValueofAllInventory()
    {
        double total = 0.0;
        for (int i = 0; i < dvd.length; i++)
        {
            total += dvd[i].getDvdValue();
        }
        return total;
    }

} // end class Inventory


public class Inventory3 {

    public static void main(String[] args) {
        DVD dvd = null;
        Inventory inventory [] = new Inventory[8];
        
        inventory[0] = new Inventory(0, "Bad Boys", 5, 12.99);
        inventory[1] = new Inventory(1, "Color Purple", 7, 14.99);
        inventory[2] = new Inventory(2, "Madea Family Reunion", 6, 13.99);
        inventory[3] = new Inventory(3, "Diary of a Mad Black Woman", 3,

15.99);
        inventory[4] = new Inventory(4, "Forest Gump", 8, 11.99);
        inventory[5] = new Inventory(5, "How Stella Got Her Groove Back", 2,

12.99);
        inventory[6] = new Inventory(6, "What's love Got to do With it", 7,

15.99);
        inventory[7] = new Inventory(7, "Purple Rain", 7, 11.99);
    } // end main
      

} // end class Inventory3



This post has been edited by cmymazda: 20 Sep, 2007 - 01:00 PM
User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Inventory Part 3
20 Sep, 2007 - 01:43 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,655



Thanked: 313 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Yeah I can see why the instructor has said it is incomplete. There are a few things your instructor is looking for here with this. I will cover a few of them with you and show you were you need to look.

1) Base class implementation - This should be where you have defined a "Product" class. This product class should be what you created in part 1 of the project I believe. It is where you have some variables covering the type of product, a couple of methods for calculating the products worth etc.

2) Derived or inherited class - Using your base class Product you are to inherit from it. Remember ever using "extends" in your class? public class DVD extends Product { Does that ring a bell? Your extended class "is a" type of Product is it not? Look in your book at the chapter called "inheritance" and look at the example where it shows you deriving one object from another using extends.

3) Override a function - This is where the instructor is talking about a subclass that should calculate the inventory value using a same name as in the base class. So in other words, in your base class "product" you might have had a method named "getPrice()" where you returned the products price. In your subclass "DVD" you would also have a function called "getPrice()" which has its own implementation of returning its value (by calling its parent class perhaps) and adding the 5% restocking fee. Look into overriding functions in your book to learn more about this. Tip here is that your instructor may also be looking for a call to the base class to get the value of the product. So your getPrice() function make look something like...

CODE

// Get price and add restocking fee
public double getPrice() {
    return super.getPrice() * 1.05;
}


But be sure to ask your instructor if they are looking for a call to a parent class or if just implementing a new version of your override function is sufficient enough.

Hope that helps! smile.gif


User is offlineProfile CardPM
+Quote Post

cmymazda
RE: Inventory Part 3
21 Sep, 2007 - 03:04 PM
Post #3

New D.I.C Head
*

Joined: 27 Aug, 2007
Posts: 13


My Contributions
Okay let me take one part at a time. I have made some changes and I will post the classes seperately. Here is the inventory 3 class

CODE


public class Inventory3 {

    public static void main(String[] args) {
        DVD dvd= null;
        Inventory inventory [] = new Inventory[8];
        
        dvd = new DVD(0, "Bad Boys", 5, 12.99);
        System.out.println(dvd);
        inventory.add(dvd);
        
        dvd = new DVD(1, "Color Purple", 7, 14.99);
        System.out.println(dvd);
        inventory.add(dvd);
        
        dvd = new DVD(2, "Madea Family Reunion", 6, 13.99);
        System.out.println(dvd);
        inventory.add(dvd);
        
        dvd = new DVD(3, "Diary of a Mad Black Woman", 3, 15.99);
        System.out.println(dvd);
        inventory.add(dvd);
        
        dvd = new DVD(4, "Forest Gump", 8, 11.99);
        System.out.println(dvd);
        inventory.add(dvd);
        
        dvd = new DVD(5, "How Stella Got Her Groove Back", 2, 12.99);
        System.out.println(dvd);
        inventory.add(dvd);        
      
        dvd = new DVD(6, "What's love Got to do With it", 7, 15.99);
        System.out.println(dvd);
        inventory.add(dvd);
        
        dvd = new DVD(7, "Purple Rain", 7, 11.99);
        System.out.println(dvd);
        inventory.add(dvd);
        
        System.out.printf("\nTotal value of entire inventory is: $%.2f\n",
           inventory.getTotalValue());
          
        inventory.sort();
        inventory.display();
          
    } // end main



Here is my inventory class

CODE


class Inventory
{
    private DVD[] dvd;    

    int dvdItem;
    String dvdTitle;
    int dvdStock;
    double dvdPrice;
    
    public Inventory(int item, String title, int stock, double price) {
        dvdItem  = item;
        dvdTitle = title;
        dvdStock = stock;
        dvdPrice = price;
    }

    // set title
    public void setdvdTitle(String title)
    {
       dvdTitle = title;      
    }

    // set item number
    public void setdvdItem(int item)
    {
       dvdItem = item;  
    }
    public void setdvdStock(int stock)
    {
       dvdStock = stock;
    }
    
    public void setdvdPrice(double price)
    {
       dvdPrice = price;
    }
    
    public String gettitle()
    {  
       return dvdTitle;
    }
    
    public int getitem()
    {  
       return dvdItem;
    }
    
    public int getstock()
    {
       return dvdStock;
    }
    
    public Double getprice()
    {
       return dvdPrice;
    }
    
    public Double getInventoryValue()
    {
       return dvdStock * dvdPrice;
    }
    
    ///Dvd [] dvd = new dvd[number in stock];

    public double getTotalValueofAllInventory()
    {
        double total = 0.0;
        for (int i = 0; i < dvd.length; i++)
        {
            total += dvd[i].getDvdValue();
        }
        return total;
    }

} // end class Inventory



























quote name='Martyr2' date='20 Sep, 2007 - 02:43 PM' post='258184']
Yeah I can see why the instructor has said it is incomplete. There are a few things your instructor is looking for here with this. I will cover a few of them with you and show you were you need to look.

1) Base class implementation - This should be where you have defined a "Product" class. This product class should be what you created in part 1 of the project I believe. It is where you have some variables covering the type of product, a couple of methods for calculating the products worth etc.

2) Derived or inherited class - Using your base class Product you are to inherit from it. Remember ever using "extends" in your class? public class DVD extends Product { Does that ring a bell? Your extended class "is a" type of Product is it not? Look in your book at the chapter called "inheritance" and look at the example where it shows you deriving one object from another using extends.

3) Override a function - This is where the instructor is talking about a subclass that should calculate the inventory value using a same name as in the base class. So in other words, in your base class "product" you might have had a method named "getPrice()" where you returned the products price. In your subclass "DVD" you would also have a function called "getPrice()" which has its own implementation of returning its value (by calling its parent class perhaps) and adding the 5% restocking fee. Look into overriding functions in your book to learn more about this. Tip here is that your instructor may also be looking for a call to the base class to get the value of the product. So your getPrice() function make look something like...

CODE

// Get price and add restocking fee
public double getPrice() {
    return super.getPrice() * 1.05;
}


But be sure to ask your instructor if they are looking for a call to a parent class or if just implementing a new version of your override function is sufficient enough.

Hope that helps! smile.gif
[/quote]

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 12:27AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Java Help!

Java Tutorials

Reference Sheets

Java Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month