Question

In: Computer Science

I would like to create discount based on the following items on small piza , large...

I would like to create discount based on the following items on small piza , large pizza and drinks as well.

for instance for small pizza,

if qty of  small pizaa is > 10   give 50% discount

if qty of  small pizaa is > 8    give 40% discount

if qty of  small pizaa is > 6 givs 30%  discount

if qty of  small pizaa is > 4 give 20%  discount

else

0%

// Program objective: requires user to input the data, program runs through the data,calcualtes the quantity, chacks prices for each iteam intered,calautes the prices seperatly for each item, and calculates the amount due without tax, and then give total amount due with tax included.

import java.util.Scanner;

public class Main

{

public static void main(String[] args) {

Scanner sc = new Scanner(System.in); //initialise a Scanner object, and get all the information about items quantity and toppings ordered and the amount of money tendered as mentioned in questions.

string answar;

do {

System.out.print("\nEnter quantity of Small pizzas: ");// allows you to enter the quantuty of the samll pizza

int numSmallPizzas = sc.nextInt();//initialise a Scanner object for small pizza

System.out.print("Enter quantity of Small pizza toppings: "); // allows you to enter the topoings for small pizza.

int numSmallPizzaToppings = sc.nextInt();// allows you to enter the small toppings.

System.out.print("Enter quantity of Large pizzas: ");// allows you to enter the quantity of large pizza.

int numLargePizzas = sc.nextInt();//initialise a Scanner object for lage pizza.

System.out.print("Enter quantity of Large pizza toppings: ");// allows you to enter the Toppings for large pizza.

int numLargePizzaToppings = sc.nextInt();//Allows you to enter the toppings for large pizza.

System.out.print("Enter quantity of Soft Drinks: "); // allows you to enter the quantity of soft drinks.

int numSoftDrinks = sc.nextInt(); //initialise a Scanner object for sum of Soft drinks

System.out.print("Enter Amount tendered: ");

double amountTendered = sc.nextDouble();//initialise a Scanner object for totalAmount.

//stored the rates of all items

double smallPizzasRate = 8.99; // rate of small pizza

double smallPizzaToppingsRate = 1.5; // rate of the small pizza toppings

double largePizzasRate = 12.99; //rate of large pizza

double largePizzaToppingsRate = 2.5; // rate of the large pizza toppings

double softDrinksRate = 1.5; // rate of soft drinks

//find the amount for all items

double amountSmallPizzas = numSmallPizzas*smallPizzasRate; // calculates the amount of the small pizza.

double amountSmallPizzaToppings = numSmallPizzaToppings*smallPizzaToppingsRate; // calculates the amount of Toppings for small pizza.

double amountLargePizzas = numLargePizzas*largePizzasRate;// calculates the amount of large.

double amountLargePizzaToppings = numLargePizzaToppings*largePizzaToppingsRate; //calculates the amount of toppinf for large pizza

double amountSoftDrinks = numSoftDrinks*softDrinksRate;// calcualtes the amount for soft drinks intered.

//find totalAmount,salesTax, amountDueWithTax and change

double totalAmount = amountSoftDrinks + amountLargePizzaToppings + amountLargePizzas + amountSmallPizzas + amountSmallPizzaToppings;

double salesTax = totalAmount*0.06;

double amountDueWithTax = totalAmount + salesTax;

double change = amountTendered - amountDueWithTax;

//prints the receipt

System.out.println("\nWelcome to Yassir Pizza!"); //prints the title of the busniess

System.out.println("Address 111 Yassir Road Largo MD 20783 "); // print the address of the busniess

System.out.println("busniess phone number: (240)241-3462"); // prrints Busniess phone number

System.out.println("Your Order Was");

System.out.printf("%d Small pizzas @ %.4f each: $%.4f\n",numSmallPizzas,smallPizzasRate,amountSmallPizzas);

System.out.printf("%d Small pizza toppings @ %.4f each: $%.4f\n",numSmallPizzaToppings,smallPizzaToppingsRate,amountSmallPizzaToppings);

// prints out the total amount of small pizza and its toppings.

System.out.printf("%d Large pizzas @ %.4f each: $%.4f\n",numLargePizzas,largePizzasRate,amountLargePizzas);

System.out.printf("%d Large Pizza Toppings @ %.4f each: $%.4f\n",numLargePizzaToppings,smallPizzaToppingsRate,amountLargePizzaToppings);

// prints out the total amount of large pizza and its toppings.

System.out.printf("%d Soft Drinks @ %.4f each: $%.4f\n",numSoftDrinks,softDrinksRate,amountSoftDrinks);

// prints out the total amount of Softdrinks.

System.out.printf("\nTotal cost: $%.4f\n", totalAmount); // prints totalAmount due without tax

System.out.printf("Sales tax amount is: $%.4f\n", salesTax); // prints the salesTax

System.out.printf("Total amount due: $%.4f\n", amountDueWithTax);// prints the total amount due including tax.

System.out.printf("Amount tendered: $%.3f\n", amountTendered);// prints the amount given to casherir.

System.out.printf("Change: $%.4f\n", change);// prints the change for the receipt

System.out.println("\nThank you! \nYour order is complete!");

//print the complete statment.

if (totalAmount < amountTendered) {

System.out.println("\nThank you! \nYour order is complete!");

}

else

System.out.println("\nYour money is not enough");

System.out.println("do you want to add anything else? Yes or No");

answar = sc.next();

}

while (answar.equals("Yes"));

}

}

Solutions

Expert Solution

i have added comments wherever changes were made or extra code was added

if you are not able to copy paste the code below just leave a comment

import java.util.Scanner;

public class starting_java{public static void main(String[] args) {

    Scanner sc = new Scanner(System.in); //initialise a Scanner object, and get all the information about items quantity and toppings ordered and the amount of money tendered as mentioned in questions.

    String answer;

    do {

        System.out.print("\nEnter quantity of Small pizzas: ");// allows you to enter the quantuty of the samll pizza
        int numSmallPizzas = sc.nextInt();//initialise a Scanner object for small pizza
        System.out.print("Enter quantity of Small pizza toppings: "); // allows you to enter the topoings for small pizza.
        int numSmallPizzaToppings = sc.nextInt();// allows you to enter the small toppings.
        System.out.print("Enter quantity of Large pizzas: ");// allows you to enter the quantity of large pizza.
        int numLargePizzas = sc.nextInt();//initialise a Scanner object for lage pizza.
        System.out.print("Enter quantity of Large pizza toppings: ");// allows you to enter the Toppings for large pizza.
        int numLargePizzaToppings = sc.nextInt();//Allows you to enter the toppings for large pizza.
        System.out.print("Enter quantity of Soft Drinks: "); // allows you to enter the quantity of soft drinks.
        int numSoftDrinks = sc.nextInt(); //initialise a Scanner object for sum of Soft drinks
        System.out.print("Enter Amount tendered: ");
        double amountTendered = sc.nextDouble();//initialise a Scanner object for totalAmount.

        //finding discount (added following lines of code)
        int smallPizzasDiscountPer=0;                   
        if(numSmallPizzas>10)smallPizzasDiscountPer=50;
        if(numSmallPizzas>8 && numSmallPizzas<=10)smallPizzasDiscountPer=40;
        if(numSmallPizzas>6&& numSmallPizzas<=8)  smallPizzasDiscountPer=30;
        if(numSmallPizzas>4 && numSmallPizzas<=6) smallPizzasDiscountPer=20;

        int largePizzasDiscountPer=0;
        if(numLargePizzas>10)largePizzasDiscountPer=50;
        if(numLargePizzas>8 && numLargePizzas<=10)largePizzasDiscountPer=40;
        if(numLargePizzas>6&& numLargePizzas<=8)  largePizzasDiscountPer=30;
        if(numLargePizzas>4 && numLargePizzas<=6) largePizzasDiscountPer=20;

        int softDrinksDiscountper=0;
        if(numSoftDrinks>10)softDrinksDiscountper=50;
        if(numSoftDrinks>8 && numSoftDrinks<=10)softDrinksDiscountper=40;
        if(numSoftDrinks>6&& numSoftDrinks<=8)softDrinksDiscountper=30;
        if(numSoftDrinks>4 && numSoftDrinks<=6)softDrinksDiscountper=20;

        //stored the rates of all items
        double smallPizzasRate = 8.99; // rate of small pizza
        double smallPizzaToppingsRate = 1.5; // rate of the small pizza toppings
        double largePizzasRate = 12.99; //rate of large pizza
        double largePizzaToppingsRate = 2.5; // rate of the large pizza toppings
        double softDrinksRate = 1.5; // rate of soft drinks

        //find the amount for all items
        double amountSmallPizzas = numSmallPizzas*smallPizzasRate; // calculates the amount of the small pizza.
        double amountSmallPizzaToppings = numSmallPizzaToppings*smallPizzaToppingsRate; // calculates the amount of Toppings for small pizza.
        double amountLargePizzas = numLargePizzas*largePizzasRate;// calculates the amount of large.
        double amountLargePizzaToppings = numLargePizzaToppings*largePizzaToppingsRate; //calculates the amount of toppinf for large pizza
        double amountSoftDrinks = numSoftDrinks*softDrinksRate;// calcualtes the amount for soft drinks intered.

        //find discount for all items(added these lines)
        double discountSmallPizzas=amountSmallPizzas*smallPizzasDiscountPer/100;        //total discount on small pizza
        double discountLargePizzas=amountLargePizzas*largePizzasDiscountPer/100;        //total discount on large pizza
        double discountSoftDrinks=amountSoftDrinks*softDrinksDiscountper/100;        //total discount on soft drinks
        double totalDiscount=discountSmallPizzas+discountLargePizzas+discountSoftDrinks;     //net total discount


        //find totalAmount,salesTax, amountDueWithTax and change
        double totalAmount = amountSoftDrinks + amountLargePizzaToppings + amountLargePizzas + amountSmallPizzas + amountSmallPizzaToppings;
        double salesTax = totalAmount*0.06;
        double amountDueWithTax = totalAmount + salesTax-totalDiscount; //(made changes)
        double change = amountTendered - amountDueWithTax;

        
        //prints the receipt
        System.out.println("\nWelcome to Yassir Pizza!"); //prints the title of the busniess
        System.out.println("Address 111 Yassir Road Largo MD 20783 "); // print the address of the busniess
        System.out.println("busniess phone number: (240)241-3462"); // prrints Busniess phone number
        System.out.println("Your Order Was");

        System.out.printf("%d Small pizzas @ %.4f each: $%.4f\n",numSmallPizzas,smallPizzasRate,amountSmallPizzas);
        System.out.printf("%d Small pizza toppings @ %.4f each: $%.4f\n",numSmallPizzaToppings,smallPizzaToppingsRate,amountSmallPizzaToppings);
        // prints out the total amount of small pizza and its toppings.

        System.out.printf("%d Large pizzas @ %.4f each: $%.4f\n",numLargePizzas,largePizzasRate,amountLargePizzas);
        System.out.printf("%d Large Pizza Toppings @ %.4f each: $%.4f\n",numLargePizzaToppings,smallPizzaToppingsRate,amountLargePizzaToppings);
        // prints out the total amount of large pizza and its toppings.

        System.out.printf("%d Soft Drinks @ %.4f each: $%.4f\n",numSoftDrinks,softDrinksRate,amountSoftDrinks);
        // prints out the total amount of Softdrinks.

        //printing discount(added this)
        System.out.printf("\nDiscount on Small pizzas %d%%\n",smallPizzasDiscountPer);//prints discount on small pizza in percent
        System.out.printf("Discount on large pizzas %d%%\n",largePizzasDiscountPer);//prints discount on large pizza in percent
        System.out.printf("Discount on soft drinks %d%%\n",softDrinksDiscountper);//prints discount on Soft drink in percent

        System.out.printf("\nTotal cost: $%.4f\n", totalAmount); // prints totalAmount due without tax
        System.out.printf("Total discount: $%.4f\n", totalDiscount); // prints total discount(added this)
        System.out.printf("Sales tax amount is: $%.4f\n", salesTax); // prints the salesTax
        System.out.printf("Total amount due: $%.4f\n", amountDueWithTax);// prints the total amount due including tax after discount.
        System.out.printf("Amount tendered: $%.3f\n", amountTendered);// prints the amount given to casherir.
        System.out.printf("Change: $%.4f\n", change);// prints the change for the receipt
        System.out.println("\nThank you! \nYour order is complete!");
        
        //print the complete statment.
        if (totalAmount < amountTendered) {
            System.out.println("\nThank you! \nYour order is complete!");
        }
        else
        System.out.println("\nYour money is not enough");
        System.out.println("do you want to add anything else? Yes or No");
        answer = sc.next();
    }
    while (answer.equals("Yes"));
    }
}

(NOTE:for any doubt in the code just leave a comment else please press the like button)


Related Solutions

I would like to create a rectangular vegetable patch. The fencing for the east and west...
I would like to create a rectangular vegetable patch. The fencing for the east and west sides costs $4 per foot, and the fencing for the north and south sides costs only $2 per foot. I have a budget of $96 for the project. What are the dimensions of the vegetable patch with the largest area I can enclose? HINT [See Example 2.]
given the following questions, i would like to ... Question Given the following questions, I would...
given the following questions, i would like to ... Question Given the following questions, I would like to know the answers to c, d, and e. located at the bottom (due to 4 answers per post limit). Thanks! Platinum (Pt) is used in part of your car's catalytic converter to reduce carbon monoxide emissions by the following chemical reaction: 2CO(g) + O2(g) Pt 2CO2(g) ---> 1) A matrix contains 7.1mg Pt/g of matrix. What is the %Pt in the matrix...
I need to describe a consumer physical good based on Marketing. I would like to choose...
I need to describe a consumer physical good based on Marketing. I would like to choose either or mobile phone or a laptop  as the physical good. Which includes * Brief description of the product * Company background * Competitive environment * Target market description * Product strategy - 3 levels of product
Please I would like to know what are the Eflluents and waste materials generated in large...
Please I would like to know what are the Eflluents and waste materials generated in large scale bio Ethanol plants making Ethanol form sugar beet. Thanks
i would like to do a study in “small area estimation on labour force indicators” using...
i would like to do a study in “small area estimation on labour force indicators” using hirachical bayesian modelling tsking sample weights into considerations” how does one do it
I would like to create a Memory Game using JCreator. But am unsure where to start....
I would like to create a Memory Game using JCreator. But am unsure where to start. Please help. I would like to start with a basic code so I can add and change designs and colors ect... Any help would be greatly appreciated. I do want to use pics such as .jpg in my code.
How would I work the following problems out? I would like someone to show their work...
How would I work the following problems out? I would like someone to show their work so I could better understand the answers and thought process. Genetics Problems For the first couple of problems, you will be working with guinea pigs. Their coat color shows an example of complete dominance - black (B) is dominant over brown (b). 1. A heterozygous black male is crossed with a heterozygous black female. What would be the resulting phenotypic ratio in the offspring?...
I'm having trouble putting in words, basically I would like to explain for each bond par/discount/premium,...
I'm having trouble putting in words, basically I would like to explain for each bond par/discount/premium, the relationship between coupon rate, current yield and yield-to-maturity. Basically explain the relationship Discount Bonds (Price < Par): YTM > Current Yield > Coupon Rate but in the least math terms as possible. Any tips? thanks!
One of the items that businesses would like to be able to test is whether or...
One of the items that businesses would like to be able to test is whether or not a change they make to their procedures is effective. Remember that when you create a hypothesis and then test it, you have to take into consideration that some variance between what you expect and what you collect as actual data is because of random chance. However, if the difference between what you expect and what you collect is large enough, you can more...
One of the items that businesses would like to be able to test is whether or...
One of the items that businesses would like to be able to test is whether or not a change they make to their procedures is effective. Remember that when you create a hypothesis and then test it, you have to take into consideration that some variance between what you expect and what you collect as actual data is because of random chance. However, if the difference between what you expect and what you collect is large enough, you can more...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT