Simple Ordering System (Console)

Language

I have my original program of this using the concept of stacks however, I find it difficult on updating the elements of the array. Instead of using the same concept, I've modified it and made it just to a static array with fixed elements. I hope this program/concept could help in your activities/projects.
  1. import java.util.*;
  2.  
  3. public class cart
  4. {
  5. //To publicly access the quantity as it updates every time you wish to buy again
  6. public static int total_quantity=0;
  7. //I have declared 4 products here
  8. public static String[] products = {null, "1.) Quarter-Pounder Burger 50.00",
  9. "2.) One-Percenter (2-Stacks of Quarter Pounder Patty) 99.00",
  10. "3.) Tombstone Piledriver (3 Stacks of Quarter Pounder Patty) 150.00",
  11. "4.) God's Last Gift (Tombstone Burger with 100g of Carolina Reaper) 200.00"};
  12. //Prices in accordance of their elements
  13. public static int[] product_price ={0,50,99,150,200};
  14. //This is the cart for the check-out of all order you have
  15. public static int[] final_qty=new int[5];
  16.  
  17. public static void main(String[] args)
  18. {
  19. Scanner s = new Scanner(System.in);
  20. int choose, quantity;
  21. int p1=0;
  22. int p2=0;
  23. int p3=0;
  24. int p4=0;
  25. char decision;
  26. System.out.println("Welcome to Burger TK, please choose any of the menu there..");
  27. do
  28. {
  29.  
  30. for(int i = 0; i < products.length; i++)
  31. {
  32. if(products[i] != null)
  33. System.out.println(products[i]);
  34. }
  35.  
  36. System.out.print("Choose any item: ");
  37. choose=s.nextInt();
  38.  
  39. System.out.print("How many pieces? ");
  40. quantity=s.nextInt();
  41.  
  42. switch(choose)
  43. {
  44. case 1:
  45. p1 += quantity;
  46. final_qty[1]=p1;
  47. break;
  48.  
  49. case 2:
  50. p2 += quantity;
  51. final_qty[2]=p2;
  52. break;
  53.  
  54. case 3:
  55. p3 += quantity;
  56. final_qty[3]=p3;
  57. break;
  58.  
  59. case 4:
  60. p4 += quantity;
  61. final_qty[4]=p4;
  62. break;
  63. }
  64. System.out.print("Would you like to order again? Y/N / y/n: ");
  65. decision=s.next().charAt(0);
  66. }while(decision != 'n' && decision != 'N');
  67.  
  68. System.out.println("==Final Cart==");
  69. System.out.println("\t\\Item\t\\Qty\t\\Total");
  70. int sum=0;
  71. for(int i=0; i < final_qty.length; i++)
  72. {
  73. if(final_qty[i] != 0)
  74. {
  75. System.out.println(products[i]+"\\"+final_qty[i]+"\\"+final_qty[i]*product_price[i]);
  76. sum = sum + final_qty[i]*product_price[i];
  77. }
  78. }
  79. System.out.println("Total Purchased items: "+(p1+p2+p3+p4));
  80. System.out.println("Total Purchase: "+sum);
  81. int payment=0;
  82. do
  83. {
  84. System.out.print("Enter Payment: ");
  85. payment=s.nextInt();
  86. }while(sum > payment);
  87. System.out.println("Thank you for buying! here's your change: "+(payment-sum));
  88. }
  89.  
  90. }
PS: I have modified some of its content. I just changed the name of some products but still, it is the same program.

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by SourceCodester.com for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.

FOR YOUR OWN SAFETY, PLEASE:

1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.

Comments

Submitted byAnonymous (not verified)on Wed, 05/11/2022 - 08:36

Very accurate

Add new comment