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

Improving subject and audits #19

Merged
merged 13 commits into from
Nov 17, 2022
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
| 2 | Quest | BizzCard | 1 day | [github.com](./subjects/flutter_piscine/bizzCard) |
| 3 | Quest | QuizApp | 1 day | [github.com](./subjects/flutter_piscine/quizApp) |
| 4 | Quest | MovieList | 2 days | [github.com](./subjects/flutter_piscine/movieList) |
| 5 | Rush | Hackernews | 2 days | [github.com](./subjects/flutter_piscine/hackernews) |
| 5 | Raid | Hackernews | 2 days | [github.com](./subjects/flutter_piscine/hackernews) |
| 6 | Quest | FavouriteImages | 1 day | [github.com](./subjects/flutter_piscine/favoriteImages) |
| 7 | Quest | Bouncer | 1 day | [github.com](./subjects/flutter_piscine/bouncer) |
| 8 | Quest | 01Map | 1 day | [github.com](./subjects/flutter_piscine/01Maps) |
| 9 | Quest | BlocCounter | 2 days | [github.com](./subjects/flutter_piscine/blocCounter) |
| 10 | Rush | SecureNotes | 2 days | [github.com](./subjects/flutter_piscine/secureNotes) |
| 7 | Quest | Bouncer | 2 days | [github.com](./subjects/flutter_piscine/bouncer) |
| 8 | Quest | 01Map | 2 days | [github.com](./subjects/flutter_piscine/01Maps) |
| 9 | Raid | SecureNotes | 2 days | [github.com](./subjects/flutter_piscine/secureNotes) |
| 10 | Quest | Package | 1 day | [github.com](./subjects/flutter_piscine/blocCounter) |
| 11 | Quest | BlocCounter | 2 days | [github.com](./subjects/flutter_piscine/blocCounter) |



Expand Down
11 changes: 8 additions & 3 deletions subjects/flutter_piscine/week01/day01/ex01/intro/README.md
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
## intro

### Instructions

Dart is a programming language designed for client development, such as for the web and mobile apps. It is developed by Google and can also be used to build server and desktop applications. Dart is an object-oriented, class-based, garbage-collected language with C-style syntax.

Dart (within Flutter) is used to develop cross platform applications for Android, iOS, Linux, macOS, Windows, Google Fuchsia, and the web from a single codebase.
Dart (within Flutter framework) is used to develop cross platform applications for Android, iOS, Linux, macOS, Windows, Google Fuchsia, and the web from a single codebase.

Let's start with standard programming language tradition, write your first `"Hello, world!"` in Dart.

Dart's files extension is `.dart`, create `intro.dart` with the following content and run it!
Create a file named `intro.dart` with the following content and run it!

### Expected function

```dart
void main() {
print("Hello, World!");
}
```
### Usage

To run the program, execute a command:

```bash
```console
dart intro.dart
```
10 changes: 6 additions & 4 deletions subjects/flutter_piscine/week01/day01/ex02/variables/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
## variables

### Instructions

In Dart you can declare variables in two ways:

```dart
var str1 = 'Patrick';
var strPatrick = 'Patrick';
// or ...
String str2 = 'Spongebob';
String strSpongebob = 'Spongebob';
```

- The first way declares using `var` which detects variable types automatically.
Expand All @@ -14,9 +16,9 @@ String str2 = 'Spongebob';
Declare and initialize following variables:

- `obj` of type `Object` containing any value;
- `planet` of type `String` containing planet's name you live in;
- `planet` of type `String` containing planet's name you live on;
- `year` of type `int` containing current year;
- `lucky` of type `bool` containing true of false (you decide);
- constant `pi` of type `double` containing pi value with 2 decimal points;

> Note: no main needed!
- Note: no main needed!
37 changes: 19 additions & 18 deletions subjects/flutter_piscine/week01/day01/ex03/dataStructures/README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
## dataStructures

### Instructions

In this exercise you will work with the following data structures: List, Set, and Map.

Declare and initialize following variables:

- `listNum` of type `List<int>` containing a list of integers (list length >= 5);
- `listObj` of type `List<Object>` containing a list of items of different types (list length >= 4);
- `listStr` of type `List<String>` containing a list of strings (list length >= 3);
- `listList` of type `List<List<Object>>` containing a list of lists containing `listNum`, `listObj`, `listStr`;
- `setStr` of type `Set<String>` containing at least 3 items;
- `mapStr` of type `Map<String, int>` containing at least 3 pairs;

### Usage

### List

List is an array of elements. In dart lists are initialized as following:
Expand All @@ -14,42 +27,30 @@ List<int> listNum2 = [1, 2, 3];

### Set

Set is an unordered collection of unique items. Sets are created as:
Set is an unordered collection of unique items. Sets are created as follows:

```dart
var set1 = {'Germany', 'Kazakhstan', 'France'};
var set1 = {'Germany', 'Kazakhstan', 'France', 'England'};
// or ...
Set<String> set2 = {'Germany', 'Kazakhstan', 'France'};
Set<String> set2 = {'Germany', 'Kazakhstan', 'France', 'England'};
```

### Map

Map is a key-value data structure. Maps are created as:

```dart
var map1 = {
var mapRadius = {
'Earth': 6378.1,
'Jupiter': 71492,
'Moon': 1738.1,
};
// or ...
Map<String, double> map1 = {
Map<String, double> mapRadius = {
'Earth': 6378.1,
'Jupiter': 71492,
'Moon': 1738.1,
};
```

### Instructions

Declare and initialize following variables:

- `listNum` of type `List<int>` containing a list of integers (list length >= 5);
- `listObj` of type `List<Object>` containing a list of items of different types (list length >= 4);
- `listStr` of type `List<String>` containing a list of strings (list length >= 3);
- `listList` of type `List<List<Object>>` containing a list of lists containing `listNum`, `listObj`, `listStr`;
- `setStr` of type `Set<String>` containing at least 3 items;
- `mapStr` of type `Map<String, int>` containing at least 3 pairs;

> Note: main is not needed!

- Note: main is not needed!
12 changes: 5 additions & 7 deletions subjects/flutter_piscine/week01/day01/ex04/plainSum/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## plainSum

### Instructions

Write a function `int plainSum(int, int, int)` which takes 3 integers and returns their sum.

Functions in Dart are declared as follows:

```dart
Expand All @@ -8,13 +12,7 @@ bool isEven(int num) {
}
```

---

### **Exercise**

Write a function `int plainSum(int, int, int)` which takes 3 integers and returns their sum.

Example of usage:
### Usage

```dart
void main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
## namedRequiredSum

### **Exercise**
### Instructions

Write a function that accepts *required* named parameters "first", "second", "third" and returns their sum. All the parameters are integers. Name of the function - namedRequiredSum.
Write a function called `namedRequiredSum()` that accepts *required* named parameters `first`, `second`, `third` and returns their sum. All the parameters are integers.

> Note: Find out how to make required [named parameters](https://dart.dev/guides/language/language-tour).
- Note: Find out how to make required [named parameters](https://dart.dev/guides/language/language-tour).

Original file line number Diff line number Diff line change
@@ -1,25 +1,32 @@
## namedOptionalSum

### Instructions

Write a function called `namedOptionalSum()` that accepts named parameters `first`, `second`, `third` and returns the sum of them.

- All the parameters are integers.
- Absent parameters should be considered as 0.

### Named parameters

In Dart you can declare functions that require explicit naming for arguments. Compare 2 functions below.

```dart
// Instead of
// Example 1
void someFunction(bool bold, bool hidden) {...}

someFunction(true, false);
```

```dart

// Example 2
// Now you must specify which argument you are referring to
void someFunction({bool? bold, bool? hidden}) {...}

someFunction(bold: true, hidden: false);
```

This way you must specify the name of argument each time you call a function. You can also skip parameter by simply not specifying its name and value.
This way you must specify the name of argument each time you call a function. You can also skip the parameter by simply not specifying its name and value. What do you think will be the default value for skipped parameters?

### Null safety

Expand All @@ -28,8 +35,3 @@ You might be wondering what does "?" sign in bool? mean.
As Dart's documentation suggests - "...types in your code are non-nullable by default, meaning that variables can’t contain null unless you say they can. With null safety, your runtime null-dereference errors turn into edit-time analysis errors."

What happens if the argument of the function is optional and it is omitted? It should be null, but the Dart's null safety does not allow it, and you will get error from compiler. In order to let Dart's compiler understand that certain variable should be able to accept null, you **must** initialize primitives with question sign. More on null safety [here](https://dart.dev/null-safety).

### **Exercise**

Write a function that accepts named parameters "first", "second", "third" and returns the sum of them. All the parameters are integers. Absent parameters are considered as 0. Name of the function - namedOptionalSum.

15 changes: 8 additions & 7 deletions subjects/flutter_piscine/week01/day01/ex07/optionalSum/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
## optionalSum

### Instructions

Write a function called `optionalSum()` that accepts two integer arguments, and an optional integer argument. Return the sum of all the arguments.

### Optional parameters

In Dart you can also make function arguments optional, meaning that a function can work even if the optional argument is omitted. If the optional parameter is omitted, it is considered to be null.

### Usage

Example of function with optional parameters:

```dart
Expand All @@ -21,11 +27,6 @@ void main() {
}
```

> **Note:** Optional parameters **must** come after the required parameters.

> **Note:** you cannot use both optional and named parameters, you should choose **one** of them.

### **Exercise**

Write a function that accepts two integer arguments, and an optional integer argument. Return the sum of all the arguments. Name of the function - optionalSum.
- Note: Optional parameters must come after the required parameters.

- Note: You cannot use both optional and named parameters, you should choose only one of them.
13 changes: 7 additions & 6 deletions subjects/flutter_piscine/week01/day01/ex08/maxNum/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
## maxNum

### **Ternary operators**
### Instructions

Write a function called `maxNum()` that takes three integers as arguments and returns the maximum number of the three.

### Ternary operators

One can do different things with ternary operators. It comes handy when one wants to do actions based on some condition.
This operation also keeps less amount of code, and hopefully more readable.
Expand All @@ -15,13 +19,10 @@ condition ? (value for true condition) : (value for false condition)
bool four_greater_than_five = 4 > 5 ? true : false;
```

> **Note:** the same could be achieved with simple if and else, but this approach reduces code length.
- Note: The same could be achieved with simple if and else, but this approach reduces code length.

### **Exercise**
### Usage

```dart
int maxNum(int first, int second, int third) {...}
```

The function must return the maximum of three numbers.

62 changes: 31 additions & 31 deletions subjects/flutter_piscine/week01/day01/ex09/person/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
## person

### Instructions

Create a class named `Person`.

Its attributes:

- name - `string`
- surname - `string`
- cityOfOrigin - `string`
- age - `int`
- height - `int`

Constructor:

- name - `required`
- cityOfOrigin - `required`
- age - `required`
- height - `required`
- surname - `optional`

### Object Oriented Programming

Dart supports object oriented programming which Flutter framework relies on. Classes have 2 main concepts: attributes and methods. Attributes are needed to store various data in the instance of Class and methods are functions, which can use Class attributes for various manipulations. To understand OOP and its difference from functional programming visit [this website](https://www.freecodecamp.org/news/object-oriented-programming-concepts-21bb035f7260/).
Expand All @@ -13,23 +33,24 @@ class Point {
}
```

**Point** - name of the class, **x, y** - are fields
**Point** - name of the class, **x, y** - are attributes.

What if one wants to create a Point with different x and y? To do that one needs to declare **_Constructor_** - a function that specifies how to create object of a class given a set of parameters.
What if you want to initiate a Point with different x and y? To do that declare a **_Constructor_** - which is a function that specifies how to create object of a class given a set of parameters.

```dart
class Point {
double x = 0; // field
double y = 0; // field
double x = 0; // attribute
double y = 0; // attribute

Point(double x, double y) { //Constructor
this.x = x; // initializing fields
this.y = y; // In geometry, points must have x and y coordinates
// Constructor
Point(double x, double y) {
this.x = x; // initializing attributes
this.y = y;
}
}
```

In Dart one can also use Constructor declaration of type **_Constructor(param1, param2...);_** thus saving a few lines of code if all one wants to do is to pass arguments to values.
In Dart we can also use Constructor declaration of type **_Constructor(param1, param2...);_** thus saving a few lines of code if all we want to do is to pass arguments to values.

```dart
class Point {
Expand Down Expand Up @@ -57,7 +78,7 @@ import 'dart:math';
class Point {
double x = 0; // field
double y = 0; // field

Point(double x, double y) { // constructor
this.x = x; // initializing field
this.y = y; // initializing field
Expand All @@ -77,25 +98,4 @@ var p2 = Point(8, 3);
print(p1.distanceTo(p2));
```

### **Exercise**

Make a class named `Person`.

Its attributes:

- name - string
- surname - string
- cityOfOrigin - string
- age - int
- height - int

Constructor:

- name - required
- cityOfOrigin - required
- age - required
- height - required
- surname - optional

> Note: please see the [documentation](https://dart.dev/guides/language/language-tour#classes) for examples.

- Note: please see the [documentation](https://dart.dev/guides/language/language-tour#classes) for examples.
Loading