-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jiri Hudec
committed
Feb 4, 2025
1 parent
6bb5ca1
commit 710a683
Showing
13 changed files
with
349 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/Lekce03.BreakoutRoom1.Switch/Lekce03.BreakoutRoom1.Switch.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
// Výběr nápoje: | ||
|
||
// Vytvoř celočíselnou proměnnou cisloNapoje typu int. | ||
// Vypiš do konzole nabídku nápojů: | ||
// 1 - Káva | ||
// 2 - Čaj | ||
// 3 - Limonáda | ||
// 4 - Voda | ||
// Požádej uživatele, aby zadal číslo nápoje a hodnotu ulož do proměnné cisloNapoje. | ||
|
||
// Použití switch: | ||
// Použij příkaz switch na proměnnou cisloNapoje. | ||
// Pro každou možnost (1 - 4) vypiš do konzole odpovídající zprávu (např. "Vybrali jste kávu"). | ||
// Přidej default pro případ nápoje, který není v menu - bude vypisovat "Neznámý výběr nápoje". | ||
|
||
// Rozsireni: | ||
// Přidej proměnnou mnozstvi typu int pro množství nápoje. | ||
// Po výběru nápoje požádej uživatele, aby zadal množství. | ||
// Vypiš do konzole celkovou zprávu, například "Vybrali jste 2 kávy". | ||
|
||
// BONUS: pouzij interpolovany string | ||
|
||
int cisloNapoje; | ||
|
||
Console.WriteLine("1 - Káva"); | ||
Console.WriteLine("2 - Čaj"); | ||
Console.WriteLine("3 - Limonáda"); | ||
Console.WriteLine("4 - Voda"); | ||
|
||
Console.WriteLine("Zadej cislo napoje:"); | ||
cisloNapoje = int.Parse(Console.ReadLine()); | ||
|
||
Console.WriteLine("Zadej mnozstvi:"); | ||
int mnozstvi = int.Parse(Console.ReadLine()); | ||
|
||
switch (cisloNapoje) | ||
{ | ||
case 1: | ||
Console.WriteLine("Vybral jsi " + mnozstvi + " kávu/káv!"); | ||
break; | ||
case 2: | ||
Console.WriteLine("Vybral jsi " + mnozstvi + "čaj/čaje!"); | ||
break; | ||
case 3: | ||
Console.WriteLine("Vybral jsi " + mnozstvi + "limonádu/limonády!"); | ||
break; | ||
case 4: | ||
Console.WriteLine("Vybral jsi " + mnozstvi + "vodu/vody!"); | ||
break; | ||
default: | ||
Console.WriteLine("Neznámý výběr nápoje"); | ||
break; | ||
} |
11 changes: 11 additions & 0 deletions
11
src/Lekce03.BreakoutRoom2,TryParse/Lekce03.BreakoutRoom2.TryParse.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<RootNamespace>Lekce03.BreakoutRoom2_TryParse</RootNamespace> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Výpočet ceny nápoje: | ||
|
||
// Pomocí Console.WriteLine Vypiš do konzole výzvu pro uživatele, aby zadal cenu nápoje. | ||
// Cena by měla být zadaná jako číslo s plovoucí desetinnou tečkou (například 1.5 pro Kávu). | ||
// Načti si uživatelský vstup pomocí Console.ReadLine() a ulož ho do proměnné vstupCenaNapoje. | ||
|
||
// Použití double.TryParse: | ||
// Vytvořte proměnnou cenaNapoje typu double pro uložení výsledku převodu. | ||
// Použijte metodu double.TryParse s uživatelským vstupem vstupCenaNapoje a proměnnou cenaNapoje. | ||
// double.TryParse vrátí boolovskou hodnotu, kterou uložte do proměnné jeCenaPlatna. | ||
|
||
// Výpočet celkové ceny: | ||
// Pokud byl vstup úspěšně převeden (jeCenaPlatna je true), vypiš do konzole výzvu pro zadání počtu nápojů. | ||
// Použij int.TryParse pro převod počtu nápojů na číslo a ulož výsledek do proměnné pocetNapoju. | ||
// Vypočítej celkovou cenu (cena nápoje * počet nápojů) a vypiš výsledek. | ||
// Pokud nebyl vstup úspěšně převeden, vypiš varovnou zprávu o neplatném zadání ceny. | ||
|
||
Console.WriteLine("Cena napoju"); | ||
Console.WriteLine("Zadej cenu napoje i s plovouci desetinnou teckou - napr. 1.5 pro Kavu"); | ||
|
||
string vstupCenaNapoje = Console.ReadLine(); | ||
|
||
double cenaNapoje; | ||
bool jeCenaPlatna = double.TryParse(vstupCenaNapoje, out cenaNapoje); | ||
|
||
if (jeCenaPlatna) | ||
{ | ||
Console.WriteLine("Zadej pocet napoju:"); | ||
int pocetNapoju; | ||
string vstupPocetNapoju = Console.ReadLine(); | ||
bool jePocetPlatny = int.TryParse(vstupPocetNapoju, out pocetNapoju); | ||
|
||
if (jePocetPlatny) | ||
{ | ||
double celkovaCena = pocetNapoju * cenaNapoje; | ||
Console.WriteLine($"Celkova cena je {celkovaCena}"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine($"Neplatny pocet. Nedokázal jsem převést text {vstupPocetNapoju} na celé číslo."); | ||
} | ||
} | ||
else | ||
{ | ||
Console.WriteLine( | ||
$"Zadana spatna cena :( Nedokázal jsem převést text {vstupCenaNapoje} na desetinné číslo."); | ||
} | ||
|
||
// Alternativne s poizitim return | ||
|
||
Console.WriteLine("Cena napoju"); | ||
Console.WriteLine("Zadej cenu napoje i s plovouci desetinnou teckou - napr. 1.5 pro Kavu"); | ||
|
||
string vstupCenaNapoje2 = Console.ReadLine(); | ||
|
||
double cenaNapoje2; | ||
bool jeCenaPlatna2 = double.TryParse(vstupCenaNapoje2, out cenaNapoje2); | ||
|
||
if (!jeCenaPlatna2) | ||
{ | ||
Console.WriteLine( | ||
$"Zadana spatna cena :( Nedokázal jsem převést text {vstupCenaNapoje2} na desetinné číslo."); | ||
return; | ||
} | ||
|
||
Console.WriteLine("Zadej pocet napoju:"); | ||
int pocetNapoju2; | ||
string vstupPocetNapoju2 = Console.ReadLine(); | ||
bool jePocetPlatny2 = int.TryParse(vstupPocetNapoju2, out pocetNapoju2); | ||
|
||
if (!jePocetPlatny2) | ||
{ | ||
Console.WriteLine($"Neplatny pocet. Nedokázal jsem převést text {vstupPocetNapoju2} na celé číslo."); | ||
return; | ||
} | ||
|
||
double celkovaCena2 = pocetNapoju2 * cenaNapoje2; | ||
Console.WriteLine($"Celkova cena je {celkovaCena2}"); | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// See https://aka.ms/new-console-template for more information | ||
|
||
int hadaneCislo = 4; | ||
|
||
Console.WriteLine("Zadej cislo od 0 do 10"); | ||
string textovyTip = Console.ReadLine(); | ||
|
||
int tip = int.Parse(textovyTip); | ||
Check warning on line 8 in src/Lekce03.Opakovani/Program.cs
|
||
|
||
bool cislaSeRovnaji = tip == hadaneCislo; | ||
if (cislaSeRovnaji) | ||
{ | ||
Console.WriteLine("Hura! Uhadl/a jsi!"); | ||
} | ||
else if (tip > hadaneCislo) | ||
{ | ||
Console.WriteLine("Mimo! Tip je moc vysoky"); | ||
} | ||
else if (tip < hadaneCislo) | ||
{ | ||
Console.WriteLine("Mimo! Tip je moc nizky"); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
bool jeDobrePocasi = true; | ||
bool jeVikend = true; | ||
|
||
bool chciJitSportovat = jeDobrePocasi && jeVikend; | ||
if (chciJitSportovat == true) | ||
{ | ||
Console.WriteLine("Jdu sportovat - je vikend a je hezky."); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Spotovat budu jindy, podminky nejsou vhodne."); | ||
} | ||
|
||
// toto je efektivne stejne - vykonase poku je pravda | ||
if (chciJitSportovat) { } | ||
if (chciJitSportovat == true) { } | ||
|
||
// toto je efektivne stejne - vykona se pokud chciJitSportovat je nepravda (false) | ||
if (chciJitSportovat == false) { } | ||
if (!chciJitSportovat) { } | ||
|
||
|
||
bool citimSeDobre = false; | ||
// jeDobrePocasi => true | ||
// !jeDobrePocasi => false | ||
// !citimSeDobre => true | ||
bool chciLenosit = !jeDobrePocasi || !citimSeDobre; | ||
// bool chciLenosit = false || true; | ||
if (chciLenosit) | ||
{ | ||
Console.WriteLine("Chci lenosit."); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Budu neco delat."); | ||
} | ||
|
||
if (!chciLenosit) | ||
{ | ||
Console.WriteLine("Budu neco delat - obraceny if"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Chci lenosit - obraceny if"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
string cilovaStanice = "Praha-Kacerov"; | ||
|
||
/* | ||
if (cilovaStanice == "Praha") | ||
{ | ||
Console.WriteLine("Jedeme do Prahy"); | ||
} | ||
else if (cilovaStanice == "Praha") | ||
{ | ||
Console.WriteLine("Jedeme do Brna"); | ||
} | ||
else | ||
{ | ||
Console.WriteLine("Tuto stanici neznam"); | ||
} | ||
*/ | ||
|
||
switch (cilovaStanice) | ||
{ | ||
default: | ||
Console.WriteLine("Tuto stanici neznam"); | ||
break; | ||
case "Praha": | ||
case "Praha-Bubenec": | ||
case "Praha-Zbraslav": | ||
case "Praha-Smichov": | ||
case "Praha-Dejvice": | ||
case "Praha-Hlavni nadrazi": | ||
case "Praha-Holesovice": | ||
Console.WriteLine("Jedeme do Prahy"); | ||
break; | ||
case "Brno": | ||
Console.WriteLine("Jedeme do Brna"); | ||
break; | ||
} |
10 changes: 10 additions & 0 deletions
10
src/Lekce03.Vyklad.TryParse/Lekce03.Vyklad.TryParse.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net9.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Console.WriteLine("Zadej cele cislo"); | ||
string vstupUzivatele = Console.ReadLine(); | ||
|
||
//int cislo = int.Parse(vstupUzivatele); // pokusi se prevest string na cislo, pokud se to nepovede, vyhodi vyjimku a program spadne | ||
int cislo; | ||
bool povedloSePrevest = int.TryParse(vstupUzivatele, out cislo); // pokusi se prevest string na cislo, pokud se to povede, vrati true, jinak false | ||
|
||
if (povedloSePrevest == true) // if (povedloSePrevest) - ekvivalentni zapis | ||
{ | ||
Console.WriteLine("Zadano cislo " + cislo); | ||
} | ||
else | ||
{ | ||
Console.Write("Nezadano cislo. Nedokazu prevest " + vstupUzivatele + " na cele cislo."); | ||
} |