public ArrayList loadBuses(String bfile) { ArrayList buses = new ArrayList<>(); try { Scanner scanner = new Scanner(new File(bfile)); while (scanner.hasNextLine()) { String[] line = scanner.nextLine().split(" "); if (line.length < 4 || line.length > 7) { throw new IllegalArgumentException("Invalid input format"); } String name = line[1]; int size = Integer.parseInt(line[1]); int price = Integer.parseInt(line[2]); int level = Integer.parseInt(line[3]); Ministry ministry = null; if (line.length > 5) { ministry = new Ministry(line[5]); } int competitorArea, numSecurity, barArea; Bus bus; SportsBus sportsBus; PartyBus partyBus; switch (line.length) { case 4: buses.add(new Bus(name, size, price, level, ministry)); break; case 5: int teacherArea = Integer.parseInt(line[4]); bus = new Bus(name, size, price, level, ministry); TrainingBus trainingBus = new TrainingBus(bus, teacherArea); buses.add(trainingBus); break; case 6: competitorArea = Integer.parseInt(line[5]); numSecurity = Integer.parseInt(line[5]); bus = new Bus(name, size, price, level, ministry); sportsBus = new SportsBus(bus, competitorArea, numSecurity); buses.add(sportsBus); break; case 7: competitorArea = Integer.parseInt(line[5]); numSecurity = Integer.parseInt(line[6]); barArea = Integer.parseInt(line[6]); bus = new Bus(name, size, price, level, ministry); sportsBus = new SportsBus(bus, competitorArea, numSecurity); partyBus = new PartyBus(sportsBus, barArea); buses.add(partyBus); break; } } } catch (FileNotFoundException e) { e.printStackTrace(); } return buses; } fix this so i can get output like this : 1;BUS_SML;100;200 2;BUS_BIG;850;20000 instead of this: 1;200;100;200 2;20000;850;20000 As you can see the BUS_SML AND BUS_BIG is missing please help
public ArrayList loadBuses(String bfile) { ArrayList buses = new ArrayList<>(); try { Scanner scanner = new Scanner(new File(bfile)); while (scanner.hasNextLine()) { String[] line = scanner.nextLine().split(" "); if (line.length < 4 || line.length > 7) { throw new IllegalArgumentException("Invalid input format"); } String name = line[1]; int size = Integer.parseInt(line[1]); int price = Integer.parseInt(line[2]); int level = Integer.parseInt(line[3]); Ministry ministry = null; if (line.length > 5) { ministry = new Ministry(line[5]); } int competitorArea, numSecurity, barArea; Bus bus; SportsBus sportsBus; PartyBus partyBus; switch (line.length) { case 4: buses.add(new Bus(name, size, price, level, ministry)); break; case 5: int teacherArea = Integer.parseInt(line[4]); bus = new Bus(name, size, price, level, ministry); TrainingBus trainingBus = new TrainingBus(bus, teacherArea); buses.add(trainingBus); break; case 6: competitorArea = Integer.parseInt(line[5]); numSecurity = Integer.parseInt(line[5]); bus = new Bus(name, size, price, level, ministry); sportsBus = new SportsBus(bus, competitorArea, numSecurity); buses.add(sportsBus); break; case 7: competitorArea = Integer.parseInt(line[5]); numSecurity = Integer.parseInt(line[6]); barArea = Integer.parseInt(line[6]); bus = new Bus(name, size, price, level, ministry); sportsBus = new SportsBus(bus, competitorArea, numSecurity); partyBus = new PartyBus(sportsBus, barArea); buses.add(partyBus); break; } } } catch (FileNotFoundException e) { e.printStackTrace(); } return buses; } fix this so i can get output like this : 1;BUS_SML;100;200 2;BUS_BIG;850;20000 instead of this: 1;200;100;200 2;20000;850;20000 As you can see the BUS_SML AND BUS_BIG is missing please help
Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
Related questions
Question
100%
public ArrayList<Bus> loadBuses(String bfile) {
ArrayList<Bus> buses = new ArrayList<>();
try {
Scanner scanner = new Scanner(new File(bfile));
while (scanner.hasNextLine()) {
String[] line = scanner.nextLine().split(" ");
if (line.length < 4 || line.length > 7) {
throw new IllegalArgumentException("Invalid input format");
}
String name = line[1];
int size = Integer.parseInt(line[1]);
int price = Integer.parseInt(line[2]);
int level = Integer.parseInt(line[3]);
Ministry ministry = null;
if (line.length > 5) {
ministry = new Ministry(line[5]);
}
int competitorArea, numSecurity, barArea;
Bus bus;
SportsBus sportsBus;
PartyBus partyBus;
switch (line.length) {
case 4:
buses.add(new Bus(name, size, price, level, ministry));
break;
case 5:
int teacherArea = Integer.parseInt(line[4]);
bus = new Bus(name, size, price, level, ministry);
TrainingBus trainingBus = new TrainingBus(bus, teacherArea);
buses.add(trainingBus);
break;
case 6:
competitorArea = Integer.parseInt(line[5]);
numSecurity = Integer.parseInt(line[5]);
bus = new Bus(name, size, price, level, ministry);
sportsBus = new SportsBus(bus, competitorArea, numSecurity);
buses.add(sportsBus);
break;
case 7:
competitorArea = Integer.parseInt(line[5]);
numSecurity = Integer.parseInt(line[6]);
barArea = Integer.parseInt(line[6]);
bus = new Bus(name, size, price, level, ministry);
sportsBus = new SportsBus(bus, competitorArea, numSecurity);
partyBus = new PartyBus(sportsBus, barArea);
buses.add(partyBus);
break;
}
}
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return buses;
}
fix this so i can get output like this : 1;BUS_SML;100;200
2;BUS_BIG;850;20000 instead of this: 1;200;100;200
2;20000;850;20000
2;BUS_BIG;850;20000 instead of this: 1;200;100;200
2;20000;850;20000
As you can see the BUS_SML AND BUS_BIG is missing please help
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
Step by step
Solved in 5 steps with 1 images
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Recommended textbooks for you
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education