Question
LAB-2 Parallel Arrays In this lab, you use what you have learned about parallel arrays to execute a Java program that has been completed for
LAB-2 Parallel Arrays
In this lab, you use what you have learned about parallel arrays to execute a Java program that has been completed for you. The program should either print the name and price for a coffee add-in from the Jumpin Jive coffee shop or it should print the message: "Sorry, we do not carry that.".
Read the problem description carefully before you begin.
- Open the source code file named JumpinJive.java using Notepad or the IDE of your choice.
- Compile and execute code provided; Attach execution results to Moodle see sample below
- Explain in your own words how the logic works
import java.util.Scanner;
public class JumpinJive { public static void main(String args[]) throws Exception { // Declare variables. String addIn; // Add-in ordered by customer. final int NUM_ITEMS = 5; // Named constant // Initialized array of add-ins. String addIns[] = {"Cream", "Cinnamon", "Chocolate", "Amaretto", "Whiskey"}; // Initialized array of add-in prices. double addInPrices[] = {.89, .25, .59, 1.50, 1.75}; boolean foundIt; int x; // Loop control variable. double orderTotal = 2.00; // All orders start with a 2.00 charge
// Get user input. Scanner input = new Scanner(System.in); System.out.print("Enter coffee add-in or XXX to quit: "); addIn = input.nextLine(); while(addIn.compareTo("XXX") != 0) { foundIt = false; // Loop through array. for(x = 0; x < NUM_ITEMS; x++) { // Test for a match. if(addIn.compareTo(addIns[x]) == 0) { System.out.println(addIn + " Price is $" + addInPrices[x]); orderTotal += addInPrices[x]; foundIt = true; } } if (foundIt == false) System.out.println("Sorry we do not carry that."); System.out.print("Enter coffee add-in or XXX to quit: "); addIn = input.nextLine(); } System.out.println("Order Total" + " is $" + orderTotal); System.exit(0); } // End of main() method. } // End of JumpinJive class.
the program is complete I need help with the third question "Explain in your own words how the logic works"
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started