From the course: Oracle Java Foundations
Unlock this course with a free trial
Join today to access over 24,700 courses taught by industry experts.
Loops: Demo 1 - Java Tutorial
From the course: Oracle Java Foundations
Loops: Demo 1
(air whooshes) (logo whooshes) - [Instructor] "Exercise 4-3: Using a loop to Process an Array." In this exercise, we'll remove the code that calculates the total, but we'll keep the declaration of the total variable and the code that prints the total value, and we'll place comments on the existing lines of code to calculate the total. And we'll ensure that we still have the total variable declared, and we'll set its value to 0. Then we're going to iterate through the array and calculate the total cost of all items, including tax. We'll create a for-each loop that iterates through all the items in the clothing array, gets the price, and adds that into the running total for the price. We'll remove code that print details of individual clothing objects, and in a loop, we'll print details of each clothing object. We'll place this code inside the loop before the total value calculation. So first, we'll retain the declaration of the total variable and the code that prints the total value…