- Joined
- Mar 16, 2007
- Sythe Gold
- 248
- Messages
- 23,694
- Location
- Georgia
- Discord Unique ID
- 100075291572998144
Code:
public static void readFile() throws IOException{
BufferedReader read = new BufferedReader(new FileReader("src/receipts.txt"));
Item[] items = new Item[12];
String line;
int lineCount = 0;
while ((line = read.readLine()) != null) {
lineCount++;
}
System.out.println(lineCount);
for(int i = 0; i<lineCount ; i++){
System.out.println(i);
String code = read.readLine();
String description = read.readLine();
double price = read.read();
int stock = read.read();
items[i] = new Item(code,description,price,stock);
}
}
output:
60
0
1
2
3
4
5
6
7
8
9
10
11
12
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 12
at Read.readFile(Read.java:27)
at Functionality.main(Functionality.java:16)
Code:
GR0001
Kleenex Toilet Rolls 18 pk
6.00
200
TF0001
Heinz Baked Beans 600g
0.90
500
GR0002
Morning Fresh Dishwashing Liquid 1 ltr
3.25
150
TF0002
John West Tuna 450g
2.75
35
PF0001
Vetta Spaghetti No 9. 500g
1.50
120
TF0003
Heinz Big Eat Meatballs 485g
1.20
20
PF0002
Vetta Egg Fettuccini 500g
2.50
100
TF0004
Heinz Peas ‘n Corn 485g
0.90
210
PF0003
Vetta Bolognese Sauce 575g
3.00
160
GR0003
Morning Fresh Dishwasher Tablets 6pk
5.50
90
GR0004
Chux Kitchen Wipes 10pk
1.50
70
PF0004
Vetta Carbonara Sauce 575g
3.00
30
,,,,,,









