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

1 Expert Approved Answer
Step: 1 Unlock

This code segment initializes arrays to store valid item numbers and their corresponding prices It t... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!