Skip to content

Instantly share code, notes, and snippets.

@saav0004
Created September 9, 2023 19:07
Show Gist options
  • Save saav0004/5612d143e1bcaec4ee0f719436ec82cc to your computer and use it in GitHub Desktop.
Save saav0004/5612d143e1bcaec4ee0f719436ec82cc to your computer and use it in GitHub Desktop.
import "dart:math";
void main() {
ClassicalGuitar ramirez = ClassicalGuitar('Centenario');
print(
"Ramirez is the ${ramirez.model} model celebrating 100 years of history");
ramirez.numberOfStrings();
ramirez.wood("Russian birch");
ramirez.loudness();
print("");
ElectricGuitar fender = ElectricGuitar('Stratocaster');
print("I am a legendary ${fender.model} model");
fender.wood("Ash");
fender.heaviness(1);
fender.squeal();
}
class Guitar {
Guitar();
wood(var type) {
print("I am made out of $type");
}
}
class ClassicalGuitar extends Guitar {
late String model;
late String woodType;
int numOfStrings = Random().nextInt(8) + 6;
ClassicalGuitar(this.model);
numberOfStrings() {
print("I have $numOfStrings strings");
}
@override
wood(woodType) {
print("I'm made from a $woodType tree");
}
loudness() {
print("I am very quiet and sound better in a hall");
}
}
class ElectricGuitar extends Guitar {
late String model;
late double weight;
List<String> woodTypes = ["Ash", "Basswood", "Alder"];
ElectricGuitar(this.model);
@override
wood(var type) {
if (woodTypes.contains(type)) {
print("I am a $type electric guitar");
} else {
print(
"I am not usually made out of $type, but whatever floats your boat");
}
}
heaviness(var weight) {
if (weight <= 3) {
print("This is a very light guitar");
} else if (weight > 3 && weight <= 5) {
print("This is a medium weight guitar");
} else {
print("This is a heavy guitar");
}
}
squeal() {
print("I can wail and have electric scrreeeeeeaaammmmms!");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment