Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

import java.util.*; import java.io.*; public class VendorPricesReader { public static void main(String[] args) throws IOException { /* * Create a Java program that reads the

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

public class VendorPricesReader {

public static void main(String[] args) throws IOException { /* * Create a Java program that reads the contents of the text given file (vendorPrices.csv). * Read the file line by line using @Scanner * @parse each int into an array */ BufferedReader br = null; try(FileInputStream file = new FileInputStream("vendorPrices.csv");) { Scanner sr = new Scanner(file); String line = sr.nextLine(); sr.useDelimiter(","); // delimit by line while(sr.hasNextLine()) { System.out.println(line); } } }

}

For some reason my Java code is stuck in an infinite loop some how only reading the first line of the csv file. there are 5000 rows different rows that look similar to the one be low, but my code is stuck on the first line. We are using file output stream and random access file as well as scanners, delimiter, and any other techniques that can get the expected result. No token or tokenizer.

repeating output:

1,17,40,61,25,42,56,40,44,59,22,18,18,66,52,56,44,28,45,60,27,70,61,42,70,36,73,46,50,28,33,31,24,44,40,19,61,43,29,58,34,74,12,21,19,12,56,17,61,50,19,75,47,29,39,51,69,44,12,74,60,55,35,25,54,36,33,14,65,67,72,57,66,38,18,40,51,63,19,46,49,60,58,40,59,69,37,24,30,45,35,71,46,18,36,52,43,16,68,61,38,13,72,58,19,37,50,72,66,53,51,24,75,44,24,41,28,52,52,59,45,25,24,22,12,34,55,55

The problem I'm coding for:

A file called vendorPrices.csv contains a list of vendor IDs in column 1 and prices for item numbers in all other columns. These product numbers are highly simplified and are referred to simply by the index, e.g. product ID 4 would be the 5th column (the first column is the vendor ID).

Create a Java program that reads the contents of the text given file (vendorPrices.csv).

Next output all of the data in binary form to another file vendorPrices.db.

Lastly, prompt a user for input (in a loop where any invalid vendor ID exits the application).

The user should enter a vendor ID (the row #) and product ID (the column # offset by one).

Print the price to the screen.

Verify that your program works as expected and that there isn't much of a lag in the lookup time.

If you have extra time and want to compare, do the lookup in the random access file and in the original CSV and compare the response times.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

More Books

Students also viewed these Databases questions