Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cabalonga-Maps and Sets #25

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions Cabalonga-Map.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
void main() {
const pizza = {
'margherita': 5.5,
'pepperoni': 7.5,
'vegetarian': 6.5,
};
print("Pizza Menu");
pizza.forEach((k, v) => print('${k}: ${v}'));

const order = ['margherita', 'pepperoni', 'pineapple']; //given order
double sum = 0;
print('');
print('Your order: ');
print(order);
order.forEach((element) {
if (pizza.containsKey(element) == true) {
sum += pizza[element];
} else {
print('Sorry, $element is not on the menu.');
}
;
});
print('');
print('Total: \$' + sum.toString());
}
13 changes: 13 additions & 0 deletions Cabalonga-Sets.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
void main() {
int sum = 0;
Set<int> a = {1, 3, 6, 8, 2, 7};
Set<int> b = {3, 5, 7, 6, 10};

Set<int> result = a.union(b).difference(a.intersection(b));
print(
'Set of the elements that belong to either a or b, but not both: $result');
result.forEach((element) {
sum += element;
});
print('Sum of items: $sum');
}
78 changes: 25 additions & 53 deletions activities/activity1/main.dart
Original file line number Diff line number Diff line change
@@ -1,54 +1,26 @@
import 'dart:io';

void main() {
Person p1 = Person('Jane','Alba', 25);
print(p1.getFullName());
print(Person.getInfo());
Person p2 = Person.withLNandAgeOnly('Villaruel', 23);
print(p2.getFullName());

print("Enter First Name: ");
String fn = stdin.readLineSync();
print("Enter Last Name: ");
String ln = stdin.readLineSync();
print("Enter Age: ");
String strAge = stdin.readLineSync();
int age = int.parse(strAge);
Person p3 = Person(fn,ln,age);
print(p3.getFullName());
}

class Person {
static String company = 'ABC Company';
String firstName, lastName;
int age = 18;
String _dept;

String get dept => _dept;

Person(this.firstName, this.lastName, this.age);

//named constructor
Person.withLNandAgeOnly(this.lastName, this.age);

//Person p = Person();
//p.getFullName();
String getFullName() {
return ("$firstName $lastName age is $age");
}

//Person.getInfo()
static String getInfo() {
return 'This is a Person class';
}

//
@override
String toString() {
return lastName;
}

void setLastName(String lastName) {
this.lastName = lastName;
}
import 'dart:io';

void main(){
print('Enter First Name: ');
String first = stdin.readLineSync();
print('Enter Middle Name: ');
String mid = stdin.readLineSync();
print('Enter Last Name: ');
String last = stdin.readLineSync();
print('Enter Age: ');
String agee = stdin.readLineSync();
var ageint = int.parse(agee);
Student s = Student(first, mid, last, ageint);
print(s.getFullName());
}
class Student{
String fn, mn, ln;
int age;
static final String department = 'Computer Science';

Student(this.fn, this.mn, this.ln, this.age);

String getFullName(){
return ('Hello $fn $mn $ln, $age, from $department department.');
}
}