You work at a soft drink distributorship that sells at most 100 different kinds of soft drinks. This program will process weekly transactions and allow for a report to be displayed that includes the soft-drink name, ID number, starting inventory, final inventory, and the number of transactions received.
There are two data files, data7.txt 
and data7trans.txt
, which hold the initial soft drink information
and transactions, respectively. The file data7.txt
consists of at most 100 lines where each line
contains the soft drink name (string), ID number (string), and the
starting inventory of cases (int).
The file data7trans.txt
holds the transactions. Each transaction consists
of the ID number followed by the number of cases purchased
(positive integer), or the amount sold (negative integer). In the
case of an invalid ID number, do not process the data (ignore it,
no error message).
Sample data7.txt:
Coke 123 100 Pepsi 345 50 CanadaDry 678 75 DrPepper 444 120
Sample data7trans.txt:
345 10 123 -5 345 10 678 8 444 20 444 -20 444 10 999 5 345 10 123 -25
The displayReport function displays the drink name, ID number, starting inventory, final inventory, and the number of transactions processed.
For the sample data, the output of your program would be as follows:
Soft drink ID number Starting Inventory Final Inventory # transactions Coke 123 100 70 2 Pepsi 345 50 80 3 CanadaDry 678 75 83 1 DrPepper 444 120 130 3
Write a SoftDrinkInventory class with the following functionality:
public SoftDrinkInventory: Is a constructor that initializes arrays holding soft drink name, ID number, and starting inventory from data file. The array holding final inventory is set to the same values as the starting inventory and transaction counts array is initialized to zero (initialize described below is used for this).
public processTransactions: Processes the transactions by correctly adjusting the final inventory and transaction counts arrays. Data for IDs which don't exist are not processed.
public displayReport: Displays a report including soft drink name, ID number, starting inventory, final inventory, and number of transactions processed.
private findID: Takes an ID number parameter and returns the position in the array where the soft drink with that ID is found. A -1 value is returned if the ID is not found.
private initialize: Takes an int array parameter and initializes its array values to zero.
/** * This program tests the functionality of a the SoftDrinkInventory class. * A datafile containing initial data is used to construct a SoftDrink object. * Then transactions are processed where each transaction contains how * cases are bought or sold. A function displays a report of the drink name, * ID number, starting inventory, final inventory, and the number of * transactions processed. The largest and smallest transaction value * is displayed. */ import java.util.Scanner; import java.io.FileInputStream; import java.io.FileNotFoundException; public class SoftDrinkTester { public static void main (String[] args) { Scanner inventoryFile = null; // inventory data file Scanner transFile = null; // transaction data file // open the inventory initialization file try { inventoryFile = new Scanner(new FileInputStream("data7.txt")); } catch (FileNotFoundException e) { System.out.println("File not found or not opened."); System.exit(0); } // open the file containing the buy/sell transactions try { } catch (FileNotFoundException e) { System.out.println("File not found or not opened."); System.exit(0); } // instantiate the soft drink distributorship object // and process the transactions by updating the inventory totals } } 
import java.util.Scanner;
public class SoftDrinkInventory {
private String names[];
private int ids[];
private int startingInventorys[];
private int finalInventorys[];
private int transactions[];
private int total = 0;
public SoftDrinkInventory(Scanner in) {
names = new String[100];
ids = new int[100];
startingInventorys = new
int[100];
finalInventorys = new
int[100];
transactions = new int[100];
initialize(ids);
initialize(startingInventorys);
initialize(finalInventorys);
initialize(transactions);
String temp[];
while (in.hasNextLine()) {
names[total] =
in.next();
ids[total] =
in.nextInt();
int val =
in.nextInt();
startingInventorys[total] = val;
finalInventorys[total] = val;
total++;
}
}
public void processTransactions(int id, int items)
{
int ind = findID(id);
if (ind != -1) {
transactions[ind]++;
finalInventorys[ind] += items;
}
}
public void displayReport() {
System.out
.println("Soft Drink\tID Number\tStarting
Inventory\tFinal Inventory\t# transactions");
for (int i = 0; i < total; ++i)
{
if
(names[i].length() < 6) {
System.out.printf("%s\t\t%d\t\t%d\t\t\t%d\t\t\t%d\n",
names[i],
ids[i],
startingInventorys[i], finalInventorys[i],
transactions[i]);
}
else{
System.out.printf("%s\t%d\t\t%d\t\t\t%d\t\t\t%d\n", names[i],
ids[i],
startingInventorys[i], finalInventorys[i],
transactions[i]);
}
}
}
private int findID(int id) {
for (int i = 0; i < total; ++i)
{
if (ids[i] ==
id) {
return i;
}
}
return -1;
}
private void initialize(int arr[]) {
for (int i = 0; i < arr.length;
++i) {
arr[i] =
0;
}
}
}
__________________________________________________________________________________

import java.util.Scanner;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
public class SoftDrinkTester {
public static void main (String[] args)
{
Scanner inventoryFile =
null;
// inventory data file
Scanner transFile =
null;
// transaction data file
SoftDrinkInventory s =
null;
// open the inventory
initialization file
try {
inventoryFile = new Scanner(new
FileInputStream("data7.txt"));
s = new SoftDrinkInventory(inventoryFile);
}
catch
(FileNotFoundException e) {
System.out.println("File not found or not opened.");
System.exit(0);
}
// open the file
containing the buy/sell transactions
try {
transFile = new Scanner(new
FileInputStream("data7trans.txt"));
while(transFile.hasNextLine()){
int id = transFile.nextInt();
int items = transFile.nextInt();
s.processTransactions(id, items);
}
s.displayReport();
}
catch
(FileNotFoundException e) {
System.out.println("File not found or not opened.");
System.exit(0);
}
}
}
You work at a soft drink distributorship that sells at most 100 different kinds of soft...
Write a program in C++ that simulates a soft drink machine. The program will need several classes: DrinkItem, DrinkMachine and Receipt. For each of the classes you must create the constructors and member functions required below. You can, optionally, add additional private member functions that can be used for doing implementation work within the class. DrinkItem class The DrinkItem class will contains the following private data members: name: Drink name (type of drink – read in from a file). Type...
write a code on .C file
Problem Write a C program to implement a banking application system. The program design must use a main and the below functions only. The program should use the below three text files that contain a set of lines. Sample data of these files are provided with the assessment. Note that you cannot use the library string.h to manipulate string variables. For the file operations and manipulations, you can use only the following functions: fopen(),...
FOR JAVA: Summary: Create a program that adds students to the class list (see below). The solution should be named Roster402_v2.java. Allow the user to control the number of students added to the roster. Ask if the user would like to see their new roster to confirm additions. If yes, then display contents of the file, if no, end the program. ------------------------------------------------------------------------------------- List of student names and IDs for class (this will be your separate text file): Jones, Jim,45 Hicks,...
Make the following modifications/enhancements to Version 0 of the Phonebook application: The phonebook should now contain a first name as well as a last name. The format of the entries in the file should be: last-name first-name phone-number The lookup process now prompts for both a last and a first name A reverse lookup should also be provided, allowing a name to be obtained by supplying the phone number. Rather than continuing until the user signals end-of-file (at the keyboard),...
Language Java Step 1: Design a class called Student. The Student class should contain the following data: firstName lastName studentID totalCredits gpa Your class should implement the “sets” and “gets” for the class. Include methods: equals, compareTo, toString. Change the toString method (from class) to put each member variable on a new line. Step 2: Write a driver program to test that Student works correctly. Test is with 3 students as given in class. Step 3: Write a “registration” program...
Write in JAVA Get Familiar with the Problem Carefully read the program description and look at the data file to gain an understanding of what is to be done. Make sure you are clear on what is to be calculated and how. That is, study the file and program description and ponder! Think! The Storm Class Type Now concentrate on the Storm class that we define to hold the summary information for one storm. First, look at the definition of...
I am really struggling with this assignment, can anyone help? It is supposed to work with two files, one that contains this data: 5 Christine Kim # 30.00 3 1 15 Ray Allrich # 10.25 0 0 16 Adrian Bailey # 12.50 0 0 17 Juan Gonzales # 30.00 1 1 18 J. P. Morgan # 8.95 0 0 22 Cindy Burke # 15.00 1 0 and another that contains this data: 5 40.0 15 42.0 16 40.0 17 41.5...
Write a program that can read XML files for customer accounts receivable, such as <ar> <customerAccounts> <customerAccount> <name>Apple County Grocery</name> <accountNumber>1001</accountNumber> <balance>1565.99</balance> </customerAccount> <customerAccount> <name>Uptown Grill</name> <accountNumber>1002</accountNumber> <balance>875.20</balance> </customerAccount> </customerAccounts> <transactions> <payment> <accountNumber>1002</accountNumber> <amount>875.20</amount> </payment> <purchase> <accountNumber>1002</accountNumber> <amount>400.00</amount> </purchase> <purchase> <accountNumber>1001</accountNumber> <amount>99.99</amount> </purchase> <payment> <accountNumber>1001</accountNumber> <amount>1465.98</amount> </payment> </transactions> </ar> Your program should construct an CustomerAccountsParser object, parse the XML data & create new CustomerAccount objects in the CustomerAccountsParser for each of the products the XML data, execute all of...
You’ll create the parser with a 2-part layered approach. You’ll first create a Lexer, which will read characters from a file and output tokens. Then you’ll write the second part, which will process the tokens and determine if there are errors in the program. This program have 3 files Lexer.java, Token.java, Parser.java Part 1 Lexer: The class Lexer should have the following methods: public constructor which takes a file name as a parameter○private getInput which reads the data from the...
Question I This question carries 20% of the marks for this assignment. You are asked to develop a set of bash shell script: Write a script that asks for the user's salary per month. If it is less or equals to 800, print a message saying that you need to get another job to increase your income, what you earn is the Minim living cost. If the user's salary is higher than 800 and below 2000, print a message telling...