Having the ability to write to a sequential file enables us to retain data for future...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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 <= numRecords; i++) { • Within the for() loop, obtain the data records information, via user input. PROJECT Data Structures - File Processing for Inventory Analysis // obtain user input System.out.println("item description"); strName=sc.next(); System.out.println("item cost"); dblCost = sc.nextDouble(); System.out.println("item quantity"); View as Page + 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 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 <= numRecords; i++) { • Within the for() loop, obtain the data records information, via user input. PROJECT Data Structures - File Processing for Inventory Analysis // obtain user input System.out.println("item description"); strName=sc.next(); System.out.println("item cost"); dblCost = sc.nextDouble(); System.out.println("item quantity"); View as Page + 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
Expert Answer:
Answer rating: 100% (QA)
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 ... View the full answer
Related Book For
Auditing and Assurance services an integrated approach
ISBN: 978-0132575959
14th Edition
Authors: Alvin a. arens, Randal j. elder, Mark s. Beasley
Posted Date:
Students also viewed these programming questions
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Let A, B be sets. Define: (a) the Cartesian product (A B) (b) the set of relations R between A and B (c) the identity relation A on the set A [3 marks] Suppose S, T are relations between A and B, and...
-
The doctrine of intention to create legal relations has now become a challenge towards the doctrine of consideration, which has been riddled with so many criticisms and as such the former doctrine...
-
Tagawa Corporation issued $500,000 of 10-year, 5% bonds on January 1, 2012, at a price to yield a market interest rate of 6%. Interest is payable semi-annually on July 1 and January 1. Tagawa has a...
-
Solve the linear equation either symbolically or graphically. x-4 2 + 1 - 2x 3
-
Lynn Goldsmith is a photographer known for her photographs of famous musicians. In 1981, Goldsmith had a photography session with the singer Prince. Three years later, Vanity Fair obtained a license...
-
La Casa Interiors deposits all cash receipts each Wednesday and Friday in a night depository, after banking hours. The data required to reconcile the bank statement as of July 31 have been taken from...
-
How do i make a ER digram like similar to the following using my relational model My Relational model is the following Has Applications ID Applications Applicant ID Job positions ID Employer ID Apply...
-
Bawl purchased ABC bonds on 1/1/21. Data regarding these available-for-sale securities follow: December 31, 2021 December 31, 2022 December 31, 2023 Select one: Cost $100,000 100,000 100,000 a....
-
What component of the cost of capital is tax-deductible for a company? Why and how?
-
Your best friend, Margo, knowing that you are taking an income tax class, has asked you for some tax advice. Margo is single and currently has a traditional IRA that she has been making deductible...
-
Explore the bottom marriage specific social mobility also give some example.
-
A first-year student has recently won a lottery of $2.5 million. Following this win, the student decides to save the money in a savings account for the next four years until she graduates. To make...
-
Can a previous loss be offset by a recovery in accounting? use actual costing because weather can greatly change their utility costs and affect her profits. evaluation of homeland security budget...
-
You are the ethical trainer for a small organization and are to provide a training session for upper management/leadership. You have acquired a Dear Abby letter, regarding cell phone use in a public...
-
Refer to the information from Exercise 22-19. Use the information to determine the (1) Weighted average contribution margin , (2) Break-even point in units, and (3) Number of units of each product...
-
Identify the four parts of the Uniform CPA Examination.
-
State the most important factors affecting the sample size in confirmations of accounts receivable.
-
Explain what is meant by lapping and discuss how the auditor can un cover it. Under what circumstances should the auditor make a special effort to uncover lapping?
-
For the probability distribution in Exercise 14, find the sampling distribution of the sample mean for all samples of size \(n=2\). (Hint: The sample means will be the same as given in Figure 3.7,...
-
Minitab can also be used to create a graphical summary of a given variable. The graphical summary can be found by selecting the Stat menu; under Basic Statistics a. Using Minitab, create a graphical...
-
Often we may be interested in comparing the amount of variability between two different data sets. This can be done using the sample coefficient of variation \((C O V)\), which is a percentage that...
Study smarter with the SolutionInn App