Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Error I cannot figure out for the life of me

  1. #1
    Junior Member
    Join Date
    Aug 2011
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Error I cannot figure out for the life of me

    I am still learning so if at all possible try to put the information into lamen's terms for me please. I am getting an error which is: :\Users\Colby and Erin\Desktop\Inventorypart2.java:110: missing return statement
    }
    ^
    1 error...If I add that in it keeps saying it stops parsing where I put in the statement...My code is:
    public class Inventorypart2 {
     
    public static void main(String args []) {
     
    DVD dvd;
     
     
    dvd = new DVD(1, "The Fellowship of the Ring", 5, 14.95);
    System.out.println(dvd);
     
    dvd = new DVD(2, "The Chamber", 7, 12.99);
    System.out.println(dvd);
     
    dvd = new DVD(3, "Superman 3", 6, 19.99);
    System.out.println(dvd);
     
    dvd = new DVD(4, "Van Helsing", 3, 10.99);
    System.out.println(dvd);
     
    } //end main
     
    } // end class Inventorypart2
     
     
    class DVD {
    private int dvdItem;
    private String dvdTitle;
    private int dvdStock;
    private double dvdPrice;
     
    public DVD(int item, String title, int stock, double price) {
    dvdItem = item;
    dvdTitle = title;
    dvdStock = stock;
    dvdPrice = price;
    } //end four-argument constructor
     
    // set DVD Item
    public void setDvdItem(int item) {
    dvdItem = item;
    } //end method set Dvd Item
     
    //return DVD Item
    public int getDvdItem() {
    return dvdItem;
    } //end method get Dvd Item
     
    //set DVD Title
    public void setDvdTitle(String title) {
    dvdTitle = title;
    } //end method set Dvd Title
     
    //return Dvd Title
    public String getDvdTitle() {
    return dvdTitle;
    } //end method get Dvd Title
     
    public void setDvdStock(int stock) {
    dvdStock = stock;
    } //end method set Dvd Stock
     
    //return dvd Stock
    public int getDvdStock() {
    return dvdStock;
    } //end method get Dvd Stock
     
    public void setDvdPrice(double price) {
    dvdPrice = price;
    } //end method setdvdPrice
     
    //return DVD Price
    public double getDvdPrice() {
    return dvdPrice;
    } //end method get Dvd Price
     
    //calculate inventory value
    public double value() {
    return dvdPrice * dvdStock;
    } //end method value
     
    public String toString() {
     
    return String.format("item=%3d title=%-20s units=%d price=%.2f value=%.2f",
    dvdItem, dvdTitle, dvdStock, dvdPrice, value());
    }
     
    } //end class DVD
     
    class Inventory {
    DVD movies[] = new DVD[100];
     
    // Add to inventory
    public void addToInventory(DVD movie) {
     
     
    }
     
    // Get inventory value
    public double getInventoryValue() {
     
     
    Inventory myInventory = new Inventory();
     
     
    myInventory.addToInventory(new DVD(1, "Remember the Titans", 5, 14.95));
     
    // Print out the inventory total value
    System.out.println("Total value of inventory is: " + myInventory.getInventoryValue());
     
    }
    }


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Error I cannot figure out for the life of me

    "Missing return statement" is self evident. You have a non-void method which does not have a return statement. "Yes it does" you cry. Perhaps you have an if statement in the method which means that there are two or more alternative paths through the code and one of those paths does not hit a return statement. Time to debug your code.
    Improving the world one idiot at a time!

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Error I cannot figure out for the life of me

    Hi,
    Problem is in the bellow code
    // Get inventory value
    public double getInventoryValue() {


    Inventory myInventory = new Inventory();


    myInventory.addToInventory(new DVD(1, "Remember the Titans", 5, 14.95));

    // Print out the inventory total value
    System.out.println("Total value of inventory is: " + myInventory.getInventoryValue());

    }
    that should return a double value.
    eg.
    // Get inventory value
    public double getInventoryValue() {


    Inventory myInventory = new Inventory();


    myInventory.addToInventory(new DVD(1, "Remember the Titans", 5, 14.95));

    // Print out the inventory total value
    System.out.println("Total value of inventory is: " + myInventory.getInventoryValue());
    return myInventory.getInventoryValue();
    }

    bean factory
    Last edited by abani; December 18th, 2011 at 02:09 AM.

Similar Threads

  1. Defining a rational class. Simple but i cant figure it out to save my life
    By spetillo3 in forum Object Oriented Programming
    Replies: 3
    Last Post: October 26th, 2011, 11:02 PM
  2. I can't figure out why i keep getting this error
    By chrissy2860 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: September 17th, 2011, 03:06 PM
  3. just one more error that i cannot figure out please help me.
    By knoxy5467 in forum What's Wrong With My Code?
    Replies: 31
    Last Post: June 14th, 2011, 09:04 AM
  4. Game of Life GUI Error
    By Lavace in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 3rd, 2011, 09:15 AM
  5. Can not figure out my programs error!
    By mparkerj in forum What's Wrong With My Code?
    Replies: 1
    Last Post: February 16th, 2010, 10:48 AM