Question
Explain the following code: 1. Explain what the code does, you do not have to explain each line. 1.final int NUMBER_OF_ITEMS =
Explain the following code:
1. Explain what the code does, you do not have to explain each line.
1.final int NUMBER_OF_ITEMS = 10;
int[] validValues = {101, 108, 201, 213, 266,
1.304, 311, 409, 411, 412};
double[] prices = {0.29, 1.23, 3.50, 0.69, 6.79,
1.3.19, 0.99, 0.89, 1.26, 8.00};
String strItem; int itemOrdered; double itemPrice = 0.0;
1.boolean isValidItem = false;
strItem = JOptionPane.showInputDialog(null, "Enter the item number you want to order"); itemOrdered = Integer.parseInt(strItem);
for(int x = 0; x < NUMBER_OF_ITEMS; ++x)
{
if(itemOrdered == validValues[x])
{
isValidItem = true; itemPrice = prices[x];
}
}
Your answer here:
2. for(int x = 0; x < mySentence.length(); ++x)
if(mySentence.charAt(x) == ' ')
2.++countOfSpaces;
2.
Your answer here:
3. Re-write the following code using a switch statement
If (selection == 'A')
System.out.println("You Selected A.");
else If (selection == 'B')
System.out.println("You Selected B.");
else If (selection == 'C')
System.out.println("You Selected C.");
else If (selection == 'D')
System.out.println("You Selected D.");
else System.out.println("Guess you don't know what you want?.");
Your answer here:
Step by Step Solution
There are 3 Steps involved in it
Step: 1
This code segment initializes arrays to store valid item numbers and their corresponding prices It t...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started