diff --git a/lib/ApplicationAuto.dart b/lib/ApplicationAuto.dart new file mode 100644 index 0000000..638e10f --- /dev/null +++ b/lib/ApplicationAuto.dart @@ -0,0 +1,117 @@ +import 'dart:async'; + +enum CarType { sedan, suv, truck, coupe, hatchback } + +class Car { + final String brand; + final CarType type; + final double price; + + Car(this.brand, this.type, this.price); + + void displayInfo() { + print('Car: $brand, Type: ${carTypeToString(type)}, Price: \$${price.toStringAsFixed(2)}'); + } + + static String carTypeToString(CarType type) { + switch (type) { + case CarType.sedan: + return 'Sedan'; + case CarType.suv: + return 'SUV'; + case CarType.truck: + return 'Truck'; + case CarType.coupe: + return 'Coupe'; + case CarType.hatchback: + return 'Hatchback'; + default: + return 'Unknown'; + } + } +} + +extension CarExtension on Car { + String get detailedInfo => 'Detailed Info: Brand: $brand, Type: ${Car.carTypeToString(type)}, Price: \$${price.toStringAsFixed(2)}'; +} + +class AutoCenter { + final List cars = []; + + void addCar(T car) { + cars.add(car); + } + + List findCarsByType(CarType type) { + return cars.where((car) => car.type == type).toList(); + } + + void showAllCars() { + for (var car in cars) { + car.displayInfo(); + } + } +} + +class PriceFilter { + static List filterByPrice(List cars, double minPrice, double maxPrice) { + return cars.where((car) => car.price >= minPrice && car.price <= maxPrice).toList(); + } +} + +class ApplicationAuto { + final AutoCenter autoCenter = AutoCenter(); + + + Future> fetchCarsFromDatabase() async { + return Future.delayed(Duration(seconds: 2), () { + return [ + Car('Toyota', CarType.sedan, 25000), + Car('Ford', CarType.suv, 35000), + Car('Chevrolet', CarType.truck, 40000), + Car('BMW', CarType.coupe, 55000), + Car('Volkswagen', CarType.hatchback, 20000), + ]; + }); + } + + Future loadCars() async { + List carsFromDB = await fetchCarsFromDatabase(); + carsFromDB.forEach((car) => autoCenter.addCar(car)); + } + + void displayAllCars() { + print('All cars in the auto center:'); + autoCenter.showAllCars(); + } + + void displayCarsByType(CarType type) { + print('\nFiltered cars by type (${Car.carTypeToString(type)}):'); + var carsByType = autoCenter.findCarsByType(type); + carsByType.forEach((car) => car.displayInfo()); + } + + void displayCarsByPriceRange(double minPrice, double maxPrice) { + print('\nFiltered cars by price range (\$$minPrice - \$$maxPrice):'); + var filteredCars = PriceFilter.filterByPrice(autoCenter.cars, minPrice, maxPrice); + filteredCars.forEach((car) => car.displayInfo()); + } + void displayDetailedInfoForAllCars() { + print('\nDetailed Information for All Cars:'); + autoCenter.cars.forEach((car) => print(car.detailedInfo)); // Использование метода расширения detailedInfo() + } +} + +void main() async { + var app = ApplicationAuto(); + + await app.loadCars(); + + app.displayAllCars(); + + app.displayCarsByType(CarType.sedan); + + app.displayCarsByPriceRange(20000, 40000); + + app.displayDetailedInfoForAllCars(); +} \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index b29c5a2..dca5a22 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; void main() { - runApp(const MyApp()); + //runApp(const MyApp()); } class MyApp extends StatelessWidget {