Advertisement
agent7300

Untitled

Oct 20th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 9.87 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class P1
  4. {
  5.   public static void main (String[] args)
  6.   {
  7.     Scanner keyboard = new Scanner (System.in); //Scanner created
  8.    
  9.     double bread = 5.00; // variable for the bread item plus its cost
  10.     double pizza = 3.50; // pizza and cost
  11.     double soda = 2.00; // soda and cost
  12.     double iceCream = 3.75; // ice cream and cost
  13.     double cheese = 3.00; // cheese amd cost
  14.     double orange = 4.25; // orange and cost
  15.     double price; // variable for the total final price after shopping
  16.     double priceOfBread = 0; // variable to handle multiplying number of breads bought * bread
  17.     double priceOfSoda = 0; // sodas bought * soda
  18.     double priceOfPizza = 0; // pizzas bought * pizza
  19.     double priceOfIceCream = 0; // ice creams bought * ice cream
  20.     double priceOfCheese = 0; // cheese bought * cheese
  21.     double priceOfOrange = 0; // orange bought * orange
  22.     int numberOfItem; // variable to allow the user to select how many of an item they want
  23.     String input; // allows user input throughout the program
  24.     boolean isValid = true; //variable to determine whether or not user input was valid
  25.    
  26.     System.out.println("If you would like to quit shopping, enter 'quit'");
  27.     System.out.println("What day of the week is it?");
  28.     do{ // the do-while loop
  29.       input = keyboard.nextLine();
  30.       if(input.equalsIgnoreCase("quit")){
  31.         System.out.println("The market app had been prompted to quit.");
  32.         System.exit(1);
  33.       }
  34.      
  35.       if(input.equalsIgnoreCase("complete")){
  36.         isValid = false;
  37.         price = (priceOfOrange + priceOfCheese + priceOfIceCream + priceOfSoda + priceOfPizza + priceOfBread);
  38.        
  39.         System.out.println("Thank you for shopping! ");
  40.         System.out.printf("Your total price is... $%.2f\n " , price);
  41.         System.exit(1);
  42.       }  
  43.      
  44.  
  45.  
  46.      
  47.      if(input.equalsIgnoreCase("monday") || input.equalsIgnoreCase("wednesday") || input.equalsIgnoreCase("friday")){
  48.         System.out.println("What products would you like to purchase?");
  49.         System.out.print("bread, pizza, soda, ice cream, cheese, orange");
  50.         input = keyboard.nextLine();
  51.       }
  52.              
  53.       if(input.equalsIgnoreCase("quit")){
  54.         System.out.println("The market app had been prompted to quit.");
  55.         System.exit(1);
  56.       }
  57.                  
  58.       if(input.equalsIgnoreCase("bread")){
  59.         System.out.println("how much " + input + " do you want to purchase?");
  60.         numberOfItem = keyboard.nextInt();
  61.         priceOfBread = (numberOfItem * bread);
  62.       }
  63.      
  64.        if(input.equalsIgnoreCase("pizza")){
  65.         System.out.println("how much " + input + " do you want to purchase?");
  66.         numberOfItem = keyboard.nextInt();
  67.         priceOfPizza = (numberOfItem * pizza);
  68.       }
  69.       if(input.equalsIgnoreCase("soda")){
  70.         System.out.println("how much " + input + " do you want to purchase?");
  71.         numberOfItem = keyboard.nextInt();
  72.         priceOfSoda = (numberOfItem * soda);
  73.       }
  74.      if(input.equalsIgnoreCase("ice cream")){
  75.         System.out.println("how much " + input + " do you want to purchase?");
  76.         numberOfItem = keyboard.nextInt();
  77.         priceOfIceCream = (numberOfItem * iceCream);
  78.       }
  79.      if(input.equalsIgnoreCase("cheese")){
  80.         System.out.println("how much " + input + " do you want to purchase?");
  81.         numberOfItem = keyboard.nextInt();
  82.         priceOfCheese = (numberOfItem * cheese);
  83.       }
  84.      
  85.      if(input.equalsIgnoreCase("orange")){
  86.         System.out.println("how much " + input + " do you want to purchase?");
  87.         numberOfItem = keyboard.nextInt();
  88.         priceOfOrange = (numberOfItem * orange);
  89.       }
  90.      if(input.equalsIgnoreCase("quit")){
  91.         System.out.println("The market app had been prompted to quit.");
  92.         System.exit(1);
  93.       }
  94.    
  95.      if(input.equalsIgnoreCase("bread" + "soda" + "orange" + "ice cream" + "pizza" + "cheese")){
  96.         System.out.println("how much " + input + " do you want to purchase?");
  97.         numberOfItem = keyboard.nextInt();
  98.       }
  99.  
  100.      
  101.     if(input.equalsIgnoreCase("tuesday") || input.equalsIgnoreCase("thursday")){
  102.         System.out.println("On tuesdays and thursdays purchasing 3 of the same item gets you a 10% discount!");
  103.         System.out.println("What products would you like to purchase?");
  104.         System.out.print("bread, pizza, soda, ice cream, cheese, orange");
  105.         input = keyboard.nextLine();
  106.       }
  107.          if(input.equalsIgnoreCase("quit")){
  108.         System.out.println("The market app had been prompted to quit.");
  109.         System.exit(1);
  110.       }
  111.          
  112.      if(input.equalsIgnoreCase("bread")){
  113.         System.out.println("how much " + input + " do you want to purchase?");
  114.         numberOfItem = keyboard.nextInt();
  115.         priceOfBread = (numberOfItem * bread);
  116.         if(numberOfItem >= 3 && numberOfItem % 3 == 0){
  117.           priceOfBread = (numberOfItem * bread * .90);
  118.         }
  119.       }
  120.     if(input.equalsIgnoreCase("pizza")){
  121.         System.out.println("how much " + input + " do you want to purchase?");
  122.         numberOfItem = keyboard.nextInt();
  123.         priceOfPizza = (numberOfItem * pizza);
  124.         if(numberOfItem >= 3 && numberOfItem % 3 == 0){
  125.           priceOfPizza = (numberOfItem * pizza * .90);
  126.         }
  127.       }
  128.     if(input.equalsIgnoreCase("soda")){
  129.         System.out.println("how much " + input + " do you want to purchase?");
  130.         numberOfItem = keyboard.nextInt();
  131.         priceOfSoda = (numberOfItem * soda);
  132.         if(numberOfItem >= 3 && numberOfItem % 3 == 0){
  133.           priceOfSoda = (numberOfItem * soda * .90);
  134.         }
  135.       }
  136.     if(input.equalsIgnoreCase("ice cream")){
  137.         System.out.println("how much " + input + " do you want to purchase?");
  138.         numberOfItem = keyboard.nextInt();
  139.         priceOfIceCream = (numberOfItem * iceCream);
  140.         if(numberOfItem >= 3 && numberOfItem % 3 == 0){
  141.           priceOfIceCream = (numberOfItem * iceCream * .90);
  142.         }
  143.       }
  144.      else if(input.equalsIgnoreCase("cheese")){
  145.         System.out.println("how much " + input + " do you want to purchase?");
  146.         numberOfItem = keyboard.nextInt();
  147.         priceOfCheese = (numberOfItem * cheese);
  148.         if(numberOfItem >= 3 && numberOfItem % 3 == 0){
  149.           priceOfCheese = (numberOfItem * cheese * .90);
  150.         }
  151.       }
  152.     if(input.equalsIgnoreCase("orange")){
  153.         System.out.println("how much " + input + " do you want to purchase?");
  154.         numberOfItem = keyboard.nextInt();
  155.         priceOfOrange = (numberOfItem * orange);
  156.         if(numberOfItem >= 3 && numberOfItem % 3 == 0){
  157.           priceOfOrange = (numberOfItem * orange * .90);
  158.         }
  159.       }
  160.          if(input.equalsIgnoreCase("quit")){
  161.         System.out.println("The market app had been prompted to quit.");
  162.         System.exit(1);
  163.       }
  164.    
  165.     if(input.equalsIgnoreCase("bread" + "soda" + "orange" + "ice cream" + "pizza" + "cheese")){
  166.         System.out.println("how much " + input + " do you want to purchase?");
  167.         numberOfItem = keyboard.nextInt();
  168.       }
  169.  
  170.  
  171.      
  172.    if(input.equalsIgnoreCase("saturday") || input.equalsIgnoreCase("sunday")){
  173.         System.out.println("Saturdays and sundays are buy two get one free!");
  174.         System.out.println("What products would you like to purchase?");
  175.         System.out.print("bread, pizza, soda, ice cream, cheese, orange");
  176.         input = keyboard.nextLine();
  177.       }
  178.        if(input.equalsIgnoreCase("quit")){
  179.         System.out.println("The market app had been prompted to quit.");
  180.         System.exit(1);
  181.       }
  182.          
  183.     if(input.equalsIgnoreCase("bread")){
  184.         System.out.println("how much " + input + " do you want to purchase?");
  185.         numberOfItem = keyboard.nextInt();
  186.         priceOfBread = (((numberOfItem / 3 ) * 2 ) + (numberOfItem % 3)) * bread;
  187.       }
  188.      if(input.equalsIgnoreCase("pizza")){
  189.         System.out.println("how much " + input + " do you want to purchase?");
  190.         numberOfItem = keyboard.nextInt();
  191.         priceOfPizza = (((numberOfItem / 3 ) * 2 ) + (numberOfItem % 3)) * pizza;
  192.       }
  193.      if(input.equalsIgnoreCase("soda")){
  194.         System.out.println("how much " + input + " do you want to purchase?");
  195.         numberOfItem = keyboard.nextInt();
  196.         priceOfSoda = (((numberOfItem / 3 ) * 2 ) + (numberOfItem % 3)) * soda;
  197.       }
  198.     if(input.equalsIgnoreCase("ice cream")){
  199.         System.out.println("how much " + input + " do you want to purchase?");
  200.         numberOfItem = keyboard.nextInt();
  201.         priceOfIceCream = (((numberOfItem / 3 ) * 2 ) + (numberOfItem % 3)) * iceCream;
  202.       }
  203.      if(input.equalsIgnoreCase("cheese")){
  204.         System.out.println("how much " + input + " do you want to purchase?");
  205.         numberOfItem = keyboard.nextInt();
  206.         priceOfCheese = (((numberOfItem / 3 ) * 2 ) + (numberOfItem % 3)) * cheese;
  207.       }
  208.      if(input.equalsIgnoreCase("orange")){
  209.         System.out.println("how much " + input + " do you want to purchase?");
  210.         numberOfItem = keyboard.nextInt();
  211.         priceOfOrange = (((numberOfItem / 3 ) * 2 ) + (numberOfItem % 3)) * orange;
  212.       }
  213.        if(input.equalsIgnoreCase("quit")){
  214.         System.out.println("The market app had been prompted to quit.");
  215.         System.exit(1);
  216.       }
  217.    
  218.      if(input.equalsIgnoreCase("bread" + "soda" + "orange" + "ice cream" + "pizza" + "cheese")){
  219.         System.out.println("how much " + input + " do you want to purchase?");
  220.         numberOfItem = keyboard.nextInt();
  221.       }
  222.  
  223.               price = (priceOfOrange + priceOfCheese + priceOfIceCream + priceOfSoda + priceOfPizza + priceOfBread);
  224.       System.out.printf("Your current price is... $%.2f\n " , price);
  225.       System.out.print("If you would like to continue shopping, enter a new item, otherwise enter 'complete'");
  226.                input = keyboard.nextLine();
  227.     }while(isValid);
  228.   }
  229. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement