In: Computer Science
Introduction This program will read from a file containing inventory data, and display summary information to the user. Instructions and Information For this project, input will be from file, and output will be to standard output (the console). The file will be read, and the information stored in the appropriate data format and data structure. Then, the inventory data will be printed out, listing the frequency of each item next to its name. The frequency means the combined sum of all counts of each item. If an item occurs more than once in the file next to an integer (a count), then that count is added to the combined total, which will be printed out later. If an item is encountered which does not yet exist in the list of items (an ArrayList), then it is to be added as an instance of InventoryItem, a class that you must define, which includes the name and current frequency of occurrence of the item. Input The input will be obtained from a file, named input.txt. The general format of a line will be: ItemName, Count Output The output will be printed to the console, in the general format: ItemName TotalFrequency 2 Example Sample Input File Coke, 5 Pepsi, 4 BBQ Ribs, 7 Coke, 4 Veggie Burgers, 12 Pepsi 6 Sample Output Coke 9 Pepsi 10 BBQ Ribs 7 Veggie Burgers 12 Note that items that only occurred once in the input file only have that single count as their totals, but those that occur multiple times are printed out only once, but have the combined total of all occurrences (which could be 1, 2, 3, 4, or as many times as I want). Hints and Notable Requirements You should consider creating two classes to help you solve the problem: • InventoryItem o Represents a single, unique inventory item group o Maintains the name of the item and the frequency of occurrence of the item (the total count) o You should have a constructor to set the name and original frequency when first encountered o You should have standard setters and getters for the fields o You should have a method, named increaseBy that takes a single parameter, the amount to increase the internal count (frequency) by if lines additional to the original line are encountered o There should be NO print statements inside this class • InventoryItemDemo o This class will contain the main method o You must read the file o You must create instances of InventoryItem, and store them in an ArrayList o If you encounter the name of an item that already exists in the array list, you find that inventory item and increase its count appropriately o Once all information is read from the file and all the objects are created, you should iterate through them and print out their total frequencies
Answer required in java
Note: Could you plz go through this code and let me
know if u need any changes in this.Thank You
_________________
// InventoryData.txt
Coke, 5
Pepsi, 4
BBQ Ribs, 7
Coke, 4
Veggie Burgers, 12
Pepsi, 6
________________
// InventoryItem.java
public class InventoryItem {
//Declaring instance variables
private String name;
private int count;
//Parameterized constructor
public InventoryItem(String name, int count) {
this.name = name;
this.count = count;
}
// getters and setters
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public void increaseBy(int count) {
this.count += count;
}
}
_____________________
// InventoryItemDemo.java
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Scanner;
public class InventoryItemDemo {
public static void main(String[] args) {
String name,str;
int count;
ArrayList<InventoryItem>
arls=new ArrayList<InventoryItem>();
try {
Scanner sc=new Scanner(new
File("InventoryData.txt"));
while(sc.hasNext())
{
str=sc.nextLine();
String
arr[]=str.split(", ");
InventoryItem
i=new InventoryItem(arr[0],Integer.parseInt(arr[1]));
for(int
j=0;j<arls.size();j++)
{
if(arls.get(j).getName().equals(arr[0]))
{
arls.get(j).increaseBy(Integer.parseInt(arr[1]));
}
}
arls.add(i);
}
sc.close();
System.out.println("Item\t\tFrequency");
System.out.println("----\t\t--------");
for(int
i=0;i<arls.size();i++)
{
System.out.printf("%-15s%10d\n",arls.get(i).getName(),arls.get(i).getCount());
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
__________________________
Output:
Item Frequency
---- --------
Coke 9
Pepsi 10
BBQ Ribs 7
Coke 4
Veggie Burgers 12
Pepsi 6
_______________Could you plz rate me well.Thank You