Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Minnesota, 1 0 0 0 0 , 5 5 1 1 0 Kansas, 2 0 0 0 0 , false Michigan, 1 9 0 0

Minnesota, 10000,55110
Kansas, 20000, false
Michigan, 19000, true
New York, 30000, false
Washington, 52000, true
Nevada, 35000, true
Oregon, 12500,97001
California, 38000, false
Texas, 25000, true
Florida, 15000, false
Louisiana, 22000,70001
Winconsin, 9000,53001
Iowa, 5000,50001
North Dakota, 37000, true
South Carolina, 15000, false
Utah, 4000,55612
Montana, 65000,76290
Colorado, 25000,87501
New Jersey, 21000,08625
South Dakota, 70000,08515
Looking to printprint txt file into Zip/TF,10 each, just stuck. Code giving error
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
public class Main {
public static void main(String[] args){
MarketTypesLists lists = new MarketTypesLists();
// Example: Read from a file and populate lists
String fileName = "spot.txt"; // Provide correct file path
try (BufferedReader reader = new BufferedReader(new FileReader(fileName))){
String line;
while ((line = reader.readLine())!= null){
String[] parts = line.split(","); // Assuming comma-separated values
if (parts.length <3){
System.err.println("Invalid line format: "+ line);
continue;
}
int type = Integer.parseInt(parts[0].trim()); // Assuming type is the first field
String name = parts[1].trim(); // Assuming name is the second field
int value1= Integer.parseInt(parts[2].trim()); // Assuming value1 is the third field
if (type ==1){
int value2=(parts.length >=4)? Integer.parseInt(parts[3].trim()) : 0; // Optional value2
Zip itemA = new Zip(name, value1, value2);
lists.add(itemA);
} else if (type ==2){
boolean value2=(parts.length >=4)? Boolean.parseBoolean(parts[3].trim()) : false; // Optional value2
TF itemB = new TF(name, value1, value2);
lists.add(itemB);
} else {
System.err.println("Invalid type: "+ type);
}
}
} catch (IOException e){
e.printStackTrace();
} catch (NumberFormatException e){
e.printStackTrace(); // Handle the specific exception
}
// Display items of type Zip
System.out.println("Items of type Zip:");
lists.displayZip();
// Display items of type TF
System.out.println("Items of type TF:");
lists.displayTF();
// Test methods like indexOf, getZip, getTF, add(index, item), remove, removeZip, removeTF
// Example:
int indexA = lists.indexOf(new Zip("Minnesota",10000,55110));
System.out.println("Index of ItemA 'Minnesota': "+ indexA);
Zip retrievedA = lists.getZip(0);
System.out.println("Item at index 0 in Zip list: "+ retrievedA);
}
}

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

Bioinformatics Databases And Systems

Authors: Stanley I. Letovsky

1st Edition

1475784058, 978-1475784053

More Books

Students also viewed these Databases questions