Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Having the ability to write to a sequential file enables us to retain data for future retrieval and use. Sequential files have these modes
Having the ability to write to a sequential file enables us to retain data for future retrieval and use. Sequential files have these modes for input and output. File Processing Modes Description Read the file is opened for input and existing data is read from the file Write the file is opened for output and new data is written in the file Append the file is opened for output and new data is written at the end of the file The Input, Process and Output (IPOS) requirements of this project are: Input the data records to be written to the file, the data records that are read from the data files, the type of data query to be performed and the data analysis that is to be written to a separate text file Process the data to write, the data to read, the individual queries and the analytical report to be written to an output file Output any data written to the inventory data file and any data written to the inventory analysis output file Required all dollar amounts displayed in a currency format My Courses & Academics - oakton.edu PROJECT Data Structures - File Processing for Inventory Analysis Steps to Complete This Project STEP 1 Open an Integrated Development Environment (IDE) d2l.oakton.edu Open Eclipse, Net Beans, MS Visual Studio, VSCode or similar programming text editor/compiler. STEP 2 Write the Program Code Write the program code that will satisfy the requirements of this project. Into your source code, place your own name, as a comment, as the program writer. Begin coding your application by following these steps. For data input purposes, use a Scanner class object by placing these three statements in appropriate places in your source code. import java.util.Scanner; // declare a Scanner class object Scanner sc = new Scanner(System.in); Using this import statement, assign a file name to the file objects. import java.io.*; // assign a file name and declare the file objects String myFile = "C:\\Temp\\data.txt"; FileWriter file = new FileWriter(myFile); Print Writer outfile = new PrintWriter(file); Declare some local variables that will represent the number of records and the columns of the inventory data table. View as Page ] D2L CSC_241_LAB_06_2022 - CSC-241-0C1 - Java Data Structures d2l.oakton.edu My Courses & Academics - oakton.edu Declare some local variables that will represent the number of records and the columns of the inventory data table. D2L CSC_241_LAB_06_2022 - CSC-241-0C1 - Java Data Structures // variable for the number of records in the data table int numRecords = 0; // variables for the fields of the data table String strName = ""; double dblCost = 0; int intQuantity = 0; char chrLocation = '\0'; Request the number of records to be processed. // input the number of records to be processed System.out.println("How many records are for processing?"); numRecords = sc.nextInt(); Open a for() loop to process the records in the data table. for (int i = 1; i My Courses & Academics - oakton.edu // obtain user input System.out.println("item description"); strName = sc.next(); System.out.println("item cost"); dblCostsc.nextDouble(); System.out.println("item quantity"); intQuantity = sc.nextInt(); System.out.println("item location"); chrLocation = sc.next().charAt(0); Within the for() loop, write the data to the associated text file. // write the data to the file outfile.print(strName + ","); outfile.print(dblCost + ","); outfile.print(intQuantity + ","); outfile.println(chrLocation); Close the body of the for () loop. Close the Scanner class object and PrintWriter object. STEP 3 Build, Compile and Run the Program Compile and run your program code statements. Correct any syntax or compile errors. d2l.oakton.edu STEP 4 Test the Program Once you have successfully compiled your program, use the following data, when prompted, into your application. Each data record consists of an item's description, the item cost the item quantity and a warehouse location code. View as Page Item Cost Quantity Location Code D2L CSC_241_LAB_06_2022 - CSC-241-0C1 - Java Data Structures My Courses & Academics - oakton.edu STEP 5 Verify Your Output d2l.oakton.edu Item Cost Quantity Location Code Item 1 $2.72 16 C Item 3 $18.73 108 A Item 4 $ 107.11 22 C Item 6 $73.18 93 B Item 9 $ 64.79 8 A Locate and open the data file and observe its contents. Verify the accuracy of your data that was input. D2L CSC_241_LAB_06_2022 - CSC-241-0C1 - Java Data Structures STEP 6 Modify Your Program (Read the Data) Return to your Code window and supplement the program with even more additional code statements. Place the new statements before the close of your main() method. PROJECT Data Structures - File Processing for Inventory Analysis Begin coding your modified application by following these steps. Use these import statements that are necessary to include for reading the text file for which you just recorded some values. import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; Assign a file name to the file objects. // assign a file name and declare the file objects String dataFile = = "C:\\Temp\\data.txt"; String line = ""; String csv = "','"; FileReader fileIn = new FileReader(dataFile); View as Page 1 My Courses & Academics - oakton.edu import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; Assign a file name to the file objects. // assign a file name and declare the file objects String dataFile = "C:\\Temp\\data.txt"; String line = ""; String csv = " , , FileReader fileIn = new FileReader(dataFile); BufferedReader br = new BufferedReader(fileIn); Open a try{} block to place the code that will read the records. while ((line = br.readLine()) != null) { // use comma as a value separator String[] data = line.split(csv); System.out.println(data[0] + "," + data[1] + data[2] + "," + data[3]); + } Open a catch{} block to complement the try{} block. catch (IOException e) { e.printStackTrace(); } Close BufferedReader the object. br.close(); d2l.oakton.edu D2L CSC_241_LAB_06_2022 - CSC-241-0C1 - Java Data Structures Save your modified program and run the program. If you choose, you can block the write code portion of the program to prevent re - entering the data and thus just read the data file. View as Page 1 + My Courses & Academics - oakton.edu STEP 7 Analyze the Inventory Return to your source code and write some code to analyze the inventory. Construct at least three queries based on the table of records. PROJECT Data Structures - File Processing for Inventory Analysis Some examples of data queries that you can incorporate into your application include: Determine the number of items that are categorized by the same inventory location. Determine the number of items that have an item cost that exceeds $ 100. Determine the average quantity on hand in the inventory. d2l.oakton.edu Ensure that all dollar amounts are displayed in a currency format in your program output. If you choose you can write these inventory analysis queries into a separate text file. D2L CSC_241_LAB_06_2022 - CSC-241-0C1 - Java Data Structures STEP 8 Submit Your Project Once you have determined that your modified program is satisfying this project's requirements, complete the submission process as follows: Open MS Word and type a heading for a new document that includes your full name, course number, lab number and date. Within the document paste a snapshot of your program code. Label your snapshot with a reasonable description. After the snapshot, paste the output that appears in your Console screen. Note - you can use the Windows Snipping Tool, which is part of the Windows Accessories Group, to easily capture your Console window. View as Page
Step by Step Solution
★★★★★
3.45 Rating (158 Votes )
There are 3 Steps involved in it
Step: 1
The algorithm of the code is given below 1 Initialize variables and objects for input output and data processing 2 Prompt the user for the number of records to process 3 Loop for each record a Collect ...Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started