简体   繁体   中英

How do I inherit this method in Java?

So ive been given this method which reads a CSV file and outputs data

In the CSV file theres unique tailCode for each aircraft, the file looks like this

given the code at the top i have to create a new method that uses that code to print out the data for an aircraft given its tailCode.

Looks like the primary goal of your loadAircraftData is to just load the aircrafts in the list. You might be displaying all for now. Since you are looking for a specific method to display an aircraft given it's tail code, here is an example:

public void displayAircraft(Path p, String tailCode) {
    loadAircraftData(p);
    Optional<Aircraft> result = aircraft.stream().filter(a -> a.getTailCode().equals(tailCode)).findFirst();
    if (result.isPresent()) {
        System.out.println("Aircraft: "
                + result.getTailCode()
                + " is a " /*+ manufacturer + " "*/
                + result.getType()
                + " model "
                + result.getModel()
                + " with "
                + result.getSeats()
                + " seats that holds "
                + result.getCabinCrewRequired()
                + " starting at "
                + result.getStartingPosition());
    }
}

If you can have loadAircraftData take the tailCode also as a parameter, it will be cleaner. Also, if you load aircrafts from a particular path, you may not need to load them every time if you store them based on path.

Purely based on what you've asked, the method is returning 'void' and is taking 'Path' as parameter, but is outputting what's there in the CSV (residing in the path)

As per your question, you have tailcode and you need to output aircraft details by using that method.

You cannot use that method to accomplish that as it is not returning anything or the code in it is doing what you intend to do.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM