Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package RawData;
- import java.io.BufferedReader;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import java.util.StringJoiner;
- /**
- *
- * @author chobi
- */
- class Car{
- private static final int NUMBER_OF_TIRES = 4;
- private String model;
- private Engine engine;
- private Cargo cargo;
- private Tire[] tire;
- public Car(String model, Engine engine, Cargo cargo, Tire[] tire) {
- this.model = model;
- this.engine = engine;
- this.cargo = cargo;
- this.tire = tire;
- }
- public static int getNUMBER_OF_TIRES() {
- return NUMBER_OF_TIRES;
- }
- public String getModel() {
- return model;
- }
- public Engine getEngine() {
- return engine;
- }
- public Cargo getCargo() {
- return cargo;
- }
- public Tire[] getTire() {
- return tire;
- }
- @Override
- public String toString() {
- StringJoiner str = new StringJoiner(" ");
- for (int i = 0; i < tire.length; i++) {
- str.add(this.tire[i].toString());
- }
- return "Car{" + "model=" + model + ", engine=" + engine + ", cargo=" + cargo + ", tire=" + str + '}';
- }
- }
- class Engine{
- private int speed;
- private int power;
- public Engine(int speed, int power) {
- this.speed = speed;
- this.power = power;
- }
- public int getPower() {
- return power;
- }
- @Override
- public String toString() {
- return "Engine{" + "speed=" + speed + ", power=" + power + '}';
- }
- }
- class Cargo{
- private int weight;
- private String type;
- public Cargo(int weight, String type) {
- this.weight = weight;
- this.type = type;
- }
- public String getType() {
- return type;
- }
- @Override
- public String toString() {
- return "Cargo{" + "weight=" + weight + ", type=" + type + '}';
- }
- }
- class Tire{
- private double pressure;
- private int age;
- public Tire(double pressure, int age) {
- this.pressure = pressure;
- this.age = age;
- }
- public double getPressure() {
- return pressure;
- }
- @Override
- public String toString() {
- return "Tire{" + "pressure=" + pressure + ", age=" + age + '}';
- }
- }
- public class RawData {
- public static void main(String[] args) {
- try (BufferedReader reader = new BufferedReader(new InputStreamReader(System.in))){
- int numLine = Integer.parseInt(reader.readLine());
- ArrayList<Car> cars = new ArrayList<Car>();
- //ChevroletAstro 200 180 1000 fragile 1.3 1 1.5 2 1.4 2 1.7 4
- for (int i = 0; i < numLine; i++) {
- String[] inputCars = reader.readLine().split("\\s+");
- String model = inputCars[0];
- Engine engine = new Engine(Integer.parseInt(inputCars[1]), Integer.parseInt(inputCars[2]));
- Cargo cargo = new Cargo(Integer.parseInt(inputCars[3]), inputCars[4]);
- Tire[] tire = createTires(inputCars);
- cars.add(new Car(model, engine, cargo, tire));
- }
- String getCargoType = reader.readLine();
- if (getCargoType.equals("fragile")) {
- cars.stream()
- .filter(c -> c.getCargo().getType().equals(getCargoType))
- .filter(s -> averagePressure(s) < 1 )
- .forEach(s -> System.out.println(s.getModel()));
- }else if(getCargoType.equals("flamable")){
- cars.stream()
- .filter(c -> c.getCargo().getType().equals(getCargoType))
- .filter(s -> s.getEngine().getPower() > 250)
- .forEach(s -> System.out.println(s.getModel()));
- }
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- private static Tire[] createTires(String[] inputCars) {
- Tire[] tires = new Tire[Car.getNUMBER_OF_TIRES()];
- int wheel = 0;
- for (int i = 0; i < tires.length; i++) {
- tires[i] = new Tire(Double.parseDouble(inputCars[5 + wheel++]), Integer.parseInt(inputCars[5+ wheel++]));
- }
- return tires;
- }
- private static double averagePressure(Car s) {
- int wheel = s.getTire().length;
- double average = 0L;
- for (int i = 0; i < wheel; i++) {
- average += s.getTire()[i].getPressure();
- }
- return average / wheel;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment