Complete the method loadBuses(String bfile) that reads information bus information from a file (bfile contains the filename) .

COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
1st Edition
ISBN:9780357392676
Author:FREUND, Steven
Publisher:FREUND, Steven
Chapter6: Creating, Sorting, And Querying A Table
Section: Chapter Questions
Problem 3AYK
icon
Related questions
Question

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. This should be done for Bus, TrainingBus, SportsBus, PartyBus

 

public Bus( String name, int size, int price, int lev, Ministry mny) {
            approvedTrips=new ArrayList<Trip>();
            this.name = name;
            this.size =size;
            this.price = price;
            this.level = lev;
            this.id = getNextId();
            this.mny = mny;
            tripTypes = "BASICTRANSPORT";
       
        } 
 

import java.util.Scanner;
public class TrainingBus extends Bus {
    private int teacherArea;
   


   
    public TrainingBus(Bus b, int teacherArea)
    {
        super(b.getName(), b.getSize(), b.getPrice(), b.getLevel(), b.getMinistry());
        this.teacherArea =     teacherArea;
     
    }
 
import java.util.Scanner;
public class SportsBus extends  Bus {
    private int competitorArea;
    private int numSecurity;
    private Bus bus;

    public SportsBus(Bus b, int competitorArea, int numSecurity)
    {
        super(b.getName(), b.getSize(), b.getPrice(), b.getLevel(), b.getMinistry());
        bus = b;
        this.competitorArea =     competitorArea;
        this.numSecurity=numSecurity;

    }
 

import java.util.Scanner;

public class PartyBus extends SportsBus{
     int barArea;
   

    public PartyBus(SportsBus s, int barArea)
    {
        super( s.getBus(), s.getCompetitorArea(), s.getNumSecurity());
        this.barArea = barArea;      
       
       
    }
 
my attempt which is not correct but should be helpful 
 
    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]), new Ministry(nextLine[4])), Integer.parseInt(nextLine[5]));
                blist.add(b);
                    break;
                }
                case 6: //SportsBus
                {
                    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;
                }
                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();
        }



        catch(IOException e)
        {
            System.out.println("IOException");}

        return blist;

    }
 
make sure the index are right for the arrays and take into consideration the  constructors and what type each is for the different bus classes look at image uploaded please 
 
#
cols
4
456
5
6
7
Bus
Type
Generic
name Size
Price Level
Training name size Price level
name size price
Level
Level
Colo Col1 Col2 Col3
Sport
Party
Name size price
Tablo 1
Col4
Teacher Area
Spectator Area
Spectator Area
61
Col5
Col6
#Security
#Security Bar Area
Transcribed Image Text:# cols 4 456 5 6 7 Bus Type Generic name Size Price Level Training name size Price level name size price Level Level Colo Col1 Col2 Col3 Sport Party Name size price Tablo 1 Col4 Teacher Area Spectator Area Spectator Area 61 Col5 Col6 #Security #Security Bar Area
Expert Solution
steps

Step by step

Solved in 4 steps

Blurred answer
Knowledge Booster
Files and Directory
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
  • SEE MORE QUESTIONS
Recommended textbooks for you
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
COMPREHENSIVE MICROSOFT OFFICE 365 EXCE
Computer Science
ISBN:
9780357392676
Author:
FREUND, Steven
Publisher:
CENGAGE L
Np Ms Office 365/Excel 2016 I Ntermed
Np Ms Office 365/Excel 2016 I Ntermed
Computer Science
ISBN:
9781337508841
Author:
Carey
Publisher:
Cengage
New Perspectives on HTML5, CSS3, and JavaScript
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:
9781305503922
Author:
Patrick M. Carey
Publisher:
Cengage Learning
CMPTR
CMPTR
Computer Science
ISBN:
9781337681872
Author:
PINARD
Publisher:
Cengage
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning