Question

Parallel Arrays Summary In this lab, you use what you have learned about parallel arrays to...

Parallel Arrays

Summary

In this lab, you use what you have learned about parallel arrays to complete a partially completed Java program. 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. The data file provided for this lab includes the necessary variable declarations and input statements. You need to write the part of the program that searches for the name of the coffee add-in(s) and either prints the name and price of the add-in or prints the error message if the add-in is not found.

Instructions

  1. Study the prewritten code to make sure you understand it.
  2. Write the code that searches the array for the name of the add-in ordered by the customer.
  3. Write the code that prints the name and price of the add-in or the error message, and also write the code that prints the total order cost.
  4. Execute the program using the following data:
 Cream
Caramel
Whiskey
chocolate
Chocolate
Cinnamon
Vanilla 

// JumpinJive.java - This program looks up and prints the names and prices of coffee orders.
// Input: Interactive.
// Output: Name and price of coffee orders or error message if add-in is not found.

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();
      // Write the rest of the program here.
    
   } // End of main() method.
} // End of JumpinJive class.

How to make this work?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

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();
do{
   // making foundIt false for every item
   foundIt=false;
   //iterating the items array
   for(x=0;x<addIns.length;x++){
       //checking if item found in list
       if(addIns[x].equals(addIn)){
           //if found getting the price from the prices array
           orderTotal+=addInPrices[x];
           //adding to the total
           foundIt=true;
           //breaking the loop
           break;
       }
   }
   //checking if the item found in the array
   if(!foundIt){
       System.out.println("Sorry, we do not carry that");
   }
   System.out.print("Enter coffee add-in or XXX to quit: ");
addIn = input.nextLine();
}while(!addIn.equalsIgnoreCase("XXX"));
System.out.println("Order total: "+orderTotal);
// Write the rest of the program here.
  
} // End of main() method.
} // End of JumpinJive class.

Add a comment
Know the answer?
Add Answer to:
Parallel Arrays Summary In this lab, you use what you have learned about parallel arrays to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 5 5 - Parallel Arrays in Python Mind Tap - Cengage Lea x + V A...

    5 5 - Parallel Arrays in Python Mind Tap - Cengage Lea x + V A https//ng.cengage.com/static/nb/ui/evo/index.html?deploymentid=5745322406056533358933471518eISBN=9781337274509&id=586434 145&snapshotld: L x ... € → O 1 » CENGAGE MINDTAP Q Search this course x Parallel Arrays in Python D Parallel Lists Jumpinjive.py + > Terminal + 1 # Jumpin Java.py - This program looks up and prints the names and prices of coffee orders. 2 # Input: Interactive 3 # Output: Name and price of coffee orders or error message if...

  • In Java. Write a GUI contact list application. The program should allow you to input names...

    In Java. Write a GUI contact list application. The program should allow you to input names and phone numbers. You should also be able to input a name and have it display the previously entered phone number. The GUI should look something like the following, although you are welcome to format it in any way that works. This should be a GUI application with a JFrame. The program should contain two arrays of Strings. One array will contain a list...

  • In this module, you learned about Arrays in C++ and how to implement arrays within your...

    In this module, you learned about Arrays in C++ and how to implement arrays within your C++ programs. For this assignment, you will implement your knowledge of arrays for Michigan Popcorn Company’s sales management system. Write a program that lets the Michigan Popcorn Company keep track of their sales for seven different types of popcorn they produce: plain, butter, caramel, cheese, chocolate, turtle and zebra. It should use two parallel seven-element arrays: an array of strings that holds the seven...

  • I need to write a loop that examines the names of the cities stored in the...

    I need to write a loop that examines the names of the cities stored in the array. Write code that tests for a match Write code that, when appropriate, prints the message: Not a city in Illinois _______________________________________________________________ ' IllinoisCities.vb - This program prints a message for invalid cities in Illinois. ' Input: Interactive ' Output: Error message or nothing Option Explicit On Option Strict On Module IllinoisCities    Sub Main()       ' Declare variables.         Dim city As String                 ...

  • Q1) How would you declare an array of doubles called myDoubles? Arrays can be initialized in...

    Q1) How would you declare an array of doubles called myDoubles? Arrays can be initialized in one of two ways. In one method, the array elements are placed in a list enclosed in curly braces after the array name definition. For example, the code below creates an array of ints with 3 elements: 1, 2 and 3. int[] a = {1, 2, 3, 4}; We can also initialize an array with a new construct, indicating how many elements we want...

  • This lab is to give you more experience with C++ Searching and Sorting Arrays Given a...

    This lab is to give you more experience with C++ Searching and Sorting Arrays Given a file with data for names and marks you will read them into two arrays You will then display the data, do a linear search and report if found, sort the data, do a binary search. Be sure to test for found and not found in your main program. Read Data Write a function that reads in data from a file using the prototype below....

  • For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java...

    For this assignment, you will use your knowledge of arrays and ArrayLists to write a Java program that will input a file of sentences and output a report showing the tokens and shingles (defined below) for each sentence. Templates are provided below for implementing the program as two separate files: a test driver class containing the main() method, and a sentence utilities class that computes the tokens and shingles, and reports their values. The test driver template already implements accepting...

  • This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to...

    This C++ Programs should be written in Visual studio 2017 PROGRAM 1: Comparing Using Arrays to Using Individual Variables One of the main advantages of using arrays instead of individual variables to store values is that the program code becomes much smaller. Write two versions of a program, one using arrays to hold the input values, and one using individual variables to hold the input values. The programs should ask the user to enter 10 integer values, and then it...

  • CAN SOMEONE PLEASE HELP ME WRITE THIS CODE IN C++, PLEASE HAVE COMMENTS IN THE CODE...

    CAN SOMEONE PLEASE HELP ME WRITE THIS CODE IN C++, PLEASE HAVE COMMENTS IN THE CODE IF POSSIBLE!! General Description: Write a program that allows the user to enter data on their friends list. The list holds a maximum of 10 friends, but may have fewer. Each friend has a name, phone number, and email address. The program first asks the user to enter the number of friends (1-10). You are not required to validate the entry, but you may...

  • In this question you have to write a complete function. MyMedia Publishers uses two parallel arrays...

    In this question you have to write a complete function. MyMedia Publishers uses two parallel arrays to keep track of the number of subscriptions for each of their 50 publications. Array publications holds the names of the magazines and newspapers published and array subscriptions holds the number of subscriptions for each corresponding magazine or newspaper. You have to write a void function, called findMost Subs to determine which publication has the most subscribers. Function findMost Subs has to return the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT