Write Code Segments that Require ArrayList Objects
Your Turn
- Write program code to complete the provided tasks.
- While these problems can be solved using other loop types, use a
forloop to solve them. - Run the code in the Java Playground to see if your code generates the desired result.
- Make necessary changes until you have satisfied the tasks.
Practice 1: Update Inventory
- Analyze the provided code segment and predict the output.
- Try the code in the Java Playground to verify your prediction.
- The store wants to increase all of the prices. Write program code to increase all the prices by 0.25.
- Analyze the code segments and predict the output. Verify your prediction by running it in the Java Playground.
- The cost of apples was entered incorrectly. Change the price of the apples to 2.75.
- Analyze the code segments and predict the output. Verify your prediction by running it in the Java Playground.
Practice 2: Book Inventory
- Analyze the provided code segment and predict the output.
- Try the code in the Java Playground to verify your prediction.
- Write code to check out "Learn Java" if it hasn't already been checked out.
- Analyze the code segments and predict the output. Verify your prediction by running it in the Java Playground.
- Write code to return "Thrillers" back to inventory.
- Analyze the code segments and predict the output. Verify your prediction by running it in the Java Playground.
- Write code to add the following books to the inventory. They are all new and not checked out: "Mystery Rivers", "Games for Good", and "Write Like A Pro".
- Analyze the code segments and predict the output. Verify your prediction by running it in the Java Playground.
- Write code to print all available books to the console.
- Analyze the code segments and predict the output. Verify your prediction by running it in the Java Playground.