SHARE
TWEET

Untitled

a guest Jan 22nd, 2020 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import 'package:flutter/material.dart';
  2.  
  3. void main() {
  4.   final lamborghini = Car(maxSpeed: 300, strength: 90);
  5.   final ferrari = Car(maxSpeed: 280, strength: 95);
  6.   ferrari.drive(3);
  7.   lamborghini.drive(4);
  8.   runApp(
  9.     MaterialApp(
  10.       home: Scaffold(
  11.         body: Center(
  12.           child: Column(
  13.             children: <Widget>[
  14.               Text(
  15.                 Car.getAllInfo([lamborghini, ferrari]),
  16.                 style: TextStyle(fontSize: 33),
  17.               ),
  18.               Text(lamborghini.beats(ferrari).toString(),
  19.                   style: TextStyle(fontSize: 40))
  20.             ],
  21.           ),
  22.         ),
  23.       ),
  24.     ),
  25.   );
  26. }
  27.  
  28. class Car {
  29.   Car({this.maxSpeed, this.strength = 100, this.fuel = 200});
  30.   final int maxSpeed;
  31.   int odo = 0;
  32.   int strength, fuel;
  33.  
  34.   static String getAllInfo(List<Car> cars) =>
  35.     cars.map((car) => car.getInfo()).join('\n\n');
  36.  
  37.   void drive([int times = 1]) {
  38.     for (int i = 0; i < times; i++) {
  39.       if (fuel < maxSpeed ~/ 10) {
  40.         fuel = 0;
  41.         break;
  42.       }
  43.       if (strength < 10) {
  44.         strength = 0;
  45.         break;
  46.       }
  47.       odo++;
  48.       strength -= 10;
  49.       fuel -= maxSpeed ~/ 10;
  50.     }
  51.   }
  52.  
  53.   bool beats(Car car) => strength > car.strength;
  54.  
  55.   String getInfo() => 'Max Speed = $maxSpeed\n'
  56.       'Strength = $strength\nFuel = $fuel\nODO = $odo';
  57. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top