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

Join 150,121 Java Programmers for FREE! Get instant access to thousands of Java experts, tutorials, code snippets, and more! There are 2,005 people online right now. Registration is fast and FREE... Join Now!




Inventory Program Part 1-3

 
Reply to this topicStart new topic

Inventory Program Part 1-3, Ready to pull my hair out!

javagreenhorn
22 Jun, 2008 - 04:42 PM
Post #1

New D.I.C Head
*

Joined: 19 Jun, 2008
Posts: 24

Hello, I am back again. Unfortunately, I have been trying to get this right for 3 days and it is not working. Although my program will build, compile, and run, it has many errors. Pbl tells me I have two dvd classes in one directory; I do not know how I did this and now I am at a complete loss as to what I have to do to fix this. Pllllleeeeeaaaaassseee help me!

This is the assignment: Modify the inventory program by creating a subclass of the product class that uses one additional unique feature (movie year) of the product you chose. 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.

CODE


*/

package mydvdsjava;

import java.util.Scanner;

/** Inventory Program
* IT 215
* @author Tammy Fica
* June 13, 2008
*/
public class MyDvds {
  
  
    //main method begins execution of Java application
    /**
     * @param args the command line arguments
     */
    
    public static void main(String[] args)
    {
        //create and initialize a DVD object
        DVD dvd = new DVD(); //invokes constructor
        //create Scanner to obtain input from command window
        Scanner input = new Scanner( System.in);
        
        System.out.print("Enter product name, item number, number of units in stock, and price of each unit");
        // prompt for user input
        
        String title = "get this from input";
        
        double stock = 0.0;
        double price = 0.0;
        double item = 0.0;
        dvd = new DVD(title, price, stock, item);
        
        System.out.println(dvd);
        
        System.out.println("Title is: " + dvd.getTitle());
        System.out.println("The item number is: " + dvd.getDVDNumber());
        System.out.println("The number of units in stock is: " + dvd.getDVDStock());
        System.out.println("The price of each unit is: " + dvd.getDVDPrice());
        System.out.println("The value of inventory is: " + dvd.inventoryValue());
  
        } //end method main
        
} //end classMyDvds


and this:

CODE

*/

package mydvdsjava;


/**
*
* @author Tammy
*/
/**
*
* @author Tammy
*/
  class DVD extends Product {

    // fields
    private int movieyear;
    private String dvdTitle;
    private double dvdItem;
    private double dvdStock;
    private double dvdPrice;
    
    public DVD(String title, double stock, double price, double item, int year)
    {
        super(productId, itemname, quantityOnHand, itemprice);
      
      dvdTitle = title;
     dvdItem = item;
     dvdStock = stock;
     dvdPrice = price;
    } //end class DVD constructor

    DVD() {
         this ("Unspecified", 0.0, 10.0, 0.0);
    }
    
    public void setYear(int year)
    {
    }
    public int getYear()
    {
        int DVDyear;
        return DVDyear;
    }
    
    @Override
    public double getItemValue()    
    {
        return super.getItemValue() + 1.05;
    }
    
    public double getRestockingFee()
    {
        return super.getItemValue() + .05;
    }
    }
    //set DVD name
    public void setDVDTitle(String title)
    {
        dvdTitle = title;
    }// end method setDVDTitle
    
    //return DVD name
    public String getDvdTitle(String title)
    {
        return dvdTitle;
    } //end method get DvdTitle
    
    //set item number
    public void setDvdItem(double item)
    {
        dvdItem = item;
    } //end method setDvdItem
    
    //return item number
    public double getDvdItem()
    {
        return dvdItem;
    } //end method getDvdItem
    
    //set number of units in stock
    public void setDvdStock (double stock)
    {
        dvdStock = stock;
    } //end method setDvdStock
    
    //return number of units in stock
    public double getDvdStock()
    {
        return dvdStock;
    } //end method getDvdStock
    
    //set price of each unit
    public void setDvdPrice (double price)
    {
        dvdPrice = price;
    } //end method setDvdPrice
  
    //return price of each unit
    public double getDvdPrice()
    {
        return dvdPrice;
    } //end method getDvdPrice
    
    //calculate inventory value
    public double inventoryValue()
    {
        return dvdPrice * dvdStock;
    } //end method inventoryValue

    String getDVDNumber()
      
    {  
        String DVDNumber = null;
  
      return DVDNumber;
    }
        
     String getDVDPrice()
    {        
         String DVDPrice = null;
            return DVDPrice;
  
    }
    String getDVDStock()
    {    
        String DVDStock = null;
            return DVDStock;
    }
        
    
    String getTitle()
    {  
        String DVDTitle = null;
            return DVDTitle;
    }
  }
  }
    
    
    //end class DVD
          




and this:

CODE

*/
// Import class to format values into currency
    import java.text.DecimalFormat;
/**
*
* @author Tammy
*/

public class Inventory {
    // Set up an array 0f Products
    int inventorySize = 30;
    private Product items[] = new Product[inventorySize];
    
    // Set formatter to format values into currency
    DecimalFormat formatter = new DecimalFormat("$###,###.00");
    private int InventorySize;

    // Add a product to array, adds to first empty slot found
     private void addProduct (Product Item) {
        Product item = null;
        
     for (int i = 0; i< inventorySize; i++){
            if (items[i] == null) {
                items[i] = item;
                return;
            }
     }
    }

    /* Loop through array and add up the total value
    * Add quantity on hand and multiply by its price
    * Add the value to a running total
    */

    public double getTotalInvValue(){
        double sumOfInventory = 0.0;
        
        for (Product item : items) {
          
            // Make sure there is an item
            if (item != null) {
                sumOfInventory += item.getItemValue();
            }
        }
        return sumOfInventory;
    }
    
    // Prints inventory list with; name, quantity, price, and total stock value for each item.
    public void printInventory() {
        System.out.println("Printing items in inventory...\n");
        
        boolean hasItems = false;
        
        for (Product item : items) {
            if (item!= null)  {
                hasItems = true;
                  System.out.println("Inventory is currently empty.\n");
            }
         }
     }
}        
        


and finally this:

[code]
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/**
*
* @author Tammy
*/
class Product {

private String name;
private int quantity;
private double price;
private int productid = 0;

// Set the default state of object

public Product() {
this (0,"Unknown", 0, 0.00);
}

// Constructor to specify name, quantity, and price for items
public Product (int productId, String itemname, int quantityOnHand, double itemprice) {
productid = productId;
setName (itemname);
setQuantityOnHand (quantityOnHand);
setPrice (itemprice);

}
public void setName(String itemname) {
name = itemname;
}

// Sets quantity on hand and defaults to zero, if negative
public void setQuantityOnHand (int quantityOnHand) {
if (quantityOnHand > 0) {
quantity = quantityOnHand;
}
else { quantity = 0; }

}
// Set price of product and default to zero if negative
public void setPrice (double itemPrice) {
if (itemPrice > 0.00) {
price = itemPrice;
}
else { price = 0.00; }

}

// Get product name
public String getName() {
return name;
}

public int getQuantityOnHand() {
return quantity;

}

public double getPrice() {
return price;
}

// Calculate value of stock on this item
public double getItemValue() {
return (price * (double)quantity);
}

@Override
public String toString() {
return name + "-" + price;
}

}
[\code]


and the errors are all on the DVD code:

super(productId, itemname, quantityOnHand, itemprice);
cannot find symbol for variables, productId, itemname, quantityOnHand, itemprice.

next one:

this ("Unspecified", 0.0, 10.0, 0.0);
cannot find symbol, dvd constructor

and a bunch of class interface or enum expected starting at the line with:
public void setDVDTitle(String title)






User is offlineProfile CardPM
+Quote Post

Martyr2
RE: Inventory Program Part 1-3
22 Jun, 2008 - 04:57 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 5,660



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

My Contributions
Not to sound like a broken record for this question but I have parts 1 - 3 of a standard inventory program in Java completed and available on my blog (see link below). It is there for you to take a look at, compile and run, play with etc. Just don't rip it please.

Enjoy!

Parts 1 - 3 of Product / Inventory Project

User is offlineProfile CardPM
+Quote Post

pbl
RE: Inventory Program Part 1-3
22 Jun, 2008 - 05:08 PM
Post #3

D.I.C Lover
Group Icon

Joined: 6 Mar, 2008
Posts: 3,587



Thanked: 233 times
Dream Kudos: 75
My Contributions
CODE

    DVD() {
         this ("Unspecified", 0.0, 10.0, 0.0);
    }


The DVD class does not have a constructor which expects as parameter:
String, double, double, double
The only constructor you have is

CODE

    public DVD(String title, double stock, double price, double item, int year)
    {


which has as constructor parameter
String, double, double, double, int

CODE

   public DVD(String title, double stock, double price, double item, int year)
    {
        super(productId, itemname, quantityOnHand, itemprice);


productId, itemname, quantityOnHand, itemprice are not defined

CODE

    public int getYear()
    {
        int DVDyear;         //  <------------- this variable is not initialized
        return DVDyear;
    }






User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/9/09 01:23AM

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