Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class P1
- {
- public static void main (String[] args)
- {
- Scanner keyboard = new Scanner (System.in); //Scanner created
- double bread = 5.00; // variable for the bread item plus its cost
- double pizza = 3.50; // pizza and cost
- double soda = 2.00; // soda and cost
- double iceCream = 3.75; // ice cream and cost
- double cheese = 3.00; // cheese amd cost
- double orange = 4.25; // orange and cost
- double price; // variable for the total final price after shopping
- double priceOfBread = 0; // variable to handle multiplying number of breads bought * bread
- double priceOfSoda = 0; // sodas bought * soda
- double priceOfPizza = 0; // pizzas bought * pizza
- double priceOfIceCream = 0; // ice creams bought * ice cream
- double priceOfCheese = 0; // cheese bought * cheese
- double priceOfOrange = 0; // orange bought * orange
- int numberOfItem; // variable to allow the user to select how many of an item they want
- String input; // allows user input throughout the program
- boolean isValid = true; //variable to determine whether or not user input was valid
- System.out.println("If you would like to quit shopping, enter 'quit'");
- System.out.println("What day of the week is it?");
- do{ // the do-while loop
- input = keyboard.nextLine();
- if(input.equalsIgnoreCase("quit")){
- System.out.println("The market app had been prompted to quit.");
- System.exit(1);
- }
- if(input.equalsIgnoreCase("complete")){
- isValid = false;
- price = (priceOfOrange + priceOfCheese + priceOfIceCream + priceOfSoda + priceOfPizza + priceOfBread);
- System.out.println("Thank you for shopping! ");
- System.out.printf("Your total price is... $%.2f\n " , price);
- System.exit(1);
- }
- if(input.equalsIgnoreCase("monday") || input.equalsIgnoreCase("wednesday") || input.equalsIgnoreCase("friday")){
- System.out.println("What products would you like to purchase?");
- System.out.print("bread, pizza, soda, ice cream, cheese, orange");
- input = keyboard.nextLine();
- }
- if(input.equalsIgnoreCase("quit")){
- System.out.println("The market app had been prompted to quit.");
- System.exit(1);
- }
- if(input.equalsIgnoreCase("bread")){
- System.out.println("how much " + input + " do you want to purchase?");
- numberOfItem = keyboard.nextInt();
- priceOfBread = (numberOfItem * bread);
- }
- if(input.equalsIgnoreCase("pizza")){
- System.out.println("how much " + input + " do you want to purchase?");
- numberOfItem = keyboard.nextInt();
- priceOfPizza = (numberOfItem * pizza);
- }
- if(input.equalsIgnoreCase("soda")){
- System.out.println("how much " + input + " do you want to purchase?");
- numberOfItem = keyboard.nextInt();
- priceOfSoda = (numberOfItem * soda);
- }
- if(input.equalsIgnoreCase("ice cream")){
- System.out.println("how much " + input + " do you want to purchase?");
- numberOfItem = keyboard.nextInt();
- priceOfIceCream = (numberOfItem * iceCream);
- }
- if(input.equalsIgnoreCase("cheese")){
- System.out.println("how much " + input + " do you want to purchase?");
- numberOfItem = keyboard.nextInt();
- priceOfCheese = (numberOfItem * cheese);
- }
- if(input.equalsIgnoreCase("orange")){
- System.out.println("how much " + input + " do you want to purchase?");
- numberOfItem = keyboard.nextInt();
- priceOfOrange = (numberOfItem * orange);
- }
- if(input.equalsIgnoreCase("quit")){
- System.out.println("The market app had been prompted to quit.");
- System.exit(1);
- }
- if(input.equalsIgnoreCase("bread" + "soda" + "orange" + "ice cream" + "pizza" + "cheese")){
- System.out.println("how much " + input + " do you want to purchase?");
- numberOfItem = keyboard.nextInt();
- }
- if(input.equalsIgnoreCase("tuesday") || input.equalsIgnoreCase("thursday")){
- System.out.println("On tuesdays and thursdays purchasing 3 of the same item gets you a 10% discount!");
- System.out.println("What products would you like to purchase?");
- System.out.print("bread, pizza, soda, ice cream, cheese, orange");
- input = keyboard.nextLine();
- }
- if(input.equalsIgnoreCase("quit")){
- System.out.println("The market app had been prompted to quit.");
- System.exit(1);
- }
- if(input.equalsIgnoreCase("bread")){
- System.out.println("how much " + input + " do you want to purchase?");
- numberOfItem = keyboard.nextInt();
- priceOfBread = (numberOfItem * bread);
- if(numberOfItem >= 3 && numberOfItem % 3 == 0){
- priceOfBread = (numberOfItem * bread * .90);
- }
- }
- if(input.equalsIgnoreCase("pizza")){
- System.out.println("how much " + input + " do you want to purchase?");
- numberOfItem = keyboard.nextInt();
- priceOfPizza = (numberOfItem * pizza);
- if(numberOfItem >= 3 && numberOfItem % 3 == 0){
- priceOfPizza = (numberOfItem * pizza * .90);
- }
- }
- if(input.equalsIgnoreCase("soda")){
- System.out.println("how much " + input + " do you want to purchase?");
- numberOfItem = keyboard.nextInt();
- priceOfSoda = (numberOfItem * soda);
- if(numberOfItem >= 3 && numberOfItem % 3 == 0){
- priceOfSoda = (numberOfItem * soda * .90);
- }
- }
- if(input.equalsIgnoreCase("ice cream")){
- System.out.println("how much " + input + " do you want to purchase?");
- numberOfItem = keyboard.nextInt();
- priceOfIceCream = (numberOfItem * iceCream);
- if(numberOfItem >= 3 && numberOfItem % 3 == 0){
- priceOfIceCream = (numberOfItem * iceCream * .90);
- }
- }
- else if(input.equalsIgnoreCase("cheese")){
- System.out.println("how much " + input + " do you want to purchase?");
- numberOfItem = keyboard.nextInt();
- priceOfCheese = (numberOfItem * cheese);
- if(numberOfItem >= 3 && numberOfItem % 3 == 0){
- priceOfCheese = (numberOfItem * cheese * .90);
- }
- }
- if(input.equalsIgnoreCase("orange")){
- System.out.println("how much " + input + " do you want to purchase?");
- numberOfItem = keyboard.nextInt();
- priceOfOrange = (numberOfItem * orange);
- if(numberOfItem >= 3 && numberOfItem % 3 == 0){
- priceOfOrange = (numberOfItem * orange * .90);
- }
- }
- if(input.equalsIgnoreCase("quit")){
- System.out.println("The market app had been prompted to quit.");
- System.exit(1);
- }
- if(input.equalsIgnoreCase("bread" + "soda" + "orange" + "ice cream" + "pizza" + "cheese")){
- System.out.println("how much " + input + " do you want to purchase?");
- numberOfItem = keyboard.nextInt();
- }
- if(input.equalsIgnoreCase("saturday") || input.equalsIgnoreCase("sunday")){
- System.out.println("Saturdays and sundays are buy two get one free!");
- System.out.println("What products would you like to purchase?");
- System.out.print("bread, pizza, soda, ice cream, cheese, orange");
- input = keyboard.nextLine();
- }
- if(input.equalsIgnoreCase("quit")){
- System.out.println("The market app had been prompted to quit.");
- System.exit(1);
- }
- if(input.equalsIgnoreCase("bread")){
- System.out.println("how much " + input + " do you want to purchase?");
- numberOfItem = keyboard.nextInt();
- priceOfBread = (((numberOfItem / 3 ) * 2 ) + (numberOfItem % 3)) * bread;
- }
- if(input.equalsIgnoreCase("pizza")){
- System.out.println("how much " + input + " do you want to purchase?");
- numberOfItem = keyboard.nextInt();
- priceOfPizza = (((numberOfItem / 3 ) * 2 ) + (numberOfItem % 3)) * pizza;
- }
- if(input.equalsIgnoreCase("soda")){
- System.out.println("how much " + input + " do you want to purchase?");
- numberOfItem = keyboard.nextInt();
- priceOfSoda = (((numberOfItem / 3 ) * 2 ) + (numberOfItem % 3)) * soda;
- }
- if(input.equalsIgnoreCase("ice cream")){
- System.out.println("how much " + input + " do you want to purchase?");
- numberOfItem = keyboard.nextInt();
- priceOfIceCream = (((numberOfItem / 3 ) * 2 ) + (numberOfItem % 3)) * iceCream;
- }
- if(input.equalsIgnoreCase("cheese")){
- System.out.println("how much " + input + " do you want to purchase?");
- numberOfItem = keyboard.nextInt();
- priceOfCheese = (((numberOfItem / 3 ) * 2 ) + (numberOfItem % 3)) * cheese;
- }
- if(input.equalsIgnoreCase("orange")){
- System.out.println("how much " + input + " do you want to purchase?");
- numberOfItem = keyboard.nextInt();
- priceOfOrange = (((numberOfItem / 3 ) * 2 ) + (numberOfItem % 3)) * orange;
- }
- if(input.equalsIgnoreCase("quit")){
- System.out.println("The market app had been prompted to quit.");
- System.exit(1);
- }
- if(input.equalsIgnoreCase("bread" + "soda" + "orange" + "ice cream" + "pizza" + "cheese")){
- System.out.println("how much " + input + " do you want to purchase?");
- numberOfItem = keyboard.nextInt();
- }
- price = (priceOfOrange + priceOfCheese + priceOfIceCream + priceOfSoda + priceOfPizza + priceOfBread);
- System.out.printf("Your current price is... $%.2f\n " , price);
- System.out.print("If you would like to continue shopping, enter a new item, otherwise enter 'complete'");
- input = keyboard.nextLine();
- }while(isValid);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement