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

********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...
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...
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...
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...
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...
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,...
Bank Accounts in Java! Design and implement a Java program that does the following: 1) reads...
Bank Accounts in Java! Design and implement a Java program that does the following: 1) reads in the principle 2) reads in additional money deposited each year (treat this as a constant) 3) reads in years to grow, and 4) reads in interest rate And then finally prints out how much money they would have each year. See below for formatting. Enter the principle: XX Enter the annual addition: XX Enter the number of years to grow: XX Enter the...
java please 1. Write a Java program to generate random numbers in the following range a....
java please 1. Write a Java program to generate random numbers in the following range a. 1 <=n <= 3 b. 1 <= n <= 200 c. 0 <= n <= 9 d. 1000 <= n <= 2112 e. -1 <= n <= 5 2. Write statements that assign random integers to the variable n in the following ranges: a) 1 ≤ n ≤ 2 b) 1 ≤ n ≤ 100 c) 0 ≤ n ≤ 9 d) 1000 ≤...
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest...
IN JAVA Write a program that uses a two-dimensional array to store the highest and lowest temperatures for each month of the year. Prompt the user for 12 months of highest and lowest.   Write two methods : one to calculate and return the average high and one to calculate and return the average low of the year. Your program should output all the values in the array and then output the average high and the average low. im trying to...
1. The produce manager for a local grocery store is interested in estimating the proportion of...
1. The produce manager for a local grocery store is interested in estimating the proportion of apples that arrive on a shipment with major bruises. The supplier claims the rate will be about 10%. a) The produce manager wants to estimate the true proportion of bruised apples to within ±2%, with 90% confidence. How many apples should he sample? b) A random sample of 150 apples showed 12 with major bruises. Conduct a full hypothesis test to see if this...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT