java code (pseudocode) Imagine that you are a merchant and need to keep better t
ID: 3734074 • Letter: J
Question
java code (pseudocode)
Imagine that you are a merchant and need to keep better tabs on your merchandise to know when to reorder supplies. First, write out pseudocode, and then create a program to help you by accomplishing the following tasks:
Use command line interface to ask the user to input the following. (You will need to convert this from a string to an integer.)
How many apples are on hand
How many apples should be in stock
How many oranges are on hand
How many oranges should be in stock
Perform an operation to determine how many of each item should be ordered to maintain the stock.
Use command line interface to output the number of apples and oranges that need to be ordered.
Once you have the program laid out, build it by creating a functional program. Use your pseudocode as a guide.
Explanation / Answer
Please find my Pseudo Code (As you have mentioned in Question)
Psuedocode
def checkStock():
apple_in_hand = ask user for number of apples in hand
apple_in_stock = user for number of apples required in stock
oranges_in_hand = ask user for number of oranges in hand
oranges_in_stock = ask user for number of oranges required in stock
print()
if (apples in hand are less than the number of apples needed in stock):
compute how many more apples are needed by using
apple_needed = apple_in_stock - apple_in_hand
print('More apples needed :', apple_needed)
else if(apples in hand are more than the number of apples needed in stock)
# stock i now already full
print('Stock of apples already full')
if(oranges in hand are less than the number of oranges needed in stock):
oranges_needed = compute how many more oranges are needed
print 'More oranges needed :', oranges_needed
else:
print('Stock of oranges already full')
call checkStock() function
Program:
def checkStock():
# ask user for number of apples in hand
apple_in_hand = int(input('Enter the number of apples are in hand '))
# ask user for number of apples required in stock
apple_in_stock = int(input('Enter the number of apples which should be in stock '))
# ask user for number of oranges in hand
oranges_in_hand = int(input('Enter the number of oranges are in hand '))
# ask user for number of oranges required in stock
oranges_in_stock = int(input('Enter the number of oranges which should be in stock '))
print()
# if apples in hand are less than the number of apples needed in stock
if(apple_in_hand < apple_in_stock):
# compute how many more apples are needed
apple_needed = apple_in_stock - apple_in_hand
print('More apples needed :', apple_needed)
# if apples in hand are more than the number of apples needed in stock
else:
# stock i now already full
print('Stock of apples already full')
# if oranges in hand are less than the number of oranges needed in stock
if(oranges_in_hand < oranges_in_stock):
# compute how many more oranges are needed
oranges_needed = oranges_in_stock - oranges_in_hand
print('More oranges needed :', oranges_needed)
else:
print('Stock of oranges already full')
# call checkStock function
checkStock()
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.