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 14 of 14

Thread: Cash register

  1. #1
    Junior Member
    Join Date
    Jul 2014
    Posts
    14
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Cash register

    my program is almost done! just one more problem
    i want to display in the O.I part the items that the user orders i wonder how am i gonna do that?

    here is my syntax

            System.out.println ("\n        *************************************");
            System.out.print ("        ||Enter choice: ");
            choice1 = input.nextInt ();
            System.out.println ("        *************************************");
                if (choice1 == 1) {
                    do {
                        System.out.println ("\n        **---------------------------------**");
                        System.out.println ("        **---------------------------------**");
                        System.out.println ("                       CHOOSE            ");
                        System.out.println ("            1 FOR BEVERAGES              ");
                        System.out.println ("            2 FOR MEALS                  ");
                        System.out.println ("            3 FOR DESSERTS                ");
                        System.out.println ("        **---------------------------------**");
                        System.out.println ("        **---------------------------------**");
                        System.out.println ("\n        *************************************");
                        System.out.print ("        ||Enter choice: ");
                        choice2 = input.nextInt ();
                        System.out.println ("        *************************************");
                        if (choice2 == 1)  {
                            do {
                                System.out.println ("\n        **---------------------------------**");
                                System.out.println ("         *---------------------------------* ");
                                System.out.println ("        ||              BEVERAGES          ||");
                                System.out.println ("         *---------------------------------* ");
                                System.out.println ("        *|  1 FOR MC CAFE                  |*");
                                System.out.println ("        ||  2 FOR MC CAFE (LARGE)          ||");
                                System.out.println ("        ||  3 FOR MC FlOAT                 ||");
                                System.out.println ("        *|  4 FOR MONSTER FLOAT            |*");
                                System.out.println ("         *---------------------------------* "); 
                                System.out.println ("        **---------------------------------**");
                                System.out.println ("\n        *************************************");
                                System.out.print ("        ||Enter choice: ");
                                choice3 = input.nextInt ();
                                System.out.println ("        *************************************");
                                if (choice3 == 1) {
                                    System.out.print ("        ||ENTER QUANTITY: ");
                                    bevQuant1 = input.nextInt ();
                                } else if (choice3 == 2) {
                                    System.out.print ("        ||ENTER QUANTITY: ");
                                    bevQuant2 = input.nextInt ();
                                } else if (choice3 == 3) {
                                    System.out.print ("        ||ENTER QUANTITY: ");
                                    bevQuant3 = input.nextInt ();
                                } else if (choice3 == 4) {
                                    System.out.print ("        ||ENTER QUANTITY: ");
                                    bevQuant4 = input.nextInt ();
                                }
                                bevTotal = bevQuant1*25.00 + bevQuant2*35.00 + bevQuant3*25.00 + bevQuant4*35.00;
                                System.out.println ("        *************************************");
                                System.out.println ("        ||ADD ANOTHER DRINK(S)?");
                                System.out.println ("        ||1 FOR YES 2 FOR NO");
                                System.out.print ("        ||Enter choice: ");
                                choice4 = input.nextInt ();
                                System.out.println ("        *************************************");
                            } while (choice4 == 1);
                            } 
                            else if (choice2 == 2) {
                                do {
                                    System.out.println ("\n        **---------------------------------**");
                                    System.out.println ("         *---------------------------------* ");
                                    System.out.println ("        ||              MEALS              ||");
                                    System.out.println ("         *---------------------------------* ");
                                    System.out.println ("        *|                                 |*");
                                    System.out.println ("        ||  1 FOR BIG MC                   ||");
                                    System.out.println ("        ||  2 FOR BIG N' TASTY             ||");
                                    System.out.println ("        ||  3 FOR QUARTER POUND W/CHEESE   ||");
                                    System.out.println ("        ||  4 FOR MC DOUBLE                ||");
                                    System.out.println ("        *|  5 FOR Mc SPICY                 |*");
                                    System.out.println ("        ||  6 FOR MC NUGGETS               ||");
                                    System.out.println ("        ||  7 FOR FILET-O-FISH             ||");
                                    System.out.println ("        ||  8 FOR MC CHICKEN SANDWICH      ||");
                                    System.out.println ("        ||  9 FOR CHICKEN MCDO AND FRIES   ||");
                                    System.out.println ("         *---------------------------------* ");
                                    System.out.println ("        **---------------------------------**");
                                    System.out.println ("\n        *************************************");
                                    System.out.print ("        Enter choice: ");
                                    choice6 = input.nextInt ();
                                    System.out.println ("        *************************************");
                                    if (choice6 == 1) {
                                        do {
                                            mealCycle ();
                                            bigMcChoice = input.nextInt ();
                                            System.out.println ("        **==========================================**");
                                            if (bigMcChoice == 1) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                bigMcQuant1 = input.nextInt ();
                                            } 
                                            else if (bigMcChoice == 2) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                bigMcQuant2 = input.nextInt ();
                                            }
                                            bigMcTotal = bigMcQuant1 * 175.00 + bigMcQuant2 * 155.00;
                                            orderRepeater ();
                                            bigMcChoice2 = input.nextInt ();
                                            System.out.println ("        **==========================================**");  
                                        }while (bigMcChoice2 == 1);
                                    }
                                    else if (choice6 == 2) {
                                        do {
                                            mealCycle ();
                                            bigNTastyChoice = input.nextInt ();
                                            System.out.println ("        **==========================================**");
                                            if (bigNTastyChoice == 1) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                bigNTastyQuant = input.nextInt ();
                                            }
                                            else if (bigNTastyChoice == 2 ) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                bigNTastyQuant2 = input.nextInt ();
                                            }
                                            bigNTastyTotal = bigNTastyQuant * 172.00 + bigNTastyQuant2 * 152.00;
                                            orderRepeater ();
                                            bigNTastyChoice2 = input.nextInt ();
                                            System.out.println ("        **==========================================**");
                                        } while (bigNTastyChoice2 == 1); 
                                    }
                                    else if (choice6 == 3) {
                                        do {
                                            mealCycle ();
                                            qPoundChoice = input.nextInt ();
                                            System.out.println ("        **==========================================**");
                                            if (qPoundChoice == 1 ) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                qPoundQuant = input.nextInt ();
                                            }
                                            else if (qPoundChoice == 2 ) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                qPoundQuant2 = input.nextInt ();
                                            }
                                            qPoundTotal = qPoundQuant * 169.00 + qPoundQuant2 * 149.00;
                                            orderRepeater ();
                                            qPoundChoice2 = input.nextInt ();
                                            System.out.println ("        **==========================================**");
                                        } while (qPoundChoice2 == 1);
                                    }
                                    else if (choice6 == 4) {
                                        do {
                                            System.out.println ("    ||1 FOR REGULAR 2 FOR DELUXE");
                                            System.out.print ("        ||ENTER QUANTITY: ");
                                            mcDoubleRegOrDeluxe = input.nextInt ();
                                            if (mcDoubleRegOrDeluxe == 1) {
                                                do {
                                                    mealCycle ();
                                                    mcDoubleChoice = input.nextInt ();
                                                    System.out.println ("        **==========================================**");
                                                    if (mcDoubleChoice == 1 ) {
                                                        System.out.print ("        ||ENTER QUANTITY: ");
                                                        mcDoubleQuant = input.nextInt ();
                                                    }
                                                    else if (mcDoubleChoice == 2 ) {
                                                        System.out.print ("        ||ENTER QUANTITY: ");
                                                        mcDoubleQuant2 = input.nextInt ();
                                                    }
                                                    orderRepeater ();
                                                    mcDoubleChoice2 = input.nextInt ();
                                                    System.out.println ("        **==========================================**");
                                                } while (mcDoubleChoice2 == 1);
                                            }
                                            else if (mcDoubleRegOrDeluxe == 2) {
                                                do {
                                                    mealCycle ();
                                                    mcDoubleChoice3 = input.nextInt ();
                                                    System.out.println ("        **==========================================**");
                                                    if (mcDoubleChoice3 == 1 ) {
                                                        System.out.print ("        ||ENTER QUANTITY: ");
                                                        mcDoubleQuant3 = input.nextInt ();
                                                    }
                                                    else if (mcDoubleChoice3 == 2 ) {
                                                        System.out.print ("        ||ENTER QUANTITY: ");
                                                        mcDoubleQuant4 = input.nextInt ();
                                                    }
                                                    mcDoubleTotal = mcDoubleQuant * 130.00 + mcDoubleQuant2 * 110.00 + mcDoubleQuant3 * 155.00 + mcDoubleQuant4 * 135.00;
                                                    orderRepeater ();
                                                    mcDoubleChoice4 = input.nextInt ();
                                                    System.out.println ("        **==========================================**");
                                                } while (mcDoubleChoice4 == 1);   
                                            }
                                            System.out.println ("        ||RETURN TO TYPE SELECTION? ");
                                            System.out.println ("        ||1 FOR YES 2 FOR NO");
                                            System.out.print ("        ||Enter choice: ");
                                            mcDoubleRegOrDeluxe2 = input.nextInt ();
                                        }while (mcDoubleRegOrDeluxe2 == 1);
                                    }
                                    else if (choice6 == 5) {
                                        do {
                                            System.out.println ("\n        **==========================================**");
                                            System.out.println ("            1 W/MEDIUM FRIES & MEDIUM SOFTDRINK");
                                            System.out.println ("            2 w/REGULAR FRIES & REGULAR SOFTDRINK");
                                            System.out.println ("            3 w/SHAKE SHAKE FRIES & REGULAR SOFTDRINK");
                                            System.out.println ("        **==========================================**");
                                            System.out.println ("\n        **==========================================**");
                                            System.out.print ("        ||Enter choice: ");
                                            mcSpicyChoice = input.nextInt ();
                                            if (mcSpicyChoice == 1 ) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                mcSpicyQuant = input.nextInt ();
                                            }
                                            else if (mcSpicyChoice == 2 ) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                mcSpicyQuant2 = input.nextInt ();
                                            }
                                            else if (mcSpicyChoice == 3) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                mcSpicyQuant3 = input.nextInt ();
                                            }
                                            mcSpicyTotal = mcSpicyQuant * 151.00 + mcSpicyQuant2 * 141.00 + mcSpicyQuant3 * 121.00;
                                            orderRepeater ();
                                            mcSpicyChoice2 = input.nextInt ();
                                            System.out.println ("        **==========================================**");
                                        } while (mcSpicyChoice2 == 1);
                                    }
                                    else if (choice6 == 6) {
                                        do {
                                            System.out.println ("\n        **==========================================**");
                                            System.out.println ("            1 FOR 6PC MC NUGGETS w/MEDIUM FRIES");
                                            System.out.println ("            2 FOR 6PC MC NUGGETS w/MEDIUM SOFTDRINK");
                                            System.out.println ("            3 FOR 6PC MC NUGGETS w/REGULAR SOFTDRINK");
                                            System.out.println ("            4 FOR 6PC MC NUGGETS w/REG. FRIES & SOFTDRINK");
                                            System.out.println ("        **==========================================**");
                                            System.out.println ("\n        **==========================================**");
                                            System.out.print ("        ||Enter choice: ");
                                            mcNuggetChoice = input.nextInt ();
                                            if (mcNuggetChoice == 1) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                mcNuggetQuant = input.nextInt ();
                                            }
                                            else if (mcNuggetChoice == 2 ) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                mcNuggetQuant2 = input.nextInt ();
                                            }
                                            else if (mcNuggetChoice == 3) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                mcNuggetQuant3 = input.nextInt ();
                                            }
                                            else if (mcNuggetChoice == 4) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                mcNuggetQuant4 = input.nextInt ();
                                            }
                                            mcNuggetTotal = mcNuggetQuant * 146.00 + mcNuggetQuant2 * 132.00 + mcNuggetQuant3 * 125.00 + mcNuggetQuant4 * 120.00;
                                            orderRepeater ();
                                            mcNuggetChoice2 = input.nextInt ();
                                            System.out.println ("        **==========================================**");
                                        } while (mcNuggetChoice2 == 1);
                                    }   
                                    else if (choice6 == 7 ) {
                                        do {
                                            mealCycle ();
                                            filetOFishChoice = input.nextInt ();
                                            System.out.println ("        **==========================================**");
                                            if (filetOFishChoice == 1 ) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                filetOFishQuant = input.nextInt ();
                                            }
                                            else if (filetOFishChoice == 2 ) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                filetOFishQuant2 = input.nextInt ();
                                            }
                                            filetOFishTotal = filetOFishQuant * 143.00 + filetOFishQuant2 * 123.00;
                                            orderRepeater ();
                                            filetOFishChoice2 = input.nextInt ();
                                            System.out.println ("        **==========================================**");
                                        } while (filetOFishChoice2 == 1);
                                    }
                                    else if (choice6 == 8) {
                                        do {
                                            mealCycle ();
                                            mcChickenSandwichChoice = input.nextInt ();
                                            System.out.println ("        **==========================================**");
                                            if (mcChickenSandwichChoice == 1 ) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                mcChickenSandwichQuant = input.nextInt ();
                                            }
                                            else if (mcChickenSandwichChoice == 2 ) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                mcChickenSandwichQuant2 = input.nextInt ();
                                            }
                                            mcChickenSandwichTotal = mcChickenSandwichQuant * 143.00 + mcChickenSandwichQuant2 * 123.00;
                                            orderRepeater ();
                                            mcChickenSandwichChoice2 = input.nextInt ();
                                            System.out.println ("        **==========================================**");
                                        } while (mcChickenSandwichChoice2 == 1);
                                    } 
                                    else if (choice6 == 9) {
                                        do {
                                            mealCycle ();
                                            chickenMcdoAndFriesChoice = input.nextInt ();
                                            System.out.println ("        **==========================================**");
                                            if (chickenMcdoAndFriesChoice == 1 ) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                chickenMcdoAndFriesQuant = input.nextInt ();
                                            }
                                            else if (chickenMcdoAndFriesChoice == 2 ) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                chickenMcdoAndFriesQuant2 = input.nextInt ();
                                            }
                                            chickenMcdoAndFriesTotal = chickenMcdoAndFriesQuant * 159.00 + chickenMcdoAndFriesQuant2 * 149.00;
                                            orderRepeater ();
                                            chickenMcdoAndFriesChoice2 = input.nextInt ();
                                            System.out.println ("        **==========================================**");
                                        } while (chickenMcdoAndFriesChoice2 == 1);                          
                                    }
                                    System.out.println ("\n        ***********************************");                                
                                    System.out.println ("        ||ADD ANOTHER MEAL(S)?");
                                    System.out.println ("        ||1 FOR YES 2 FOR NO");                                
                                    System.out.print ("        ||Enter choice: ");
                                    choice7 = input.nextInt ();
                                    mealTotal = bigMcTotal + bigNTastyTotal + qPoundTotal + mcDoubleTotal + mcSpicyTotal + mcNuggetTotal + filetOFishTotal + mcChickenSandwichTotal + chickenMcdoAndFriesTotal;
                                } while (choice7 == 1);
                            }
                        else if (choice2 == 3) {
                            do {
                                System.out.println ("\n        **---------------------------------**");
                                System.out.println ("         *---------------------------------* ");
                                System.out.println ("        ||              DESSERTS           ||");
                                System.out.println ("         *---------------------------------* ");
                                System.out.println ("        *|  1 FOR HOT FUDGE                |*");
                                System.out.println ("        ||  2 FOR SUNDAE                   ||");
                                System.out.println ("        *|  3 FOR MC FLURRY                 |*");
                                System.out.println ("         *---------------------------------* "); 
                                System.out.println ("        **---------------------------------**");
                                System.out.println ("\n        *************************************");
                                System.out.print ("        ||Enter choice: ");
                                choice8 = input.nextInt ();
                                System.out.println ("        *************************************");
                                    if (choice8 == 1) {
                                        do {
                                            System.out.println ("\n        **==========================================**");
                                            System.out.println ("            1 FOR CARAMEL");
                                            System.out.println ("            2 FOR UPSIZED CARAMEL");
                                            System.out.println ("            3 FOR CHOCOLATE");
                                            System.out.println ("            4 FOR UPSIZED CHOCOLATE");
                                            System.out.println ("            5 FOR STRAWBERRY");
                                            System.out.println ("            6 FOR UPSIZED STRAWBERRY");
                                            System.out.println ("        **==========================================**");
                                            System.out.println ("\n        **==========================================**");
                                            System.out.print ("        ||Enter choice: ");
                                            hotFudgeFlavorChoice = input.nextInt ();
                                            if (hotFudgeFlavorChoice == 1) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                hotFudgeQuant = input.nextInt ();
                                            }
                                            else if (hotFudgeFlavorChoice == 2 ) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                hotFudgeQuant2 = input.nextInt ();
                                            }
                                            else if (hotFudgeFlavorChoice == 3) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                hotFudgeQuant3 = input.nextInt ();
                                            }
                                            else if (hotFudgeFlavorChoice == 4) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                hotFudgeQuant4 = input.nextInt ();
                                            }                                            
                                            else if (hotFudgeFlavorChoice == 5) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                hotFudgeQuant5 = input.nextInt ();
                                            }
                                            else if (hotFudgeFlavorChoice == 6) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                hotFudgeQuant6 = input.nextInt ();
                                            }
                                            hotFudgeTotal = hotFudgeQuant * 25.00 + hotFudgeQuant2 * 25.00 + hotFudgeQuant3 *25.00 + hotFudgeQuant4 * 25.00 + hotFudgeQuant5 * 25.00 + hotFudgeQuant6 * 25.00;
                                            System.out.println ("        ||ADD ANOTHER FLAVOR(S)?");
                                            System.out.println ("        ||1 FOR YES 2 FOR NO");
                                            System.out.print ("        ||Enter choice: ");
                                            hotFudgeChoice2 = input.nextInt ();
                                            System.out.println ("        **==========================================**");
                                        } while (hotFudgeChoice2 == 1);
                                    }
     
                                    else if (choice8 == 2) {
                                        do {
                                            System.out.println ("\n        **==========================================**");
                                            System.out.println ("            1 FOR CARAMEL");
                                            System.out.println ("            2 FOR CHOCOLATE");
                                            System.out.println ("            3 FOR STRAWBERRY");
                                            System.out.println ("        **==========================================**");
                                            System.out.println ("\n        **==========================================**");
                                            System.out.print ("        ||Enter choice: ");
                                            sundaeFlavorChoice = input.nextInt ();
                                            if (sundaeFlavorChoice == 1) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                sundaeFlavorQuant = input.nextInt ();
                                            }
                                            else if (sundaeFlavorChoice == 2 ) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                sundaeFlavorQuant2 = input.nextInt ();
                                            }
                                            else if (sundaeFlavorChoice == 3) {
                                                System.out.print ("        ||ENTER QUANTITY: ");
                                                sundaeFlavorQuant3 = input.nextInt ();
                                            }
                                            sundaeFlavorTotal = (sundaeFlavorQuant + sundaeFlavorQuant2 + sundaeFlavorQuant3) * 25.00;
                                            System.out.println ("        ||ADD ANOTHER FLAVOR(S)?");
                                            System.out.println ("        ||1 FOR YES 2 FOR NO");
                                            System.out.print ("        ||Enter choice: ");
                                            sundaeFlavorChoice2 = input.nextInt ();
                                            System.out.println ("        **==========================================**");
                                        } while (sundaeFlavorChoice2 == 1); 
                                    }
                                    else if (choice8 == 3) {                                    
                                        System.out.println ("\n        **==========================================**");
                                        System.out.println ("            FLAVOR OF THE DAY IS COOKIES & CREAM");
                                        System.out.println ("        **==========================================**");
                                        System.out.println ("\n        **==========================================**");
                                        System.out.print ("        ||Enter QUANTITY: ");
                                        mcTwirlQuant = input.nextInt ();
                                        System.out.println ("        **==========================================**");
                                    } 
                                mcTwirlTotal = mcTwirlQuant * 30.00;
                                System.out.println ("**********************");                                
                                System.out.print ("ADD ANOTHER DESSERT(S)?");
                                System.out.print ("\n1 FOR YES 2 FOR NO");                                
                                System.out.print ("\nEnter choice: ");
                                choice9 = input.nextInt ();
                            } while (choice9 == 1);
                        }
                        System.out.println ("        ||RETURN TO FOOD TYPE SELECTION? ");
                        System.out.println ("        ||1 FOR YES 2 FOR NO");
                        System.out.print ("        ||Enter choice: ");
                        choice5 = input.nextInt ();
                        System.out.println ("        ***********************************");
                        dessertTotal = hotFudgeTotal + sundaeFlavorTotal + mcTwirlTotal;
                    } while (choice5 == 1);
                totalTotal = bevTotal + mealTotal + dessertTotal;
                System.out.print ("        ENTER AMOUNT TENDERED: ");
                amountTendered = input.nextDouble ();
                System.out.println ("\n \n              *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~* ");
                System.out.println ("              |**||**       WC DONALDS      **||**| ");
                System.out.println ("              *~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~* ");
                System.out.println ("\n                       OFFICIAL INVIOCE           ");
                System.out.println ("\n        **==========================================**");
                System.out.println ("           THE TOTAL AMOUNT YOU HAVE ORDERED IS: " + totalTotal);
                System.out.println ("           AMOUNT TENDERED IS:" + amountTendered);
                System.out.println ("        **==========================================**");
                change = amountTendered - totalTotal;
                System.out.println ("        CHANGE: " + change);
                }
        }
     
    public static void mealCycle () {
        System.out.println ("\n        **==========================================**");
        System.out.println ("            1 W/MEDIUM FRIES & MEDIUM SOFTDRINK");
        System.out.println ("            2 w/REGULAR FRIES & REGULAR SOFTDRINK");
        System.out.println ("        **==========================================**");
        System.out.println ("\n        **==========================================**");
        System.out.print ("        ||Enter choice: ");
        }
    public static void orderRepeater () {
        System.out.println ("        ||ORDER FOR THE OTHER SIZE? ");
        System.out.println ("        ||1 FOR YES 2 FOR NO");
        System.out.print ("        ||Enter choice: "); 
        }
    }

    the code above is just short and an overview i removed the declarations part because of text limits.
    and

    as you can see in the official invoice the only thing that will be printed is the cash invoice and the total.

    i want to see the items that the user orders and be printed in the Official Invoice part and same as the quantity just like the official I.O of the MCDONALDS! thanks! and more power!


  2. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,520
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Cash register

    Welcome to the forum! Thanks for taking the time to learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.

    Wow!

    I assume the first 400 or so lines of code is the main() method. Correct? Most of the code in the main() method should be moved to other methods. You might have methods that get sandwiches, drinks, sides, meals, etc., each method doing one thing and one thing only, each with its own repeating, error handling, etc.

    I doubt you'll take that advice, so to your original question, there is really only one solution: keep track of the items ordered and output them on the invoice. It's not clear what tools you can use to do that, but a String, a String array, or a StringBuilder object are possible choices in which to collect the items ordered. Since I think the String option might be the only tool in your box at the moment, it would work something like:

    Item ordered: Hamburger Happy Meal with Extra Fat

    // previously declared: String orderedString;
    orderedString += "Hamburger Happy Meal with Extra Fat" + "\n";

    repeating for each item ordered.

    In this way, each item ordered is added to the orderedString object. Then when the invoice is printed, the orderedString object is output. Now, if you want to add the details like quantity and price after each item ordered in the orderedString object, that becomes more complicated, and the String approach might not work. It's a start.

  3. The Following 2 Users Say Thank You to GregBrannon For This Useful Post:

    Ada Lovelace (July 20th, 2014), itzmexei (July 20th, 2014)

  4. #3
    Junior Member
    Join Date
    Jul 2014
    Posts
    14
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Cash register

    Quote Originally Posted by GregBrannon View Post
    Welcome to the forum! Thanks for taking the time to learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.

    Wow!

    I assume the first 400 or so lines of code is the main() method. Correct? Most of the code in the main() method should be moved to other methods. You might have methods that get sandwiches, drinks, sides, meals, etc., each method doing one thing and one thing only, each with its own repeating, error handling, etc.

    I doubt you'll take that advice, so to your original question, there is really only one solution: keep track of the items ordered and output them on the invoice. It's not clear what tools you can use to do that, but a String, a String array, or a StringBuilder object are possible choices in which to collect the items ordered. Since I think the String option might be the only tool in your box at the moment, it would work something like:

    Item ordered: Hamburger Happy Meal with Extra Fat

    // previously declared: String orderedString;
    orderedString += "Hamburger Happy Meal with Extra Fat" + "\n";

    repeating for each item ordered.

    In this way, each item ordered is added to the orderedString object. Then when the invoice is printed, the orderedString object is output. Now, if you want to add the details like quantity and price after each item ordered in the orderedString object, that becomes more complicated, and the String approach might not work. It's a start.
    thank you very much i do get what your point is! YEY!

  5. #4
    Junior Member
    Join Date
    Jul 2014
    Posts
    14
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Cash register

    Quote Originally Posted by GregBrannon View Post
    Welcome to the forum! Thanks for taking the time to learn how to post code correctly. If you haven't already, please read this topic to learn other useful info for new members.

    Wow!

    I assume the first 400 or so lines of code is the main() method. Correct? Most of the code in the main() method should be moved to other methods. You might have methods that get sandwiches, drinks, sides, meals, etc., each method doing one thing and one thing only, each with its own repeating, error handling, etc.

    I doubt you'll take that advice, so to your original question, there is really only one solution: keep track of the items ordered and output them on the invoice. It's not clear what tools you can use to do that, but a String, a String array, or a StringBuilder object are possible choices in which to collect the items ordered. Since I think the String option might be the only tool in your box at the moment, it would work something like:

    Item ordered: Hamburger Happy Meal with Extra Fat

    // previously declared: String orderedString;
    orderedString += "Hamburger Happy Meal with Extra Fat" + "\n";

    repeating for each item ordered.

    In this way, each item ordered is added to the orderedString object. Then when the invoice is printed, the orderedString object is output. Now, if you want to add the details like quantity and price after each item ordered in the orderedString object, that becomes more complicated, and the String approach might not work. It's a start.
    about the one with the quantity can you tell me i know you said that it can be more complicated but try me! haha! i dont get 1 for programming with just nothing! ^_^

  6. #5
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: Cash register

    One way is to declare a integer variable to store each type of
    product. Say if you had six products, you could declare six
    separate integer variables which each store the quantity purchased
    of each product.

    There are of course more productive ways of achieving the same things
    like using an array for example, but this is one of the most simplistic.

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  7. The Following User Says Thank You to Ada Lovelace For This Useful Post:

    itzmexei (July 20th, 2014)

  8. #6
    Junior Member
    Join Date
    Jul 2014
    Posts
    14
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Cash register

    Quote Originally Posted by Ada Lovelace View Post
    One way is to declare a integer variable to store each type of
    product. Say if you had six products, you could declare six
    separate integer variables which each store the quantity purchased
    of each product.

    There are of course more productive ways of achieving the same things
    like using an array for example, but this is one of the most simplistic.

    Wishes Ada xx
    haha uhmm you dont get it! XD the problem is the quantity that will be displayed in invoice XD i do get the quantity for each of the items. i was just having a mental block this days that i cant think properly and deadline is coming near XD

    thanks tho! (Y)

  9. #7
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: Cash register

    That's more or less what I meant. For example, if your output
    is like this:

    Item Quantity Price
    Fries 2 0.99
    Burger 1 0.99
    Total: 1.98


    Then for the invoice to show how many of each product was sold
    you could print the gathered variable value that represented the
    quantity (and price for that matter) - in a similar manor to the
    product description.

    Apologises if this is still not what you meant.

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  10. The Following User Says Thank You to Ada Lovelace For This Useful Post:

    itzmexei (July 20th, 2014)

  11. #8
    Junior Member
    Join Date
    Jul 2014
    Posts
    14
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Cash register

    Quote Originally Posted by Ada Lovelace View Post
    That's more or less what I meant. For example, if your output
    is like this:

    Item Quantity Price
    Fries 2 0.99
    Burger 1 0.99
    Total: 1.98


    Then for the invoice to show how many of each product was sold
    you could print the gathered variable value that represented the
    quantity (and price for that matter) - in a similar manor to the
    product description.

    Apologises if this is still not what you meant.

    Wishes Ada xx
    unless i misinterpret you but what your saying is easy if you only have a hand countable items and you want all to be printed in the invoice but what if you only wanted to print are the things you ordered and you got hundreds of items in your menu? hope you get my point? XD

  12. #9
    Member Ada Lovelace's Avatar
    Join Date
    May 2014
    Location
    South England UK
    Posts
    414
    My Mood
    Angelic
    Thanks
    27
    Thanked 61 Times in 55 Posts

    Default Re: Cash register

    One way to do that (and it's quite an advanced Java concept)
    would be to create a text file (txt) which stores the entire menu.
    Then write a program that would interact with the text file and print
    the menu to the screen. (Using file write and read algorithms).

    The user could pick the items he/she wanted, and the quantity of the
    items, and then have the program read from the file only the menu items selected by
    the user and display them on the invoice, along with the quantity ordered
    and their individual pricing, in the list format you specify.

    Wishes Ada xx
    If to Err is human - then programmers are most human of us all.
    "The Analytical Engine offers a new, a vast, and a powerful language . . .
    for the purposes of mankind
    ."
    Augusta Ada Byron, Lady Lovelace (1851)

  13. The Following User Says Thank You to Ada Lovelace For This Useful Post:

    itzmexei (July 20th, 2014)

  14. #10
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Cash register

    What would the textfile be needed for?

    I am sorry, but to be honest, I still dont exactly understand what the problem is.
    I see that you know how to print something to screen. And you seem to understand how variables work.
    What exactly do you have problems with?

    By the way, perhaps an OOP approach would be good for a task like this.

  15. The Following User Says Thank You to Cornix For This Useful Post:

    itzmexei (July 20th, 2014)

  16. #11
    Junior Member
    Join Date
    Jul 2014
    Posts
    14
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Cash register

    Quote Originally Posted by Ada Lovelace View Post
    One way to do that (and it's quite an advanced Java concept)
    would be to create a text file (txt) which stores the entire menu.
    Then write a program that would interact with the text file and print
    the menu to the screen. (Using file write and read algorithms).

    The user could pick the items he/she wanted, and the quantity of the
    items, and then have the program read from the file only the menu items selected by
    the user and display them on the invoice, along with the quantity ordered
    and their individual pricing, in the list format you specify.

    Wishes Ada xx
    ok so i guess that's way out of our lessons and i doubt i would need that tho thanks for your help i might study in advance for that

    Quote Originally Posted by Cornix View Post
    What would the textfile be needed for?

    I am sorry, but to be honest, I still dont exactly understand what the problem is.
    I see that you know how to print something to screen. And you seem to understand how variables work.
    What exactly do you have problems with?

    By the way, perhaps an OOP approach would be good for a task like this.
    actually we are in OOP! >.< and anyways on what my problem is this:

    in the code above my problem is showing what was ordered and how many did he/she ordered.
    and so i managed to print what he/she ordered in the I.O part but i dont get how would I also include on how many items did he/she ordered for the specified item.
    ex.
    the user ordered FRIES FLOAT and SUNDAE the IO should have look like similar to this:

    5 X REGULAR FRIES 125.00
    2 X MC FLOAT 50.00
    3 X SUNDAE 75.00
    -----------------------------
    total 250.00

    i already got on how would i display the total price and the items ordered just displaying it's price and the quantity ordered per item.
    hope you got my problem now >.<

  17. #12
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Cash register

    The program does not look OOP in the slightest. The methods are static (completely against OOP paradigm) and all code is put into one huge method that does everything.

    You said you know how to display the total price, but in order to calculate this price you should also know the quantities of the articles.
    Total price should be something like:
    totalPrice = 0;
     
    for (Item in Buy-List) do
        totalPrice += Item.cost * Item.quantity;
    end-for
     
    return totalPrice
    In this case I dont see what the problem is.

  18. The Following User Says Thank You to Cornix For This Useful Post:

    itzmexei (July 21st, 2014)

  19. #13
    Junior Member
    Join Date
    Jul 2014
    Posts
    14
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Re: Cash register

    Quote Originally Posted by Cornix View Post
    The program does not look OOP in the slightest. The methods are static (completely against OOP paradigm) and all code is put into one huge method that does everything.

    You said you know how to display the total price, but in order to calculate this price you should also know the quantities of the articles.
    Total price should be something like:
    totalPrice = 0;
     
    for (Item in Buy-List) do
        totalPrice += Item.cost * Item.quantity;
    end-for
     
    return totalPrice
    In this case I dont see what the problem is.
    i know it was not yet in OOP approach we are still in the SA that's why. and anyways i dont understand why people dont get my point >.<
    anyhow i'll try to solve my own problem XD

    but i was just wondering and this is an off topic hope they allow this but.

    how do you make java to clear the "windows console"? example:

    enter input: 1

    the user will input the "1" then after he/she hit's the enter the "enter input: 1" will be cleared and the console will display another list of outputs..

    is that possible? if i remember it right it was possible in c# or c++ perhaps? the cls or clr command or a like? in java is that possible?

  20. #14
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Cash register

    You have no control over the console, its a completey different and independent program.
    In java its only a PrintStream. You can re-route the output to anything else, so clearing doesnt make sense.

    What you can do is just print a bunch of empty lines if you like to push the old output back.

Similar Threads

  1. Cash Register Simulation Help
    By Gont in forum Object Oriented Programming
    Replies: 1
    Last Post: September 22nd, 2012, 06:58 PM
  2. bit array and register problem
    By ryu2le in forum What's Wrong With My Code?
    Replies: 35
    Last Post: August 31st, 2011, 10:52 PM
  3. How to validate username?this my register.jsp
    By surendran610 in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: August 22nd, 2011, 01:42 AM
  4. Cash Register Exercise
    By Consus in forum What's Wrong With My Code?
    Replies: 0
    Last Post: February 19th, 2010, 11:52 PM