In: Computer Science
for the following JAVA program
Deals of the grocery store. The infomations on the flyer:
1.By buying items under $250, the client will get a 10% off in total and get double point
2.By buying items between $250-500 (both included),the client will get 15% off in total and get double points.
3.By buying items over 500, the client will get 20% off in total and get triple points.
Fish is not included in the total discount price.
The calculation of the points is the following:
You need to have a membership in order to get the points
double points = 2*total price (fish included)
triple points = 3*total price ( fish included).
The total of the points will be an integer that is rounded up. (you can use Math.round())
| 
 _Item No.  | 
 Item Name  | 
 Price per item  | 
| 
 1  | 
 Vegetables  | 
 $26.99  | 
| 
 2  | 
 Cheese  | 
 $22.99  | 
| 
 3  | 
 Eggs  | 
 $13.99  | 
| 
 4  | 
 Meat  | 
 $56.99  | 
| 
 5  | 
 Fish  | 
 $38.99  | 
Example :
Please enter the quantities for each item in the list? 1 2 0 1 1
Do you have the membership of the store? (Yes or no) Yes
The total of your shopping is $155.954. You accumulated 312 points for your purchase today.
Thank you
Program:
import java.util.Scanner;
class GroceryStore
{
   //main method
   public static void main(String[] args)
   {
       //create instance
   Scanner kb = new Scanner(System.in);
   //array of prices
   double itemPrice[] = {26.99, 22.99, 13.99, 56.99,
38.99};
  
   int n = itemPrice.length;
   //prompt to enter the quantities for each item in the
list
   System.out.print ("Please enter the quantities for
each item in the list? ");
  
   double totalCost = 0;
   double fishAmount = 0;
   for(int i=0; i<n; i++)
   {
       //read the quantities for each item
in the list
       int items =
Integer.parseInt(kb.next());
       //check for fish item
       if(i==4)
           fishAmount =
itemPrice[i]*items;
       else
           totalCost =
totalCost + itemPrice[i]*items;
   }
       
        //prompt and read if yo have
membership of the store
        System.out.print ("Do you
have the membership of the store? (Yes or no) ");
   String res = kb.next();
  
   //calculate off amount
   double off;
   if(totalCost<250)
       off = totalCost*0.1;
   else if(totalCost<=500)
       off = totalCost*0.15;
   else
       off = totalCost*0.2;
  
   totalCost = totalCost + fishAmount - off;
  
   //calculate points
   long points = 0;
   if(res.equalsIgnoreCase("yes"))
   {
       if(totalCost<=500)
           points =
Math.round(totalCost*2);
           else
           points =
Math.round(totalCost*3);
   }
  
   //display the totalCost and points
   System.out.print ("The total of your shopping is $" +
totalCost + ".");
   if(res.equalsIgnoreCase("yes"))
       System.out.println ("You
accumulated " + points + " points for your purchase today.");
   System.out.println ("Thank you");
   }
}
Output:
Please enter the quantities for each item in the list? 1 2 0 1
1
Do you have the membership of the store? (Yes or no) yes
The total of your shopping is $155.954.You accumulated 312 points
for your purchase today.
Thank you
Solving your question and
helping you to well understand it is my focus. So if you face any
difficulties regarding this please let me know through the
comments. I will try my best to assist you. However if you are
satisfied with the answer please don't forget to give your
feedback. Your feedback is very precious to us, so don't give
negative feedback without showing proper reason.
Always avoid copying from existing answers to avoid
plagiarism.
Thank you.