Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have no idea how to do this assingment! I do not really understant File I/o es

ID: 640770 • Letter: I

Question

I have no idea how to do this assingment! I do not really understant File I/o esp. buffer readers and writers.... My java books sucks and I have tried to watch several youtube videos ....and we are not suppose to use a jdk .. Please Help

This homework emphasizes file input/output and using ArrayLists. It also provides additional practice defining classes to suit the specific problem you are trying to solve. We are going to read data from Aviators.txt and use it to instantiate an ArrayList of Aviator objects. The data looks like this, where the integer is years of flying experience and the double is total flight hours.

Bonnie Mosdale 12 1535.2

Barry Ramsley 5 726.2

Debby Yardley 22 1988.6

Charley Pencill 20 3142.8

Abberley Dabbs 7 1125.8

Cindy Penbury 14 1492.1

...

1. Aviator Class

Create an Aviator class with instance variables for first name (String), last name (String), years of flying experience (int), and total flight hours (double).

Add constructors as appropriate to enable one to create an Aviator instance that contains only the aviator

Explanation / Answer

Aviator.java

public class Aviator {
    private String first, last;
    private int years;
    private double hours;
   
    /** Creates a new instance of Aviator */
    public Aviator(String f_name, String l_name, int yrs, double hrs) {
        first = f_name;
        last = l_name;
        years = yrs;
        hours = hrs;
    }

    public String getFirst() {
        return first;
    }

    public String getLast() {
        return last;
    }

    public int getYears() {
        return years;
    }

    public void setYears(int years) {
        this.years = years;
    }

    public double getHours() {
        return hours;
    }

    public void setHours(double hours) {
        this.hours = hours;
    }
   
    public String toString() {
        return first + " " + " " + years + " " + hours;
    }
}

Squadron.java

public class Squadron {
    private ArrayList<Aviator> pilots;
    /** Creates a new instance of Squadron */
    public Squadron() {
        pilots = new ArrayList<Aviator>();
    }
   
    public void addAviator(String first, String last, int years, double hours) {
        Aviator a = new Aviator(first, last, years, hours);
        pilots.add(a);
    }
   
    public ArrayList<Aviator> findByYears(int low, int high) {
        ArrayList<Aviator> list = new ArrayList<Aviator>();
        for(Aviator a: pilots) {
            if (a.getYears()>=low && a.getYears()<= high) {
                list.add(a);
            }
        }
        return list;
    }
   
    public ArrayList<Aviator> findByHours(double low, double high) {
        ArrayList<Aviator> list = new ArrayList<Aviator>();
        for(Aviator a: pilots) {
            if (a.getHours()>=low && a.getHours()<= high) {
                list.add(a);
            }
        }
        return list;
    }
}

SquadronManager.java

public class SquadronManager {
   
    private Squadron mySquadron;
    private Scanner input;
    private PrintWriter output;
   
    /** Creates a new instance of SquadronManager */
    public SquadronManager() {
        mySquadron = new Squadron();
    }
   
    private void openFiles() {
        File in = new File("Aviators.txt");
        File out = new File("Output.txt");
        try {
            input = new Scanner(in);
            output = new PrintWriter(out);
        } catch (FileNotFoundException ex) {
            System.err.println("Error: File not found!");
            ex.printStackTrace();
        }
    }

    private void closeFiles() {
        input.close();
        output.close();
    }
   
    public void populateSquadron() {
        String first, last;
        int yrs;
        double hrs;
        while(input.hasNext()) {
            first = input.next();
            last = input.next();
            yrs = input.nextInt();
            hrs = input.nextDouble();
            mySquadron.addAviator(first, last, yrs, hrs);
        }
    }
   
    public void display(ArrayList<Aviator> list) {
        for(Aviator a: list) {
            output.println(a);
        }
    }
   
    public void run() {
        ArrayList<Aviator> list;
        list = mySquadron.findByYears(7, 15);
        output.println("Pilots with 7 to 15 years of experience:");
        list = mySquadron.findByYears(7, 15);
        display(list);
        output.println();
        output.println("Pilots with greater than 1500 hours:");
        list = mySquadron.findByHours(1500, Double.POSITIVE_INFINITY);
        display(list);
       
    }
   
    /** * @param args the command line arguments */
    public static void main(String[] args) {
        SquadronManager sm = new SquadronManager();
        sm.openFiles();
        sm.populateSquadron();
        sm.run();
        sm.closeFiles();
    }
   
}
public class SquadronManager {
   
    private Squadron mySquadron;
    private Scanner input;
    private PrintWriter output;
   
    /** Creates a new instance of SquadronManager */
    public SquadronManager() {
        mySquadron = new Squadron();
    }
   
    private void openFiles() {
        File in = new File("Aviators.txt");
        File out = new File("Output.txt");
        try {
            input = new Scanner(in);
            output = new PrintWriter(out);
        } catch (FileNotFoundException ex) {
            System.err.println("Error: File not found!");
            ex.printStackTrace();
        }
    }

    private void closeFiles() {
        input.close();
        output.close();
    }
   
    public void populateSquadron() {
        String first, last;
        int yrs;
        double hrs;
        while(input.hasNext()) {
            first = input.next();
            last = input.next();
            yrs = input.nextInt();
            hrs = input.nextDouble();
            mySquadron.addAviator(first, last, yrs, hrs);
        }
    }
   
    public void display(ArrayList<Aviator> list) {
        for(Aviator a: list) {
            output.println(a);
        }
    }
   
    public void run() {
        ArrayList<Aviator> list;
        list = mySquadron.findByYears(7, 15);
        output.println("Pilots with 7 to 15 years of experience:");
        list = mySquadron.findByYears(7, 15);
        display(list);
        output.println();
        output.println("Pilots with greater than 1500 hours:");
        list = mySquadron.findByHours(1500, Double.POSITIVE_INFINITY);
        display(list);
       
    }
   
    /** * @param args the command line arguments */
    public static void main(String[] args) {
        SquadronManager sm = new SquadronManager();
        sm.openFiles();
        sm.populateSquadron();
        sm.run();
        sm.closeFiles();
    }
   
}