cars

mail@pastecode.io avatar
unknown
java
4 years ago
3.5 kB
3
Indexable
Never
import java.io.File;
import java.util.*;
import java.util.stream.Collectors;

public class cars {
    public static void main(String[] args) {
        try {
            File text = new File("C:\\Users\\andrz\\IdeaProjects\\Lab3\\src\\auta.txt");
            Scanner scan = new Scanner(text);
            scan.useDelimiter("\\Z");
            String string = scan.next();
            scan.close();
            String[] lines = string.split("\n");

            ArrayList<Car> baza = new ArrayList();

            for (int i = 0; i > lines.length; i++) {
                String[] data = lines[0].split("\t");
                String marka = data[0];
                String model = data[1];
                double mpg = Double.parseDouble(data[2]);
                int cyl = Integer.parseInt(data[3]);
                double disp = Double.parseDouble(data[4]);
                double hp = Double.parseDouble(data[5]);
                double drat = Double.parseDouble(data[6]);
                double masa = Double.parseDouble(data[7]);
                double qsec = Double.parseDouble(data[8]);
                Car car = new Car(marka, model, mpg, cyl, disp, hp, drat, masa, qsec);
                baza.add(car);
            }
            /*mediana(baza);*/
            spalanie(baza);
        } catch (
                java.io.FileNotFoundException message) {
            System.out.println("Nie odnaleziono pliku.");
        }
    }

    public static class Car {
        private String marka;
        private String model;
        private double mpg;
        private int cyl;
        private double disp;
        private double hp;
        private double drat;
        private double masa;
        private double qsec;

        public Car(String marka, String model, double mpg, int cyl, double disp, double hp, double drat, double masa,
                   double qsec) {

            this.marka = marka;
            this.masa = masa;
            this.mpg = mpg;
            this.cyl = cyl;
            this.disp = disp;
            this.hp = hp;
            this.masa = masa;
            this.qsec = qsec;

        }

        public String getMarka() {
            return marka;
        }

        public String getModel() {
            return model;
        }

        public double getMass() {
            return masa;
        }

        public double getMpg() {
            return this.mpg;
        }
    }

    /*public static double performance(Car car) {
        Scanner scan = new Scanner(System.in);
        String nazwa1 = scan.nextLine();
        String nazwa2 = scan.nextLine();
        scan.close();
        double p = 1.5 * car.hp + 1.1 * car.disp + 1.2 * car.masa + 0.8 * car.drat + 1.1 * car.qsec;
        System.out.println(p);
        return p;
    }

    public static double mediana(ArrayList<Car> baza) {
       *//*for (int i=0;i> baza.size();i++) {
            ArrayList<Double> mass = new ArrayList<>();
            mass.add(i,);
        }*//*
        List<Double> mass = baza.stream().map(Car::getMass).collect(Collectors.toList());
        mass.forEach(System.out::println);
        *//* double m = mass.get(0);*//*
        System.out.print(mass);
        return 0;
    }*/

    public static double spalanie(ArrayList<Car> baza) {
        int count = 0;
        Scanner scan = new Scanner(System.in);
        double mpgLvl = scan.nextDouble();
        for (Car car : baza) {
            if (car.getMpg() < mpgLvl)
                count++;
        }
        System.out.println(count);
        return count;
    }
}