Create a Java application that displays the product number, the name of the product, the
number of units in stock, the price of each unit, and the value of the inventory (the
number of units in stock multiplied by the price of each unit). Pay attention to the good
programming practices in the text to ensure your source code is readable and well

I'm having trouble with the code to print the value of the inventory. Please assist.

///MICHAEL -- See below...

// Author Michael Anderson
// IT 215 Java Programming April 27, 2008
// Inventory1.java
// Inventory program that displays the value of inventory and number of units in stock.

///MICHAEL - This is public class Inventory1. It MUST be in a file named Inventory1.java
///          NOTE the capitalization...

public class Inventory1 {

    ///MICHAEL - I have straightened out your indentation
    ///          I also corrected some typos re DVD, dvd below...  System
    public static void main(String[] args) {
        DVD dvd;

        dvd = new DVD(11, "American Gangster", 1, 19.99);

        dvd = new DVD(21, "Scarface", 5, 14.95);

        dvd = new DVD(13, "Donnie Brasco", 3, 13.50);

        dvd = new DVD(41, "The Godfather", 10, 29.99);
    } // end main

} // end class Inventory1

class DVD {
    private int itemNum;
    private String dvdTitle;
    private int numInStock;
    private double dvdPrice;

    ///MICHAEL - This is the DEFAULT constructor...
    public DVD () {
        itemNum    = 0;
        dvdTitle   = "";
        numInStock = 0;
        dvdPrice   = 0;
    }// end default constructor

    // 4-argument constructor
    DVD(int itemNum, String dvdTitle, int numInStock, double dvdPrice) {
        this.itemNum    = itemNum;
        this.dvdTitle   = dvdTitle;
        this.numInStock = numInStock;
        this.dvdPrice   = dvdPrice;
    }//end constructor

    public int getItemNum() {
        return itemNum;

    public String dvdTitle() {
        return dvdTitle;

    public int numInStock() {
        return numInStock;

    public double dvdPrice() {
        return dvdPrice;

    public double valueOfInventory() {
        return numInStock * dvdPrice;

    ///MICHAEL - I added this for you...
    /// It's incomplete... YOU need to complete it...
    public String toString() {
        return String.format("Num=%3d   Title=%-20s   Value=$%7.2f",
                              itemNum, dvdTitle, valueOfInventory());


} // end class DVD

Edited by mike_2000_17: Fixed formatting

8 Years
Discussion Span
Last Post by jwenting

So, someone did your work (or most of it) for you, but left you with a little nugget to complete yourself, and so now, you'll post here (without even removing the comments that clearly spell out that someone else did it) hoping that we do even that litlle nugget for you?

What a maroon! (Spelling intended.)

Do Your Own Homework! This is not a homework service. Normally I would have been more than happy to help point out what was wrong (not do it for you, though), but looking at that code, which so clearly spells out that you didn't do it, and that you're then posting it here, in that form, clearly spells out that you didn't even attempt to finish it, just disgusts me.

Votes + Comments

for what? For expecting us to help you cheat or for being stupid enough to make your attempts easy to detect?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.