Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

/do/conference?toggle mode-read&action; list forums C Java How To Program Please

ID: 3849206 • Letter: #

Question



/do/conference?toggle mode-read&action; list forums C Java How To Program Please state the complete source of reference a point is not from your original knowledge in order for an answer to be counted as complete Please label your answers (as which one is for which question or which part of which question, such as 1a........, 1b....., etc.) and please use separate paragraphs for your answers to individual questions or individual parts of each question. Thank you for your co-operation. would like to use Java parallel arrays to hold information of five menu items that a little restaurant sells. Each item has attributes an item number, an item name. and a unit price The system uses three parallel arrays for these three attributes. The data of these five menu items have been put into the arrays hem Number Them Name Item Price 3 Regular Hamburger Delux Hamburger 35 Coffee The application accepts an incoming item number This is the search ID Then the system looks for the information of item and displays the item name and unit if this item has been found this incoming Search ID is not one of the five menu items. the system will display an message to look Parts of the code are shown below. The for loop is for examining each item ID in the ID array the matching ID that the same as the defined class. Please also assume that there is a properly defined method main() in the tes application written separately import java util, Scanner, public void processorders0 Scanner sc new Scanner System in int itemNumber (3, 11, 17, 24, 35) Delux Hamburger", "Fries' string itemName Hamburger, 1.19 double unitPrice li 69, 2.69, 1.29 soft Drink", "Coffee? ......int inltemNo s 0; No hold the incoming ID boolean hasNextItem while (hasNextItem true) INoop to accept the tem of current order next System out print("Please enter the next menu number (3 11, 17. 24, 35 or -99-ene) -99) /lend System out printin OK, no more. Bye") false

Explanation / Answer

Q.1 Would the logic above work? Is there anything missing inside processOrder() method ?

Ans: Yes.The above logic will work fine as if we declared 'itemFound' as boolean but there is missing thing inside the code that the for loop declared inside while loop will continue its iteration if the item is found i.e. we should stop the loop if the item is found and get out of loop. For this example(as there are only 5 records) the time required to loop is not noticable but consider that there are 90000 records and the item found location is at 3rd then the loop will continue to iterate and we need to wait for its completion. The best way is to stop the loop by using 'break' once the item is found.

Q2.What is the function of itemPosition?

Ans: The function of itemPosition is to hold the position index of the found item and by using this index we can display the information of found item by providing it as array index. For example in above program to display the item name as' itemName[itemPosition]' and 'unitPrice[itemPosition]'.

Q3a.Is the for loop as writtned now is operationally efficient as it can be?

Ans: Operationally the For loop is efficient, The function of the loop is to only iterate for the specified criteria where as it is the way logic using it that makes it more efficient.

Q3b

Ans: If the item is in slot zero we should stop the loop by using 'break' to avoid unnecessary iteration and time consumption.

To be more concise with loop iteration,search and time follow this link:

http://www.programcreek.com/2014/04/check-if-array-contains-a-value-java/