Very accurate
Very accurate
import java.util.*; public class cart { //To publicly access the quantity as it updates every time you wish to buy again public static int total_quantity=0; //I have declared 4 products here "2.) One-Percenter (2-Stacks of Quarter Pounder Patty) 99.00", "3.) Tombstone Piledriver (3 Stacks of Quarter Pounder Patty) 150.00", "4.) God's Last Gift (Tombstone Burger with 100g of Carolina Reaper) 200.00"}; //Prices in accordance of their elements public static int[] product_price ={0,50,99,150,200}; //This is the cart for the check-out of all order you have public static int[] final_qty=new int[5]; { int choose, quantity; int p1=0; int p2=0; int p3=0; int p4=0; char decision; do { for(int i = 0; i < products.length; i++) { if(products[i] != null) } choose=s.nextInt(); quantity=s.nextInt(); switch(choose) { case 1: p1 += quantity; final_qty[1]=p1; break; case 2: p2 += quantity; final_qty[2]=p2; break; case 3: p3 += quantity; final_qty[3]=p3; break; case 4: p4 += quantity; final_qty[4]=p4; break; } decision=s.next().charAt(0); }while(decision != 'n' && decision != 'N'); int sum=0; for(int i=0; i < final_qty.length; i++) { if(final_qty[i] != 0) { sum = sum + final_qty[i]*product_price[i]; } } int payment=0; do { payment=s.nextInt(); }while(sum > payment); } }
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.