Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.

  1. Open the source code file named JumpinJive.java using Notepad or the IDE of your choice.
  2. Compile and execute code provided; Attach execution results to Moodle see sample below
  3. 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

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

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions