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
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
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
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
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);](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe4aa3b5e-e7fa-4aac-8b86-8434ebe6fb39%2Fe3e9cf21-a5ce-4813-924e-dc512ab3f19b%2F2rear2_processed.png&w=3840&q=75)
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");](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fe4aa3b5e-e7fa-4aac-8b86-8434ebe6fb39%2Fe3e9cf21-a5ce-4813-924e-dc512ab3f19b%2Fm6p1s7q_processed.png&w=3840&q=75)
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

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 4 steps with 6 images

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
Knowledge Booster
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.Recommended textbooks for you

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON

Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education