1
resposta

[Projeto] Classes e Herança

Insira aqui a descrição dessa imagem para ajudar na acessibilidade

void main() {
  Clothing jacket1 = Tops('black jacket', 'Gucci', 589.74, true);
  Bottom jeans1 = Bottom('navy jeans', 'Zara', 299.99, false);
  Tops tshirt1 = Tops('white T-shirt', 'Levis', 87.70, true);
  Shoes sneakers1 = Shoes('Casual sneakers', 'Nike', 120.45, true);


  jacket1.printClothing();
  jeans1.printClothing();
  tshirt1.printClothing();
  sneakers1.printClothing();
  tshirt1.washNecessity();
  sneakers1.tooOld();
  jeans1.washNecessity();

}

class Clothing {
  String type;
  String brand;
  double price;
  bool isWashNecessary;

  Clothing(this.type, this.brand, this.price, this.isWashNecessary);

  void printClothing() {
    print('This/These $type is from $brand and it costed R\$ $price.');
  }

  void washNecessity() {
    if (isWashNecessary) {
      print('Put it in the wash. It will be grand.');
    } else {
      print('Put away in the wardrobe, it is clean.');
    }
  }
}

class Tops extends Clothing {
  Tops(String type, String brand, double price, bool isWashNecessary)
      : super(type, brand, price, isWashNecessary);
}

class Bottom extends Tops {
  Bottom(String type, String brand, double price, bool washNecessary)
      : super(type, brand, price, washNecessary);
}

class Shoes extends Clothing {
  bool isTooOld;

  Shoes(String type, String brand, double price, this.isTooOld)
      : super(type, brand, price, isTooOld);

  void tooOld() {
    if (isTooOld) {
      print('Donate them to a charity.');
    } else {
      print('You may continue using them for a bit more');
    }
  }
}
1 resposta

Oi Taissa, tudo bem ?

Muito legal sua implementação do projeto!

Quer mergulhar em tecnologia e aprendizagem?

Receba a newsletter que o nosso CEO escreve pessoalmente, com insights do mercado de trabalho, ciência e desenvolvimento de software