Results 1 to 6 of 6
  1. #1
    Mario_1990 is offline Member
    Join Date
    Aug 2011
    Posts
    11
    Rep Power
    0

    Default Quick Question About My Formatting

    For some reason my formatting is adding an additional character of space when my menu returns from doing a function, it doesn't happen on the initial menu but does on any afterwards, I'll give you a example.

    ***************

    ***************

    _*************** <----- This is the issue, I've uploaded a image of it so you can see my source code.

    ***************

    http://imageshack.us/photo/my-images/600/40259847.png/
    Last edited by Norm; 08-23-2011 at 07:37 PM. Reason: Removed unnecessary font

  2. #2
    stchman's Avatar
    stchman is offline Member
    Join Date
    Apr 2011
    Location
    Saint Louis, Missouri
    Posts
    97
    Rep Power
    0

    Default

    Give us some code to see what's going on.
    If you aren't programming in Java, well that's just too bad.
    I'd rather be using Ubuntu.

  3. #3
    Mario_1990 is offline Member
    Join Date
    Aug 2011
    Posts
    11
    Rep Power
    0

    Default

    I did have a link there which shows the code but I'll display it here also I guess.


    Java Code:
    /********************************************************/
    /*														*/
    /* DEVELOPED BY MARIO STANICIC & COMPLETED BY 8/23/2011	*/
    /*														*/
    /********************************************************/
    
    import java.util.*;
    import java.text.DecimalFormat;
    
    	public class Supermarket_Items
    	{
    		public static void needToOrder(ArrayList ItemList)
    		{
    			Iterator<Items> iterator = ItemList.iterator();
    			while (iterator.hasNext())
    			{
    				Items anItem = iterator.next();
    
    				if(anItem.outOfStock())
    				{
    					System.out.print(anItem + "\n");
    				}
    			}
    		}
    
    		public static void showItems(ArrayList ItemList)
    		{
    			Iterator<Items> iterator = ItemList.iterator();
    			while (iterator.hasNext())
    			{
    				Items anItem = iterator.next();
    				System.out.print(anItem);
    			}
    		}
    
    	public static void main(String args[])
    	{
    		boolean exit = false;
    		Scanner S = new Scanner(System.in);
    		ArrayList<Items> ItemList = new ArrayList<Items>();
    		DecimalFormat money = new DecimalFormat("$0.00");
    
    		ItemList.add(new Grocery	(" APPLES ", 		1, 0, 10.00, 50	));
    		ItemList.add(new Grocery	(" BANANAS ", 		2, 0, 10.00, 50	));
    		ItemList.add(new Grocery	(" COCONUTS ", 		3, 0, 10.00, 50	));
    		ItemList.add(new Grocery	(" ORANGES ", 		4, 0, 10.00, 50	));
    		ItemList.add(new Grocery	(" PEACHES ", 		5, 0, 10.00, 50	));
    		ItemList.add(new Houseware	(" LARGE CHAIR ", 	6, 0, 75.00, 0	));
    		ItemList.add(new Sweets		(" CHOCOLATE ", 	7, 0, 10.00, 0	));
    		ItemList.add(new Toys		(" G.I. JOE ", 		8, 0, 10.00, 0	));
    
    		while (exit != true)
    		{
    			System.out.print(" ***************************** \n\n");
    			System.out.print(" 1: FIND PRODUCT \n 2: SHOW PRODUCTS \n 3: APPLY DISCOUNT \n 4: FIND OUT OF STOCK PRODUCTS \n 5: EXIT \n\n");
    			System.out.print(" ***************************** ");
    			System.out.print(" \n\n REQUESTING A COMMAND: \t");
    			int select = S.nextInt();
    
    			if (select == 1)
    			{
    				System.out.print("\n INSERT BARCODE: \t");
    				long barcode = S.nextLong();
    
    				Iterator<Items> iterator = ItemList.iterator();
    				while (iterator.hasNext())
    				{
    					Items anItem = iterator.next();
    
    					if(anItem.getBarcode() == barcode)
    					{
    						System.out.print(anItem);
    					}
    				}
    
    			System.out.print("\n");
    			}
    
    			if (select == 2)
    			{
    				showItems(ItemList);
    				System.out.print("\n");
    			}
    
    			if (select == 3)
    			{
    				System.out.print(" \n ENTER BARCODE: \t");
    				long barcode = S.nextLong();
    
    				Iterator<Items> iterator = ItemList.iterator();
    				while (iterator.hasNext())
    				{
    					Items anItem = iterator.next();
    
    					if(anItem.getBarcode() == barcode)
    					{
    						System.out.print(anItem);
    						System.out.print(" \n\n ENTER DISCOUNT: \t");
    						double discount = S.nextDouble();
    						anItem.putOnSale(discount);
    						System.out.print(anItem + " \n\n PRICE: \t\t"
    						+ money.format(anItem.getPrice())
    						+ "\n\n PRICE WITH DISCOUNT: \t"
    						+ money.format(anItem.getPrice() - (discount / 100 * anItem.getPrice()))
    						+ "\n");
    					}
    				}
    			}
    
    			if (select == 4)
    			{
    				needToOrder(ItemList);
    			}
    
    			if (select == 5)
    			{
    				exit = true;
    			}
    
    			System.out.print("\n ");
    		}
    	}
    }

  4. #4
    pbrockway2 is online now Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,547
    Rep Power
    11

    Default

    At the end of the big loop you say

    Java Code:
    System.out.print("\n ");
    ie "print a new line then a space". So it is no wonder that the next ouput will follow that extra space.

    -----

    Also "while (exit != true)" is better written as "while(!exit)". Generally variables should be as descriptive as possible and should start with a lowercase letter. Personally, I would go for exitWanted, scanner, itemList, format.

  5. #5
    Mario_1990 is offline Member
    Join Date
    Aug 2011
    Posts
    11
    Rep Power
    0

    Default

    Oh wow I can't believe I didn't see that, I was convinced it was something I did further up in my script.

    Very much appreciated, thank you.

  6. #6
    pbrockway2 is online now Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,547
    Rep Power
    11

    Default

    You're welcome.

Similar Threads

  1. Quick question
    By Thumper in forum New To Java
    Replies: 10
    Last Post: 11-07-2010, 10:06 PM
  2. quick question
    By vouslavous in forum Java Applets
    Replies: 4
    Last Post: 04-24-2009, 08:35 PM
  3. Hello everyone! quick question.
    By irishhokie in forum New To Java
    Replies: 5
    Last Post: 04-03-2009, 04:13 AM
  4. Replies: 1
    Last Post: 03-16-2009, 06:05 PM
  5. One last quick question
    By jigglywiggly in forum New To Java
    Replies: 7
    Last Post: 01-26-2009, 08:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •