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: Method returning 0 for everything

  1. #1
    Junior Member JJTierney's Avatar
    Join Date
    Dec 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Method returning 0 for everything

    Ok here's my problem....again. This is the only way i know how to do this so don't be disgusted at my coding.

    public class ReOrderList 
    {
     
    	public static void printDetails(Food CheddarCheese, Food DanishBlueCheese, Food BlackOlives, Food GreenOlives, 
    			Stationary BlueBiro, Stationary RedBiro, Stationary SpiralNotebook, 
    			Cleaning Shampoo, Cleaning ShowerGel)
    	{
    		System.out.println("Welcome to the automatic re-order.\nThis program will tell you if we need items or if we dont." +
    							" Any items needed will automatically update.\n");
     
    		if(CheddarCheese.getQtyInStock() > CheddarCheese.getReOrderPoint())
    		{
    			System.out.println("We dont need to order any " + CheddarCheese.getDescription());
    		}
    		else if(CheddarCheese.getQtyInStock() <= CheddarCheese.getReOrderPoint())
    		{
    			System.out.println("We need to order " + (CheddarCheese.getMaxNum() - CheddarCheese.getQtyInStock()) + " more " + CheddarCheese.getDescription() + ".");
    			CheddarCheese.setNewQtyInStock(CheddarCheese.getMaxNum());
    		}
     
    		if(DanishBlueCheese.getQtyInStock() > DanishBlueCheese.getReOrderPoint())
    		{
    			System.out.println("We dont need to order any " + DanishBlueCheese.getDescription());
    		}
    		else if(DanishBlueCheese.getQtyInStock() <= DanishBlueCheese.getReOrderPoint())
    		{
    			System.out.println("We need to order " + (DanishBlueCheese.getMaxNum() - DanishBlueCheese.getQtyInStock()) + " more " + DanishBlueCheese.getDescription() + ".");
    			DanishBlueCheese.setNewQtyInStock(DanishBlueCheese.getMaxNum());
    		}
     
    		if(BlackOlives.getQtyInStock() > BlackOlives.getReOrderPoint())
    		{
    			System.out.println("We dont need to order any " + BlackOlives.getDescription());
    		}
    		else if(BlackOlives.getQtyInStock() <= BlackOlives.getReOrderPoint())
    		{
    			System.out.println("We need to order " + (BlackOlives.getMaxNum() - BlackOlives.getQtyInStock()) + " more " + BlackOlives.getDescription() + ".");
    			BlackOlives.setNewQtyInStock(BlackOlives.getMaxNum());
    		}
     
    		if(GreenOlives.getQtyInStock() > GreenOlives.getReOrderPoint())
    		{
    			System.out.println("We dont need to order any " + GreenOlives.getDescription());
    		}
    		else if(GreenOlives.getQtyInStock() <= GreenOlives.getReOrderPoint())
    		{
    			System.out.println("We need to order " + (GreenOlives.getMaxNum() - GreenOlives.getQtyInStock()) + " more " + GreenOlives.getDescription() + ".");
    			GreenOlives.setNewQtyInStock(GreenOlives.getMaxNum());
    		}
     
    		if(BlueBiro.getQtyInStock() > BlueBiro.getReOrderPoint())
    		{
    			System.out.println("We dont need to order any " + BlueBiro.getDescription());
    		}
    		else if(BlueBiro.getQtyInStock() <= BlueBiro.getReOrderPoint())
    		{
    			System.out.println("We need to order " + (BlueBiro.getMaxNum() - BlueBiro.getQtyInStock()) + " more " + BlueBiro.getDescription() + ".");
    			BlueBiro.setNewQtyInStock(BlueBiro.getMaxNum());
    		}
     
    		if(RedBiro.getQtyInStock() > RedBiro.getReOrderPoint())
    		{
    			System.out.println("We dont need to order any " + RedBiro.getDescription());
    		}
    		else if(RedBiro.getQtyInStock() <= RedBiro.getReOrderPoint())
    		{
    			System.out.println("We need to order " + (RedBiro.getMaxNum() - RedBiro.getQtyInStock()) + " more " + RedBiro.getDescription() + ".");
    			RedBiro.setNewQtyInStock(RedBiro.getMaxNum());
    		}
     
    		if(SpiralNotebook.getQtyInStock() > SpiralNotebook.getReOrderPoint())
    		{
    			System.out.println("We dont need to order any " + SpiralNotebook.getDescription());
    		}
    		else if(SpiralNotebook.getQtyInStock() <= SpiralNotebook.getReOrderPoint())
    		{
    			System.out.println("We need to order " + (SpiralNotebook.getMaxNum() - SpiralNotebook.getQtyInStock()) + " more " + SpiralNotebook.getDescription() + ".");
    			SpiralNotebook.setNewQtyInStock(SpiralNotebook.getMaxNum());
    		}
     
    		if(Shampoo.getQtyInStock() > Shampoo.getReOrderPoint())
    		{
    			System.out.println("We dont need to order any " + Shampoo.getDescription());
    		}
    		else if(Shampoo.getQtyInStock() <= Shampoo.getReOrderPoint())
    		{
    			System.out.println("We need to order " + (Shampoo.getMaxNum() - Shampoo.getQtyInStock()) + " more " + Shampoo.getDescription() + ".");
    			Shampoo.setNewQtyInStock(Shampoo.getMaxNum());
    		}
     
    		if(ShowerGel.getQtyInStock() > ShowerGel.getReOrderPoint())
    		{
    			System.out.println("We dont need to order any " + ShowerGel.getDescription());
    		}
    		else if(ShowerGel.getQtyInStock() <= ShowerGel.getReOrderPoint())
    		{
    			System.out.println("We need to order " + (ShowerGel.getMaxNum() - ShowerGel.getQtyInStock()) + " more " + ShowerGel.getDescription() + ".");
    			ShowerGel.setNewQtyInStock(ShowerGel.getMaxNum());
    		}
    	}
    }

    The newQtyInStock is a variable in Store - the main class.

    public class NewStockList 
    {
    	public static void printDetails(Food CheddarCheese, Food DanishBlueCheese, Food BlackOlives, Food GreenOlives, 
    			Stationary BlueBiro, Stationary RedBiro, Stationary SpiralNotebook, 
    			Cleaning Shampoo, Cleaning ShowerGel)
    	{
    		System.out.println("		New Stock List");
    		System.out.println("Part Code" + "	Description" + "		Quantity In Stock");
    		System.out.println(CheddarCheese.getPartCode() + "		" + CheddarCheese.getDescription() + "		" + CheddarCheese.getNewQtyInStock());
    		System.out.println(DanishBlueCheese.getPartCode() + "		" + DanishBlueCheese.getDescription() + "	" + DanishBlueCheese.getNewQtyInStock());
    		System.out.println(BlackOlives.getPartCode() + "		" + BlackOlives.getDescription() + "		" + BlackOlives.getNewQtyInStock());
    		System.out.println(GreenOlives.getPartCode() + "		" + GreenOlives.getDescription() + "		" + GreenOlives.getNewQtyInStock());
    		System.out.println(BlueBiro.getPartCode() + "		" + BlueBiro.getDescription() + "		" + BlueBiro.getNewQtyInStock());
    		System.out.println(RedBiro.getPartCode() + "		" + RedBiro.getDescription() + "		" + RedBiro.getNewQtyInStock());
    		System.out.println(SpiralNotebook.getPartCode() + "		" + SpiralNotebook.getDescription() + "	" + SpiralNotebook.getNewQtyInStock());
    		System.out.println(Shampoo.getPartCode() + "		" + Shampoo.getDescription() + "			" + Shampoo.getNewQtyInStock());
    		System.out.println(ShowerGel.getPartCode() + "		" + ShowerGel.getDescription() + "		" + ShowerGel.getNewQtyInStock());
    	}
    }

    This is my class for my new stock list. However this is the output.

    New Stock List
    Part Code Description Quantity In Stock
    324 Cheddar Cheese 0
    396 Danish Blue Cheese 0
    387 Black Olives 0
    388 Green Olives 0
    224 Blue Biros 0
    225 Red Biros 0
    267 Spiral Notebooks 0
    123 Shampoo 0
    145 Shower Gel 0


    Any ideas?


  2. #2
    Super Moderator helloworld922's Avatar
    Join Date
    Jun 2009
    Posts
    2,895
    Thanks
    23
    Thanked 619 Times in 561 Posts
    Blog Entries
    18

    Default Re: Method returning 0 for everything

    Did you ever change the quantity of the different items? Also, are your getter/setter methods correct (i.e. the actually get/set the appropriate fields)?

  3. #3
    Junior Member JJTierney's Avatar
    Join Date
    Dec 2010
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Method returning 0 for everything

    CheddarCheese.setNewQtyInStock(CheddarCheese.getMa xNum());

    i thought this piece was setting a value for CheddarCheese.newQtyInStock?

Similar Threads

  1. Boolean method returning a boolean value
    By Deprogrammer in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 21st, 2010, 10:56 AM
  2. Method returning boolean
    By Plural in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 13th, 2010, 06:45 PM
  3. Returning Null
    By Woody619 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: July 22nd, 2010, 12:53 PM
  4. returning a 2D array
    By straw in forum What's Wrong With My Code?
    Replies: 3
    Last Post: March 11th, 2010, 04:30 AM
  5. throwing and returning
    By chronoz13 in forum Exceptions
    Replies: 6
    Last Post: October 25th, 2009, 12:00 AM

Tags for this Thread