1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Kaylis [27]
3 years ago
11

Write a program for a grocery store to calculate the total charge for customers. In the main: Your program should ask customer t

he number of items that he/she is purchasing and it should check to see it is less than or equal to 20 items , then your program should pass than number to FillPriceArray subroutine and call FillPriceArray subroutine.
Computers and Technology
1 answer:
gavmur [86]3 years ago
8 0

Answer:

Hello Joelwestwood! This is a good question to check your knowledge of subrountines and Arrays. Please find the implementation with the explanation below.

Explanation:

The solution can be implemented in a number of languages including C++, Java and Python to name a few. Though the implementation language is not specified in the question, i'll provide you the implementation code in Python and also in Java. Java implementation is a little complex because we need to define an array size to be able to add items to it, whereas Python allows us more flexibility by allowing dynamic size of Array.

JAVA IMPLEMENTATION

import java.util.Scanner;

import java.util.Arrays;

class TotalCharge {

 private static int[] price_array = new int[1];

 public void FillPriceArray(int price) {

   if (price_array.length == 1) {

     price_array[0] = price;

   } else {

     price_array = new int[price_array.length + 1];

     price_array[price_array.length + 1] = price;

   }

 }

 public int[] get_price_array() {

   return price_array;

 }

 public static void main(String args[]) {

   System.out.println("Please enter the total number of items to purchase: ");

   Scanner scan = new Scanner(System.in);

   int price = scan.nextInt();

   if (price <= 20) {

     System.out.println("Items being purchased are less than 20");

   } else {

     System.out.println("Items being purchased are more than 20");

   }

   TotalCharge itemsTotal = new TotalCharge();

   itemsTotal.FillPriceArray(price);

   System.out.println(Arrays.toString(itemsTotal.get_price_array()));

 }

}

PYTHON IMPLEMENTATION

calculate_total_charge.py

def FillPriceArray(price):

 price_array.append(price)

price_array = []

price = raw_input("Please enter the total number of items to purchase: ")

try:

 price = int(price)

 if price <= 20:

   print("Items being purchased are less than 20")

 else:

   print("Items being purchased are more than 20")

 FillPriceArray(price)

 print(price_array)

except ValueError:

 print("Invalid input! Exiting..")

You might be interested in
witch option in a presentation program contains the formatting and placeholders for all the items that appear on a slide?
Nikitich [7]

SWITCH BETWEEN OPEN PRESENTATIONS. ..... Presentation software is a program designed for the production and display of .... image file format and version number. 1. .... Option. To Do This. Normal. Contains three panes: the outline pane, the slide pane, and the notes pane. .... appear on every slide in a presentation.

7 0
3 years ago
Read 2 more answers
I have a .NET 6 basic website that I built using Entity Framework as the database for updating pages. I am ready to deploy the s
11Alexandr11 [23.1K]

In the above scenario, i will recommend Bluehost  or InterServer since it is good and can meet your requirement.

<h3>What is Bluehost?</h3>

Bluehost is known to be a software that is said to be a little bit better than HostGator in the aspect of  security as it gives offer free SSL certificates, malware tools, and others.

Therefore, In the above scenario, I will recommend Bluehost  or InterServer since it is good and can meet your requirement.

Learn more about Bluehost from

brainly.com/question/17062016

#SPJ1

8 0
2 years ago
Rock, Paper, Scissors is a two-player game in which each player chooses one of three items. If both players choose the same item
mezya [45]

Answer:

The answer is c

Explanation:

7 0
4 years ago
Is a list of instructions an arguments?<br> Yes or No
Bingel [31]

Answer: yes

Explanation:

5 0
3 years ago
Read 2 more answers
To reload a picture taken with a digital camera means to copy the digital picture from the camera to your computer.
goldenfox [79]
The answer would be false.
7 0
3 years ago
Read 2 more answers
Other questions:
  • Datta Computer Systems is considering a project that has the following cash flow data. What is the project's IRR? Note that a pr
    10·1 answer
  • How many frames per second can a half duplex traditional gigabit ethernet handle?
    12·1 answer
  • Instructions:Select the correct answer.
    5·1 answer
  • According to the SANS Institute, a __________ is typically a document that outlines specific requirements or rules that must be
    13·1 answer
  • BrainPower Tutoring The owner of BrainPower Tutoring needs an application to calculate and print estimates to provide to potenti
    14·1 answer
  • Which of the following are correct? I. Hold the middle mouse button to rotate the model on the screen. II. To pan the model, hol
    15·1 answer
  • What is the BCC feature used for?
    12·2 answers
  • Gina, an IT professional, noticed that the servers were running very slowly. She evaluated the system and made a recommendation
    9·2 answers
  • Hannah wants to write a book about how scientists and society interact, and she has generated ideas for chapters. Which chapter
    13·1 answer
  • Data modeling may be the most important part of the systems development process because: Group of answer choices data are less s
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!