Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
I am getting Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException error for SportsBus and Party Bus instruction: WorkArea is then to be adjusted to implement the method loadBuses. The starting code includes
the skeleton of the method, which includes the method header and the name of the file to be
accessed. . Complete the method loadBuses(String bfile) that reads information bus information from a
file (bfile contains the filename) . Each row in the file should trigger the creation of an
instance of bus or an appropriate subclass, according to the data in table 1. All buses created
should be added to an arraylist. LoadBuses should return the populated arraylist. look at image uploaded it SportsBus and PartyBus are giving index out of bound erros please fix
the skeleton of the method, which includes the method header and the name of the file to be
accessed. . Complete the method loadBuses(String bfile) that reads information bus information from a
file (bfile contains the filename) . Each row in the file should trigger the creation of an
instance of bus or an appropriate subclass, according to the data in table 1. All buses created
should be added to an arraylist. LoadBuses should return the populated arraylist. look at image uploaded it SportsBus and PartyBus are giving index out of bound erros please fix
public ArrayList<Bus> loadBuses(String vfile )
{
Scanner bscan = null;
ArrayList<Bus> blist = new ArrayList<Bus>();
try
{
bscan = new Scanner(new File(vfile));
while(bscan.hasNext())
{
String [] nextLine = bscan.nextLine().split(" ");
switch(nextLine.length)
{
case 4: //regular
{
Bus b = new Bus(nextLine[0], Integer.parseInt(nextLine[1]),Integer.parseInt(nextLine[2]),Integer.parseInt(nextLine[3]), mny);
blist.add(b);
break;
}
case 5: //TrainingBus
{
Bus b = new TrainingBus(new Bus(nextLine[0], Integer.parseInt(nextLine[1]), Integer.parseInt(nextLine[2]), Integer.parseInt(nextLine[3]), Ministry.valueOf(nextLine[4])), 2);
blist.add(b);
break;
}
case 6: //SportsBus
{
Bus b = new Bus(nextLine[0], Integer.parseInt(nextLine[1]), Integer.parseInt(nextLine[2]), Integer.parseInt(nextLine[3]), Ministry.valueOf(nextLine[4]));
SportsBus sb = new SportsBus(b, Integer.parseInt(nextLine[5]), Integer.parseInt(nextLine[6]));
blist.add(sb);
break;
}
case 7: //PartyBus
{
Bus b = (new SportsBus(new Bus(nextLine[1], Integer.parseInt(nextLine[2]), Integer.parseInt(nextLine[3]), Integer.parseInt(nextLine[4]), new Ministry(nextLine[5])), Integer.parseInt(nextLine[6]), Integer.parseInt(nextLine[7])));
blist.add(b);
break;
}
}
}
bscan.close();
}
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps
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.Similar questions
- Use stacks to implement a postfix-to-infix translator. Until the user closes the programme, it should continually read a postfix expression and output the identical infix expression. If the postfix expression entered is incorrect, throw an exception.arrow_forwardJAVA PROGRAM MODIFY THIS PROGRAM SO IT READS THE TEXT FILES IN HYPERGRADE. I HAVE PROVIDED THE INPUTS AND THE FAILED TEST CASE AS A SCREENSHOT. HERE IS THE WORKING CODE TO MODIFY: import java.io.*;import java.util.*;public class NameSearcher { private static List<String> loadFileToList(String filename) throws FileNotFoundException { List<String> namesList = new ArrayList<>(); File file = new File(filename); if (!file.exists()) { throw new FileNotFoundException(filename); } try (Scanner scanner = new Scanner(file)) { while (scanner.hasNextLine()) { String line = scanner.nextLine().trim(); String[] names = line.split("\\s+"); for (String name : names) { namesList.add(name.toLowerCase()); } } } return namesList; } private static Integer searchNameInList(String name, List<String> namesList) {…arrow_forwardTRUE OR FALSE We can use Generics to define a custom generic exception.arrow_forward
- /*TASK 5. Implement part 1 of the report. You need to read data from input.txt file, store it into array of items (called items) and write it in a formatted form to the output file. Code, debug and present it in the best possible format. Hint: It might be helpful to format the String coming from toString( ) method using String.format( ) method, which works similar to System.out.prinf. Hint2: You might have to close and delete existing output .doc or .txt file from its folder * public class YourUserName_hw7 { static Item [ ] items = new Item [200];//an array of Items static EdibleItem [ ] edibleItems;//an array of Edible Items static int countEdibleitems = 0;//count edible items static String pageHeader; //save the header //main( ) method runs the program public static void main(String[ ] args) throws FileNotFoundException { double sum = 0, average = 0; //Optional - create a new input file //CreateInput.createInputFile( );…arrow_forwardCreate the Singly Linked List after having executed the following methods. Each item must have a headand tailreference. Whenever a method is not expected or invalid, write Exception. Only the process not the code •addHead("Dancing") •addHead("Backup") •addHead("Backup") •addTail("Backup") •addTail("Backup") •removeHead()arrow_forwardYou will create two programs. The first one will use the data structure Stack and the other program will use the data structure Queue. Keep in mind that you should already know from your video and free textbook that Java uses a LinkedList integration for Queue. Stack Program Create a deck of cards using an array (Array size 15). Each card is an object. So you will have to create a Card class that has a value (1 - 10, Jack, Queen, King, Ace) and suit (clubs, diamonds, heart, spade). You will create a stack and randomly pick a card from the deck to put be pushed onto the stack. You will repeat this 5 times. Then you will take cards off the top of the stack (pop) and reveal the values of the cards in the output. As a challenge, you may have the user guess the value and suit of the card at the bottom of the stack. Queue Program There is a new concert coming to town. This concert is popular and has a long line. The line uses the data structure Queue. The people in the line are objects…arrow_forward
- Computer Science For the basic ADT Queue operations, list all cases when a QueueException will be thrown. Each item listed should be no more than 10 words and ONLY in the form "exception name : cause of exception". Remember to use correct terminology or the answer will not be acceptedarrow_forwardA pep9 call will push the return address onto the stack True or False?arrow_forwardThis will happen if you try to use an index that is out of range for a list.a. A ValueError exception will occur.b. An IndexError exception will occur.c. The list will be erased and the program will continue to run.d. Nothing—the invalid index will be ignored.arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
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