Question

In: Other

JAVA You will be given a grocery list, filed by a sequence of items that have already been purchased.

 Instructions

 You will be given a grocery list, filed by a sequence of items that have already been purchased. You are going to determine which items remain on the the list and output them so that you know what to buy.

 You will be give an integer n that describes how many items are on the original grocery list. Following that, you will be given an array of n grocery list items (strings) that you need to buy. After your grocery list is complete, you will receive a list of items that had already been purchased. For each of these items, if it matches any item on your grocery list, you can mark that item as purchased. You will know that you are at the end of the list of items already purchased when you receive the string "DONE".

 At that point, you will output a list of items left to buy (each item on its own line).

 Write the body of the program called PoD. java to the left.


 Input

 The program reads in the following:

 an integer (n) defining the length of the original grocery list

 in strings that make up the grocery list a list of items that had already been purchased (strings)

 in strings that make up the grocery list a list of items that had already been purchased (strings)

 the string "DONE", marking the end of all required input

 Processing

 Determine which items on the grocery list have already been purchased.

 Output

 Output the items from the grocery list that remain to be purchased (i.e. all items from the original n grocery items that were not

 included in the list of items already purchased). Each grocery item must be printed on its own line. The text must be

 purchased). Each grocery item must be printed on its own line. The text must be terminated by a new-line character.

Solutions

Expert Solution

/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class PoD
{
   public static void main (String[] args)
   {
       Scanner sc = new Scanner(System.in);
       int n = sc.nextInt();
       HashMap grocery_list = new HashMap<>();
      
       // add item to grocery list initially assuming none of item has been purchased
       // so make them zero
       for(int i=0;i            String item = sc.next();
           grocery_list.put(item, 0);
       }
      
       // as item list are purchased we mark them purchased by making it 1
       // if DOne is found we break out of loop
       while(true){
           String item = sc.next();
           if(item.equals("DONE"))
                break;
           grocery_list.put(item, 1);
       }
      
       //print item which are not purchased
       Set itemset = grocery_list.keySet();
       for(String key: itemset){
           if(grocery_list.get(key) == 0)
                System.out.println(key);
       }
   }
}

INPUT

5 apple orange eggplant carrots bananas orange carrots DONE

OUTPUT

apple
bananas
eggplant

Related Solutions

Question 1 Bach Distributors is a wholesaler of grocery items. As the accountant, you have been...
Question 1 Bach Distributors is a wholesaler of grocery items. As the accountant, you have been asked to develop the operating budgets. The budget must be prepared taking into consideration the following information: Sales 1. Sales in units are:    May (actual)       8,260    June (actual)       8,470    July           8,330    August           7,980    September       8,400    October       8,540 2. Average selling price is $17 per unit. 3. Each month’s sales will...
Grocery List Program Write a program that keeps track of the user's grocery list items. Prompt...
Grocery List Program Write a program that keeps track of the user's grocery list items. Prompt the user if they'd like to (each action is a function): See the list Display all items (if any) in the list Add item to their list Confirm with the user before adding item (y/n or yes/no) If they enter a duplicate item, notify them the item already exists Remove items from their list Confirm with the user before removing item (y/n or yes/no)...
Java Program Sequential Search You are given a sequence of n integers S and a sequence...
Java Program Sequential Search You are given a sequence of n integers S and a sequence of different q integers T. Write a program which outputs C, the number of integers in T which are also in the set S. Do not use any import sort packages. Input: In the first line n is given. In the second line, n integers are given. In the third line q is given. Then, in the fourth line, q integers are given. Output:...
*JAVA* For this assignment you have been given two classes, a Main.java and a Coin.java. The...
*JAVA* For this assignment you have been given two classes, a Main.java and a Coin.java. The coin class represents a coin. Any object made from it will have a 1) name, 2) weight and 3) value. As of now, the instance variables in Coin.java are all public, and the main function is calling these variables directly for the one coin made in it. Your goal is to enforce information hiding principles in this project. Take Coin.java, make all instance variables...
Think of items that you have purchased in a market such as ordinary items in your...
Think of items that you have purchased in a market such as ordinary items in your weekly budget like coffee or tea. 1. What price trends have you noticed over the last few years? Do the prices of coffee or tea fluctuate? Have prices increased or decreased? and How would you use what you have learned concerning Supply and Demand to explain these trends?
The < and == operators for the class Record have already been implemented for you.
The < and == operators for the class Record have already been implemented for you. Write the code necessary to complete the >, <=,>= and != operators. (hint: you do not need to know anything about the Record class to complete)
You have been given the following list of accounts and cost centers for a group of...
You have been given the following list of accounts and cost centers for a group of physician offices that you manage. The accounts are in alphabetical order. Create a numbering system for a chart of accounts using a 5-digit numbering system that incorporates the main categories of Assets, Liabilities, Equity, Expenses, and Revenues. You will have sub-accounts under these main headings. You will have to determine if the accounts are considered Assets, Liabilities, Equity, Expenses, or Revenues and indicate that...
You have been given the following list of variances for the Pennadi Company:         Direct...
You have been given the following list of variances for the Pennadi Company:         Direct materials price variance $ 16,800 U   Direct materials quantity variance 12,000 U   Direct labour rate variance 16,270 F   Direct labour efficiency variance 27,000 U   Variable overhead spending variance 3,120 U   Variable overhead efficiency variance 6,000 U   Fixed overhead budget variance 5,000 U Fixed overhead volume variance 53,250 F You have also been given the following information:         Actual units produced 25,000   Budgeted units...
You have been given the following list of variances for the Pennadi Company:         Direct...
You have been given the following list of variances for the Pennadi Company:         Direct materials price variance $ 16,800 U   Direct materials quantity variance 12,000 U   Direct labour rate variance 16,270 F   Direct labour efficiency variance 27,000 U   Variable overhead spending variance 3,120 U   Variable overhead efficiency variance 6,000 U   Fixed overhead budget variance 5,000 U Fixed overhead volume variance 53,250 F You have also been given the following information:         Actual units produced 25,000   Budgeted units...
in java please: You have been given the job of creating a new order processing system...
in java please: You have been given the job of creating a new order processing system for the Yummy Fruit CompanyTM. The system reads pricing information for the various delicious varieties of fruit stocked by YFC, and then processes invoices from customers, determining the total amount for each invoice based on the type and quantity of fruit for each line item in the invoice. The program input starts with the pricing information. Each fruit price (single quantity) is specified on...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT