Results 1 to 6 of 6
- 08-23-2011, 01:00 PM #1
Member
- Join Date
- Aug 2011
- Posts
- 11
- Rep Power
- 0
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
- 08-23-2011, 06:44 PM #2
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.
- 08-24-2011, 08:56 AM #3
Member
- Join Date
- Aug 2011
- Posts
- 11
- Rep Power
- 0
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 "); } } }
- 08-24-2011, 09:08 AM #4
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
At the end of the big loop you say
ie "print a new line then a space". So it is no wonder that the next ouput will follow that extra space.Java Code:System.out.print("\n ");
-----
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.
- 08-24-2011, 09:12 AM #5
Member
- Join Date
- Aug 2011
- Posts
- 11
- Rep Power
- 0
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.
- 08-24-2011, 09:29 AM #6
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,561
- Rep Power
- 11
Similar Threads
-
Quick question
By Thumper in forum New To JavaReplies: 10Last Post: 11-07-2010, 10:06 PM -
quick question
By vouslavous in forum Java AppletsReplies: 4Last Post: 04-24-2009, 08:35 PM -
Hello everyone! quick question.
By irishhokie in forum New To JavaReplies: 5Last Post: 04-03-2009, 04:13 AM -
[SOLVED] *Simple* Eclipse Text Formatting Question
By davomyster in forum EclipseReplies: 1Last Post: 03-16-2009, 06:05 PM -
One last quick question
By jigglywiggly in forum New To JavaReplies: 7Last Post: 01-26-2009, 08:53 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks