1. Solve the following: Your friends run a small roadside kiosk where they sell their own homegrown, organic produce. Th
Posted: Fri May 20, 2022 12:43 pm
1. Solve the following:
Your friends run a small roadside kiosk where they sell their
own homegrown, organic produce. They sell different kinds of fruits
and vegetables. For example, they sell a bag of 10 apples for $2.00
and a bag of 12 ears of corn for $3.00. Some customers do not want
the whole bag of apples, corn, or whatever, so they can purchase
say, 3 apples or only half a bag of corn. The kiosk becomes busy,
so your friends do not want to risk doing the math in their mind
and make mistakes. You offer to help by writing a small program t h
a t t h e y can use on their laptops to perform the calculations
and let them know how much money to collect from customers.
You start with the Product class. This class has the following
data members:
• itemName: the name of the item, such as "apple", "corn", or
"tomato".
• itemQty: the number of items sold as a unit, for example if
they sell a bag of 10 apples for $2.00 then this data member's
value would be 10.
• itemPrice: the price for the group of items sold, for example
if they sell a bag of 10 apples for $2.00 then this data member's
value would be 2.00.
Each data member should have accessor and mutator methods.
Mutator methods should validate the data appropriately if the data
is not correct. itemName should not be an empty string; itemQty and
itemPrice should both be greater than 0.
A calcTotal() method accepts an integer value argument that
corresponds to the number of a particular item the customer wants.
This method should then return the total amount that the customer
should pay. For example, if you sell 10 apples for $2.00 and the
customer asks for 5 apples, then this method should return 1.0
(2.0/10 * 5). If the customer asks for 2 bags of 10 apples then the
method should return 4.0 (2.0/10 * 20).
A toString() method returns a string representation of the
Product object in the form:
itemName: q for $p.pp
itemName is the item name, q is the itemQty, and $p.pp is the
itemprice, formatted with a dollar sign and two decimal places.
Write the application that uses this Product class. Create an
array of sample product objects that your kiosk will sell.
Especially, the program will ask the seller about the item name
that is being sold, the quantity and the price for that quantity.
The program should then display a menu of items that will be sold
and ask the sellers to enter the name of the item being purchased,
and how many of this item they would like. Use an if-statement to
determine which of the product objects applies for the user's input
(compare name of products). Use the Product object to calculate the
total amount owed for the product. Your program should repeatedly
ask the user for products they would like to buy until the user
enters ‘N’ to end the transaction and pay for all the products
purchased.
The kiosk should ask the seller if the prices have changed due
to the increasing inflation rate [1]. If the user enters ‘yes’,
then the program will ask the seller to re-enter the items based on
the new prices (i.e., assume that all the prices have changed for
all the items).
The kiosk should then display the prompt for the next user and
continue the same operation of selling products.
At the end of the day, the operator can enter “Shutdown” and the
application will exit after displaying the total sales done for the
day.
The following is should be sample output
Sample Output:
Enter the name of the item: Apples
Enter the price: 4
Enter the QTY: 10
Enter the name of the item: Oranges
Enter the price: 4.5
Enter the QTY: 5
Enter the name of the item: Corn
Enter the price: 3
Enter the QTY: 12
Welcome to the Kiosk!
We sell: Apples 10 for $4.00
Oranges 5 for $4.50
Corn 12 for $3.00
What do you want to buy?
Apples
How many: 5
Any other product?
Oranges
How many: 3
Any other product?
N
Your total price would be $4.70 Thanks for shopping with us!
---------------------------------------------------------------------------------
Are there any changes in prices due to the new inflation
rate?
Y
Enter the name of the item:
Apples
Enter the price: 5
Enter the QTY: 10
Enter the name of the item:
Oranges
Enter the price: 4
Enter the QTY: 5
Enter the name of the item:
Corn
Enter the price: 6
Enter the QTY: 12
Welcome to the Kiosk!
We sell: Apples 10 for $5.00
Oranges 5 for $4.00
Corn 12 for $6.00
What do you want to buy?
shutdown
Your total sale would be $4.70
Your friends run a small roadside kiosk where they sell their
own homegrown, organic produce. They sell different kinds of fruits
and vegetables. For example, they sell a bag of 10 apples for $2.00
and a bag of 12 ears of corn for $3.00. Some customers do not want
the whole bag of apples, corn, or whatever, so they can purchase
say, 3 apples or only half a bag of corn. The kiosk becomes busy,
so your friends do not want to risk doing the math in their mind
and make mistakes. You offer to help by writing a small program t h
a t t h e y can use on their laptops to perform the calculations
and let them know how much money to collect from customers.
You start with the Product class. This class has the following
data members:
• itemName: the name of the item, such as "apple", "corn", or
"tomato".
• itemQty: the number of items sold as a unit, for example if
they sell a bag of 10 apples for $2.00 then this data member's
value would be 10.
• itemPrice: the price for the group of items sold, for example
if they sell a bag of 10 apples for $2.00 then this data member's
value would be 2.00.
Each data member should have accessor and mutator methods.
Mutator methods should validate the data appropriately if the data
is not correct. itemName should not be an empty string; itemQty and
itemPrice should both be greater than 0.
A calcTotal() method accepts an integer value argument that
corresponds to the number of a particular item the customer wants.
This method should then return the total amount that the customer
should pay. For example, if you sell 10 apples for $2.00 and the
customer asks for 5 apples, then this method should return 1.0
(2.0/10 * 5). If the customer asks for 2 bags of 10 apples then the
method should return 4.0 (2.0/10 * 20).
A toString() method returns a string representation of the
Product object in the form:
itemName: q for $p.pp
itemName is the item name, q is the itemQty, and $p.pp is the
itemprice, formatted with a dollar sign and two decimal places.
Write the application that uses this Product class. Create an
array of sample product objects that your kiosk will sell.
Especially, the program will ask the seller about the item name
that is being sold, the quantity and the price for that quantity.
The program should then display a menu of items that will be sold
and ask the sellers to enter the name of the item being purchased,
and how many of this item they would like. Use an if-statement to
determine which of the product objects applies for the user's input
(compare name of products). Use the Product object to calculate the
total amount owed for the product. Your program should repeatedly
ask the user for products they would like to buy until the user
enters ‘N’ to end the transaction and pay for all the products
purchased.
The kiosk should ask the seller if the prices have changed due
to the increasing inflation rate [1]. If the user enters ‘yes’,
then the program will ask the seller to re-enter the items based on
the new prices (i.e., assume that all the prices have changed for
all the items).
The kiosk should then display the prompt for the next user and
continue the same operation of selling products.
At the end of the day, the operator can enter “Shutdown” and the
application will exit after displaying the total sales done for the
day.
The following is should be sample output
Sample Output:
Enter the name of the item: Apples
Enter the price: 4
Enter the QTY: 10
Enter the name of the item: Oranges
Enter the price: 4.5
Enter the QTY: 5
Enter the name of the item: Corn
Enter the price: 3
Enter the QTY: 12
Welcome to the Kiosk!
We sell: Apples 10 for $4.00
Oranges 5 for $4.50
Corn 12 for $3.00
What do you want to buy?
Apples
How many: 5
Any other product?
Oranges
How many: 3
Any other product?
N
Your total price would be $4.70 Thanks for shopping with us!
---------------------------------------------------------------------------------
Are there any changes in prices due to the new inflation
rate?
Y
Enter the name of the item:
Apples
Enter the price: 5
Enter the QTY: 10
Enter the name of the item:
Oranges
Enter the price: 4
Enter the QTY: 5
Enter the name of the item:
Corn
Enter the price: 6
Enter the QTY: 12
Welcome to the Kiosk!
We sell: Apples 10 for $5.00
Oranges 5 for $4.00
Corn 12 for $6.00
What do you want to buy?
shutdown
Your total sale would be $4.70