There are 2 arrays, the first contains item numbers in inventory and the second parallel array contains the price of the items. The user will enter the item number they want to purchase, the program checks to see if it is a valid entry. If it is valid, it will tell the user the price of the item. If it is an invalid item, a message will display telling the user they entered an invalid item. Type up the code below, execute the program a few times

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter18: Stacks And Queues
Section: Chapter Questions
Problem 16PE: The implementation of a queue in an array, as given in this chapter, uses the variable count to...
icon
Related questions
Question

There are 2 arrays, the first contains
item numbers in inventory and the second parallel array contains the price of the items. The
user will enter the item number they want to purchase, the program checks to see if it is a valid
entry. If it is valid, it will tell the user the price of the item. If it is an invalid item, a message will
display telling the user they entered an invalid item. Type up the code below, execute the
program a few times.

Import javax.swing.*:
public class ParallelArrays {
public static void main(String[] args) {
II Variables needed
Int item;
double price = 0.0;
String itemEntered =
boolean valid = false;
// Set up arrays
Int[] items Arr = {101, 102, 103, 452, 524, 601, 775);
double priceArr(7.52, 18.36, 1.25, 450.99, 19.99, 24.97, 101.33);
// Use a loop to allow the user to order items
do {
II Ask the user to enter an item to purchase
itemEntered = JOptionPane.show/nputDialog(null, "Enter the item number to
order, enter '9999' to quit");
item= Integer.parse/nfitemEntered);
Transcribed Image Text:Import javax.swing.*: public class ParallelArrays { public static void main(String[] args) { II Variables needed Int item; double price = 0.0; String itemEntered = boolean valid = false; // Set up arrays Int[] items Arr = {101, 102, 103, 452, 524, 601, 775); double priceArr(7.52, 18.36, 1.25, 450.99, 19.99, 24.97, 101.33); // Use a loop to allow the user to order items do { II Ask the user to enter an item to purchase itemEntered = JOptionPane.show/nputDialog(null, "Enter the item number to order, enter '9999' to quit"); item= Integer.parse/nfitemEntered);
item + " is $" + price);
}
}
// If the item number entered is valid
if
(!itemEntered.equals("9999"))
}
{
+ item + " is invalid, please try again.");
// Loop through the items array to see if it there
for (int x = 0; x< itemsArr.length; x++)
{
}
else
// If the item number is found
if (item == itemsArr[x])
{
}
if (valid == true)
}
valid = true;
price = priceArr[x];
JOptionPane.showMessageDialog(null, "The price of item " +
JOptionPane.showMessageDialog(null, "The item you chose: "
// Reset the values
price = 0.0;
itemEntered = "";
valid = false;
while (!itemEntered.equals("9999"));
JOptionPane.showMessageDialog(null, "Program complete");
Transcribed Image Text:item + " is $" + price); } } // If the item number entered is valid if (!itemEntered.equals("9999")) } { + item + " is invalid, please try again."); // Loop through the items array to see if it there for (int x = 0; x< itemsArr.length; x++) { } else // If the item number is found if (item == itemsArr[x]) { } if (valid == true) } valid = true; price = priceArr[x]; JOptionPane.showMessageDialog(null, "The price of item " + JOptionPane.showMessageDialog(null, "The item you chose: " // Reset the values price = 0.0; itemEntered = ""; valid = false; while (!itemEntered.equals("9999")); JOptionPane.showMessageDialog(null, "Program complete");
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 6 images

Blurred answer
Follow-up Questions
Read through expert solutions to related follow-up questions below.
Follow-up Question

I did not ask for a the output on a GUI. I need lines

Solution
Bartleby Expert
SEE SOLUTION
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning