0% found this document useful (0 votes)
68 views2 pages

Maps in Dart

maps in dart

Uploaded by

Korbas Zineb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
68 views2 pages

Maps in Dart

maps in dart

Uploaded by

Korbas Zineb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

void main() {

Map<String,String> planets =
{
"first":"mercury",
"second":"venus",
"third":"earth",
"fourth":"mars",
"fifth":"jupiter"
};
print(planets);
}

---------------------------------------------------

void main() {
var noodles= MenuItem('veg noodles',9.99);
var pizza= Pizza(["mashrooms","peppers"],'voicano pizza',12.99);

var roast = MenuItem('veggie roast dinner',12.49);


var kebab = MenuItem('plant kebab',7.49);
/*print(noodles.title);
print(noodles.price);
print(pizza.title);
print(pizza.price);
print(noodles.format());
print(pizza.format());*/
print("$noodles,$pizza,$roast,$kebab");
var foods = Collection<MenuItem>(
'Menu Items' ,
[noodles,pizza,roast,kebab]
);
var random=foods.randomItem();
print(random);
}

class MenuItem
{
String title;
double price;
MenuItem(this.title,this.price);

String format()
{
return "$title --> $price";
}
}

class Pizza extends MenuItem


{
List<String> toppings;
Pizza(this.toppings,super.title,super.price);

String format()
{
var formattedToppings = 'Contains:';

for(final t in toppings)
{
formattedToppings = '$formattedToppings $t';
}
return ' $title -> $price DA \n$formattedToppings';
}

String toString()
{
return 'instance of Pizza: $title , $price , $toppings';
}

class Collection<T>
{
String name;
List<T> data;
Collection(this.name,this.data);

T randomItem()
{
data.shuffle();
return data[0];
}
}

You might also like