Question

In: Computer Science

for the following JAVA program Deals of the grocery store. The infomations on the flyer: 1.By...

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

Solutions

Expert Solution

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.


Related Solutions

Create a Python 3 program that acts as a grocery store shopping cart. 1. Create a...
Create a Python 3 program that acts as a grocery store shopping cart. 1. Create a class named GroceryItem. This class should contain: - an __init__ method that initializes the item’s name and price - a get_name method that returns the item’s name - a get_price method that returns the item’s price - a __str__ method that returns a string representation of that GroceryItem - an unimplemented method is_perishable Save this class in GroceryItem.py. 2. Create a subclass Perishable that...
********JAVA************ This program deals with graphs and path-finding within them. write a program which allows the...
********JAVA************ This program deals with graphs and path-finding within them. write a program which allows the user to enter multiple levels of a text, consisting of a 'start', an 'exit', 'walls', and 'floors'. The letter S represents the start. E is the exit. O (the letter 'oh') represents a 'floor' (meaning a path you can follow). X is a wall (meaning a block you cannot pass). The program will accept Standard Input (System.in), It is up to you whether you...
Program in Java Create a stack class to store integers and implement following methods: 1- void...
Program in Java Create a stack class to store integers and implement following methods: 1- void push(int num): This method will push an integer to the top of the stack. 2- int pop(): This method will return the value stored in the top of the stack. If the stack is empty this method will return -1. 3- void display(): This method will display all numbers in the stack from top to bottom (First item displayed will be the top value)....
Program in Java Create a queue class to store integers and implement following methods: 1- void...
Program in Java Create a queue class to store integers and implement following methods: 1- void enqueue(int num): This method will add an integer to the queue (end of the queue). 2- int dequeue(): This method will return the first item in the queue (First In First Out). 3- void display(): This method will display all items in the queue (First item will be displayed first). 4- Boolean isEmpty(): This method will check the queue and if it is empty,...
Project 1: Frequent Flyer Miles Calculator Write a Ruby program that calculates how many frequent flyer...
Project 1: Frequent Flyer Miles Calculator Write a Ruby program that calculates how many frequent flyer miles are needes for a free ticket on a new startup airline, CorsairAir. Frequent flyer miles are charged for a free ticket depending on the class of service (more for first class, less for coach), depending on the day flying (more if flying on Friday, Saturday or Monday, less for other days of the week), depending on the distance traveled, and a surcharge if...
Glen’s Grocery store                                       &nbsp
Glen’s Grocery store                                              Balance Sheet as at 31st December 2018 Current Assets                       $              $ Current Liabilities                  $              $            Bank                                      3,554                                                  Accounts Receivable             8,529          Accounts Payable                               10,490 Inventory                              15,637 Prepaid expenses                 2,132      29,852                                                                                    Non Current Liabilities                                                                                                                                         0               Non Current Assets                                                                                            Equipment                          49,755                       Owners’ Equity Accumulated Depreciation (14,215)                                                                35,540      Capital                                                  54,902                                                                                                Total Assets                                   $ 65,392      Total Liabilities & Owners’ Equity $ 65,392 Income Statement for the year ended 31st...
A customer comes into a grocery store and buys 8 items. Write a PYTHON program that...
A customer comes into a grocery store and buys 8 items. Write a PYTHON program that asks for the name of the item and the price of each item, and then displays these on the screen. Refer to the print() and input() statements covered in the module. Do NOT use loops as it will be covered in later modules. Apples 2.10 Hamburger 3.25 Milk 3.49 Sugar 1.99 Bread 1.76 Deli Turkey 7.99 Pickles 3.42 Butter 2.79
Python: Write a program to simulate the purchases in a grocery store. A customer may buy...
Python: Write a program to simulate the purchases in a grocery store. A customer may buy any number of items. So, you should use a while loop. Your program should read an item first and then read the price until you enter a terminal value (‘done’) to end the loop. You should add all the prices inside the loop. Add then a sales tax of 8.75% to the total price. Print a receipt to indicate all the details of the...
1) A grocery store carries the following items. There are two main categories of food –...
1) A grocery store carries the following items. There are two main categories of food – conventional and organic ingredients – and four food groups. The data are shown in the following table. Food Groups Food Categories Grains Fruits Vegetables Meat Total Conventional 82 48 276 204 610 Organic 93 77 24 11 205 Total 175 125 300 215 815 If all of the grains and meats were accidentally displayed together without a sticker or label to mark their origin,...
DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1....
DO THIS PROGRAM IN JAVA Write a complete Java console based program following these steps: 1. Write an abstract Java class called Shape which has only one abstract method named getArea(); 2. Write a Java class called Rectangle which extends Shape and has two data membersnamed width and height.The Rectangle should have all get/set methods, the toString method, and implement the abstract method getArea()it gets from class Shape. 3. Write the driver code tat tests the classes and methods you...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT