Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Humza Hnesh
- // CS0401
- // Tuesday/Thursday 9:30-10:45 AM
- /* My program is not very robust and does not work 100% as the assignment formatted.
- I had many issues with running back through my loops when I inputted a value that was
- incorrect. Thus, my program is filled with many work arounds rather than addressing the
- real problem (unfortunately). When handling exceptions, I often exited or re-ran the loops
- entirely...
- */
- import java.util.Scanner;
- public class Assignment1CS0401 {
- public static void main(String[] args) {
- Scanner inScan=new Scanner(System.in);
- Scanner inScan2=new Scanner(System.in);
- Scanner inScan3=new Scanner(System.in);
- Scanner inScan4=new Scanner(System.in);
- Scanner inScan5=new Scanner(System.in);
- Scanner inScan6=new Scanner(System.in);
- Scanner inScan7=new Scanner(System.in);
- Scanner inScan8=new Scanner(System.in);
- Scanner inScan9=new Scanner(System.in);
- Scanner inScan10=new Scanner(System.in);
- Scanner inScan11=new Scanner(System.in);
- Scanner inScan12=new Scanner(System.in);
- boolean registerloop = false;
- // I created many Scanners because I wanted to store the values I scanned progressively
- // and I feared that I would erase values I needed
- String passwordIn = "a";
- int customer = 1;
- int update;
- int update2=0;
- int update3=0;
- int update4=0;
- int update5=0;
- int order1=0;
- int order2=0;
- int order3=0;
- int order4=0;
- int total_value = 0;
- int total_value2 = 0;
- int total_value3 = 0;
- int butterval = 0;
- int butterval2 = 0;
- int remainder = 0;
- int difference = 0;
- int bag_count = 0;
- int totally = 0;
- int totallydiscountprice = 0;
- int totallydiscount = 0;
- int firstNum = 0;
- //initialized my variables outside so didn't have to worry about scope
- String firstString = " ";
- do
- {
- System.out.println("Welcome to Dumbledore's Delicious Delicacies!");
- System.out.println("Is there a customer in line? ( 1 = yes, 2 = no) >");
- customer = inScan.nextInt();
- if (customer==2){
- System.out.println("Thank you!");
- }
- else {
- System.out.println("What is the password? ");
- passwordIn = inScan2.nextLine();
- String password1 = "Dumbledore's Army";
- int attempts = 1;
- do
- {
- if (password1.equals(passwordIn))
- {
- System.out.println("Welcome Dumbledore's Army member!");
- System.out.println("You will get special discounts at DDD!! ");
- System.out.println(" Discount on bags of Cauldron Cakes");
- System.out.println(" Discount on Chocolate Frogs");
- System.out.println(" Small or Large Butterbeer - same price");
- System.out.println(" ");
- System.out.println("Here is our price list:");
- System.out.println(" Cauldron Cakes (each) 10 Knuts");
- System.out.println(" Cauldron Cakes (bag of 6) 50 Knuts");
- System.out.println(" Chocolate Frogs (each) 15 Knuts");
- System.out.println(" Butterbeer (small) 50 Knuts ");
- System.out.println(" Butterbeer (large) 50 Knuts ");
- System.out.println(" ");
- // used tabs to format output
- do{
- System.out.println("1) Update Cauldron Cakes Order");
- System.out.println("2) Update Chocolate Frogs Order");
- System.out.println("3) Update Butterbeer Order");
- System.out.println("4) Check Out");
- update = inScan3.nextInt();
- if (update == 1 )
- {
- System.out.println("Here is your current order");
- System.out.println(order1);
- System.out.println("How many Cauldron Cakes would you like for: ");
- System.out.println(" 10 Knuts per cake");
- System.out.println(" 50 Knuts per bag of 6");
- System.out.println("(Please indicate only the total amount of cakes you would like to buy): ");
- order1 = order1 + inScan4.nextInt();
- remainder = order1 % 6;
- difference = order1 - remainder;
- bag_count = difference/6;
- total_value = (remainder * 10 ) + (bag_count * 50);
- }
- else if (update == 2)
- {
- System.out.println("Here is your current order");
- System.out.println(order2);
- System.out.println("How many chocolate frogs would you like for 15 Knuts each?: ");
- order2 = order2 + inScan5.nextInt();
- total_value2 = order2 * 15;
- }
- else if (update == 3)
- {
- System.out.println("Here is your current order");
- System.out.println(order3 + order4);
- System.out.println("How many small Butterbeers would you like for 50 Knuts each?: ");
- order3 = order3 + inScan6.nextInt();
- butterval = order3 * 50;
- System.out.println("How many large Butterbeers would you like for 50 Knuts each?: ");
- order4 = order4 + inScan7.nextInt();
- butterval2 = order4 * 50;
- total_value3= butterval + butterval2;
- }
- }
- while ( update !=4);
- totally = total_value+total_value2+total_value3;
- totallydiscount = totally/10;
- totallydiscountprice= totally - (totallydiscount);
- System.out.println("Here is your subtotal");
- System.out.println(" " + bag_count + " bags of Cauldron cakes at 50 Knuts ea. " +(bag_count * 50 ));
- System.out.println(" " + remainder + " Cauldron cakes at 10 Knuts ea.: " + (remainder *10));
- System.out.println(" " + order2 + " Chocolate Frogs at 15 Knuts ea.: " + total_value2 );
- System.out.println(" " + order3 + " Small Butterbeers at 50 Knuts ea.: " + butterval);
- System.out.println(" " + order4 + " Large Butterbeers at 50 Knuts ea.: " + butterval2);
- System.out.println(" ");
- System.out.println(" " + " Total: " + totally);
- System.out.println(" " + " Bonus Discount of 10%!: " + totallydiscount);
- System.out.println(" " + " New Total: " + totallydiscountprice);
- System.out.println(" ");
- // used tabs to format output
- System.out.println("Please enter your payment amount in the following format: ");
- System.out.println(" <amount><space><currency>");
- System.out.println(" Where <amount> = an integer");
- System.out.println(" Where <currency> = {Knuts, Sickles, Galleons}");
- System.out.println(" > ");
- String userInput = inScan12.nextLine();
- int positionOfSpace = userInput.indexOf(" "); //I used this to find the position of the space in order to know where to parse for the values before and after
- String num = userInput.substring(0, positionOfSpace); //Grabs the "number" that is currently a string
- int payment = Integer.parseInt(num); // Because the value is initially a string, used this to make the number into int
- String txt = userInput.substring(positionOfSpace + 1); //Grab the currency type
- // this way I handle users that want to be difficult and type capital letters vs lowercase letters
- txt = txt.toLowerCase();
- do {
- if (txt.equals("galleons") && payment>=0) // handles if they enter negative numbers
- {
- int check = payment * 493;
- System.out.println("Thank you!");
- System.out.println("Here is your change: ");
- System.out.println("");
- int change = check - totallydiscountprice;
- if (change<0)
- {
- System.out.println("You don't have enough money! Get out of here");
- }
- else
- {
- int changeSickles = change / 29;
- int changeKnuts = change % 29;
- System.out.println(" " + changeSickles + " Sickles");
- System.out.println(" " + changeKnuts + " Knuts");
- registerloop = true;
- }
- }
- else if (txt.equals("sickles") && payment>=0)
- {
- int check = payment * 29;
- System.out.println("Thank you!");
- System.out.println("Here is your change: ");
- System.out.println("");
- int change = check - totallydiscountprice;
- if (change<0)
- {
- System.out.println("You don't have enough money! Get out of here");
- }
- else
- {
- int changeSickles = change / 29;
- int changeKnuts = change % 29;
- System.out.println(" " + changeSickles + " Sickles");
- System.out.println(" " + changeKnuts + " Knuts");
- registerloop = true;
- }
- }
- else if (txt.equals("knuts") && payment>=0)
- {
- int check = payment;
- System.out.println("Thank you!");
- System.out.println("Here is your change: ");
- System.out.println("");
- int change = check - totallydiscountprice;
- if (change<0)
- {
- System.out.println("You don't have enough money! Get out of here");
- }
- else
- {
- int changeSickles = change / 29;
- int changeKnuts = change % 29;
- System.out.println(" " + changeSickles + " Sickles");
- System.out.println(" " + changeKnuts + " Knuts");
- registerloop = true;
- }
- }
- } while (!(registerloop));
- System.out.println("Thank you for shopping at DDD!");
- System.out.println(" ");
- attempts++;
- }
- else if (attempts < 2 && !password1.equals(passwordIn))
- {
- System.out.println("Sorry, but that is not right. We will give you one more chance: ");
- passwordIn = inScan2.nextLine();
- attempts++;
- }
- else if (attempts == 2)
- {
- System.out.println("Please enjoy our items ");
- System.out.println(" ");
- System.out.println("Here is our price list:");
- System.out.println(" Cauldron Cakes (each) 10 Knuts");
- System.out.println(" Cauldron Cakes (bag of 6) 55 Knuts");
- System.out.println(" Chocolate Frogs (each) 20 Knuts");
- System.out.println(" Butterbeer (small) 50 Knuts ");
- System.out.println(" Butterbeer (large) 75 Knuts ");
- System.out.println(" ");
- do{
- System.out.println("1) Update Cauldron Cakes Order");
- System.out.println("2) Update Chocolate Frogs Order");
- System.out.println("3) Update Butterbeer Order");
- System.out.println("4) Check Out");
- update = inScan3.nextInt();
- if (update == 1 )
- {
- System.out.println("Here is your current order");
- System.out.println(order1);
- System.out.println("How many Cauldron Cakes would you like for: ");
- System.out.println(" 10 Knuts per cake");
- System.out.println(" 55 Knuts per bag of 6");
- System.out.println("(Please indicate only the total amount of cakes you would like to buy): ");
- order1 = order1 + inScan4.nextInt();
- remainder = order1 % 6;
- difference = order1 - remainder;
- bag_count = difference/6;
- total_value = (remainder * 10 ) + (bag_count * 55);
- System.out.println(total_value + " Knuts"); // This price displays the total amount from previous entries as well as the current entry, not the price of every additional entry separately
- }
- else if (update == 2)
- {
- System.out.println("Here is your current order");
- System.out.println(order2);
- System.out.println("How many chocolate frogs would you like for 20 Knuts each?: ");
- order2 = order2 + inScan5.nextInt();
- total_value2 = order2 * 20;
- System.out.println(total_value2 + " Knuts");
- }
- else if (update == 3)
- {
- System.out.println("Here is your current order");
- System.out.println(order3 + order4);
- System.out.println("How many small Butterbeers would you like for 50 Knuts each?: ");
- order3 = order3 + inScan6.nextInt();
- butterval = order3 * 50;
- System.out.println("How many large Butterbeers would you like for 75 Knuts each?: ");
- order4 = order4 + inScan7.nextInt();
- butterval2 = order4 * 75;
- total_value3= butterval + butterval2;
- System.out.println(total_value3 + " Knuts");
- }
- }
- while ( update !=4);
- totally = total_value+total_value2+total_value3;
- System.out.println("Here is your subtotal");
- System.out.println(" " + bag_count + " bags of Cauldron cakes at 55 Knuts ea. " +(bag_count * 55 ));
- System.out.println(" " + remainder + " Cauldron cakes at 10 Knuts ea.: " + (remainder *10));
- System.out.println(" " + order2 + " Chocolate Frogs at 20 Knuts ea.: " + total_value2 );
- System.out.println(" " + order3 + " Small Butterbeers at 50 Knuts ea.: " + butterval);
- System.out.println(" " + order4 + " Large Butterbeers at 75 Knuts ea.: " + butterval2);
- System.out.println(" " + " Total: " + totally);
- System.out.println(" ");
- //tabs and spaces used to format
- System.out.println("Please enter your payment amount in the following format: ");
- System.out.println(" <amount><space><currency>");
- System.out.println(" Where <amount> = an integer");
- System.out.println(" Where <currency> = {Knuts, Sickles, Galleons}");
- System.out.println(" > ");
- //
- String userInput = inScan12.nextLine();
- int positionOfSpace = userInput.indexOf(" "); //I used this to find the position of the space in order to know where to parse for the values before and after
- String num = userInput.substring(0, positionOfSpace); //Grabs the "number" that is currently a string
- int payment = Integer.parseInt(num); // Because the value is initially a string, used this to make the number into int
- String txt = userInput.substring(positionOfSpace + 1); //Grab the currency type
- // this way I handle users that want to be difficult and type capital letters vs lowercase letters
- txt = txt.toLowerCase();
- do {
- if (txt.equals("galleons") && payment>=0) // handles if they enter negative numbers
- {
- int check = payment * 493;
- System.out.println("Thank you!");
- System.out.println("Here is your change: ");
- System.out.println("");
- int change = check - totally;
- if (change<0)
- {
- System.out.println("You don't have enough money! Get out of here");
- }
- else
- {
- int changeSickles = change / 29;
- int changeKnuts = change % 29;
- System.out.println(" " + changeSickles + " Sickles");
- System.out.println(" " + changeKnuts + " Knuts");
- registerloop = true;
- }
- }
- else if (txt.equals("sickles") && payment>=0)
- {
- int check = payment * 29;
- System.out.println("Thank you!");
- System.out.println("Here is your change: ");
- System.out.println("");
- int change = check - totally;
- if (change<0)
- {
- System.out.println("You don't have enough money! Get out of here");
- }
- else
- {
- int changeSickles = change / 29;
- int changeKnuts = change % 29;
- System.out.println(" " + changeSickles + " Sickles");
- System.out.println(" " + changeKnuts + " Knuts");
- registerloop = true;
- }
- }
- else if (txt.equals("knuts") && payment>=0)
- {
- int check = payment;
- System.out.println("Thank you!");
- System.out.println("Here is your change: ");
- System.out.println("");
- int change = check - totally;
- if (change<0)
- {
- System.out.println("You don't have enough money! Get out of here");
- }
- else
- {
- int changeSickles = change / 29;
- int changeKnuts = change % 29;
- System.out.println(" " + changeSickles + " Sickles");
- System.out.println(" " + changeKnuts + " Knuts");
- registerloop = true;
- }
- }
- } while (!(registerloop));
- System.out.println("Thank you for shopping at DDD!");
- System.out.println(" ");
- attempts++;
- }
- }
- while (attempts < 3 && !password1.equals(passwordIn));
- }
- }
- while (customer==1 && customer!=2);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement