Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Programming questions

Question

please help god bless math wizards

Answered: 1 week ago