-
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 25, 2025
1 parent
1507c6e
commit a775864
Showing
9 changed files
with
314 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/Lekce06.BreakoutRoom1.Metody/Lekce06.BreakoutRoom1.Metody.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,110 @@ | ||
using System; | ||
|
||
internal class Program | ||
{ | ||
/* | ||
* Níže je uvedeno ukázkové řešení domácího úkolu. | ||
* | ||
* TIP: Všechny metody píšeme mimo metodu Main. Každá metoda má tento obecný tvar: | ||
* | ||
* public static [NavratovyTyp] [JmenoMetody]([TypParametru1] [JmenoParametru1], ...) | ||
* { | ||
* // Tělo metody | ||
* return [Hodnota]; | ||
* } | ||
* | ||
* V následující ukázce metody: | ||
* NavratovyTyp = string (metoda navrací text) | ||
* JmenoMetody = UkazkaMetodySNavratovymTypem (metody nazýváme libovolným textem s velkým počátečním písmenem) | ||
* TypParametru1 = string (libovolný datový typ, zde string) | ||
* JmenoParametru1 = textVParametru (pod tímto názvem "text" je dodaný parametr dostupný v metodě) | ||
*/ | ||
public static string UkazkaMetodySNavratovymTypem(string textVParametru) | ||
{ | ||
/// Zde (tělo metody), můžeme pracovat s dodanými parametry (zde string text a double desetinneCislo) | ||
Console.WriteLine(textVParametru); // můžeme pracovat s parameterem textVParametru | ||
|
||
string promennaObsahujiciLibovolnyText = "Toto je libovolný text"; | ||
|
||
// Vracíme hodnotu z metody | ||
return promennaObsahujiciLibovolnyText; // navrácení hodnoty z metody přes RETURN, musíme vracet hodnotu typu string. | ||
} | ||
|
||
// TIP: Metody pište mimo Main, například přímo pod tento řádek | ||
|
||
public static string NactiText() | ||
{ | ||
Console.WriteLine("Zadej libovolný text:"); | ||
string vstupUzivatele = Console.ReadLine(); | ||
return vstupUzivatele; | ||
} | ||
|
||
public static double NactiDesetinneCislo() | ||
{ | ||
Console.WriteLine("Zadej libovolné desetinné číslo:"); | ||
string vstupUzivatele = Console.ReadLine(); | ||
double desetinneCislo; | ||
bool povedloSePrevest = double.TryParse(vstupUzivatele, out desetinneCislo); | ||
|
||
while (povedloSePrevest == false) | ||
{ | ||
Console.WriteLine("Zadal jsi nesprávně. Zadej libovolné desetinné číslo:"); | ||
vstupUzivatele = Console.ReadLine(); | ||
povedloSePrevest = double.TryParse(vstupUzivatele, out desetinneCislo); | ||
} | ||
return desetinneCislo; | ||
} | ||
|
||
public static string NactiText(string textProUzivatele) | ||
{ | ||
Console.WriteLine(textProUzivatele); | ||
string vstupUzivatele = Console.ReadLine(); | ||
return vstupUzivatele; | ||
} | ||
|
||
public static double NactiDesetinneCislo(string textProUzivatele) | ||
{ | ||
Console.WriteLine(textProUzivatele); | ||
string vstupUzivatele = Console.ReadLine(); | ||
double desetinneCislo; | ||
bool povedloSePrevest = double.TryParse(vstupUzivatele, out desetinneCislo); | ||
|
||
while (povedloSePrevest == false) | ||
{ | ||
Console.WriteLine($"Zadal jsi nesprávně. {textProUzivatele}"); | ||
vstupUzivatele = Console.ReadLine(); | ||
povedloSePrevest = double.TryParse(vstupUzivatele, out desetinneCislo); | ||
} | ||
return desetinneCislo; | ||
} | ||
|
||
static void Main(string[] args) | ||
{ | ||
/* | ||
1) Vytvořte metodu, která se bude uživatele ptát na zadání libovolného textu (string). | ||
Metoda navrátí tento text jako návratovou hodnotu. | ||
2) Zavolejte metodu a vypište text, který uživatel zadal. | ||
3) Vytvořte metodu pro zadání libovolného desetinného čísla(double). | ||
Dokud uživatel nezadá správně desetinné číslo, nechávejte uživatele pokusit se číslo zadat znovu. | ||
Jakmile zadá uživatel desetinné číslo správně, metoda jej navrátí toto desetinné číslo jako návratovou hodnotu. | ||
4) Zavolejte metodu a vypište desetinné číslo, které uživatel zadal. | ||
Bonus: 5) Přidejte metodám parametr typu string, ve kterém metodě předáte text, | ||
který se zobrací v konzoli před tím, než se uživatel pokusí zadat svůj vstup. | ||
6) Zavolejte metody s parametrem a vypište text, který uživatel zadal. | ||
*/ | ||
|
||
string vstupText = NactiText(); | ||
Console.WriteLine($"Zadal jsi text: {vstupText}"); | ||
|
||
double vstupDesetinneCislo = NactiDesetinneCislo(); | ||
Console.WriteLine($"Zadal jsi desetinné číslo: {vstupDesetinneCislo}"); | ||
|
||
string vstupTextBonus = NactiText("Zadej libovolný text pro bonus:"); | ||
Console.WriteLine($"Zadal jsi text pro bonus: {vstupTextBonus}"); | ||
|
||
double vstupDesetinneCisloBonus = NactiDesetinneCislo("Zadej libovolné desetinné číslo:"); | ||
Console.WriteLine($"Zadal jsi desetinné číslo pro bonus: {vstupDesetinneCisloBonus}"); | ||
} | ||
} |
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,50 @@ | ||
namespace Lekce06.BreakoutRoom1 | ||
{ | ||
// Úkol: Třída Clovek | ||
// -------------------------------------------- | ||
// Vytvořte třídu Clovek, která bude obsahovat následující vlastnosti: | ||
// - jméno (string) | ||
// - pohlaví (string) | ||
// - rok narození (int) | ||
// - hmotnost (double) | ||
// - v manželství (bool) | ||
// | ||
// Dále proveďte následující kroky: | ||
// 1. Vytvořte dvě instance třídy Clovek a naplňte je daty. | ||
// 2. Vypište informace o těchto instancích na konzoli . | ||
// (zatím pouze pomocí Console.WriteLine v metodě Main) | ||
|
||
class Clovek | ||
{ | ||
public string Jmeno; | ||
public string Pohlavi; | ||
public int RokNarozeni; | ||
public double Hmotnost; | ||
public bool VManzelstvi; | ||
} | ||
|
||
internal class Program | ||
{ | ||
static void Main(string[] args) | ||
{ | ||
|
||
Clovek petr = new Clovek(); | ||
petr.Jmeno = "Petr"; | ||
petr.Pohlavi = "Muz"; | ||
petr.RokNarozeni = 1980; | ||
petr.Hmotnost = 80; | ||
petr.VManzelstvi = true; | ||
|
||
Console.WriteLine($"Clovek {petr.Jmeno}, pohlavi {petr.Pohlavi}, rok narozeni {petr.RokNarozeni}, hmotnost {petr.Hmotnost}, je {petr.VManzelstvi}"); | ||
|
||
Clovek jana = new Clovek(); | ||
jana.Jmeno = "Jana"; | ||
jana.Pohlavi = "Zena"; | ||
jana.RokNarozeni = 2000; | ||
jana.Hmotnost = 65; | ||
jana.VManzelstvi = false; | ||
|
||
Console.WriteLine($"Clovek {jana.Jmeno}, pohlavi {jana.Pohlavi}, rok narozeni {jana.RokNarozeni}, hmotnost {jana.Hmotnost}, je {jana.VManzelstvi}"); | ||
} | ||
} | ||
} |
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,63 @@ | ||
namespace Lekce06.OOP.Vyklad; | ||
|
||
using System; | ||
|
||
internal class Program | ||
{ | ||
class Auto | ||
{ | ||
public string Vyrobce; | ||
public int PocetSedadel; | ||
public int RokVyroby; | ||
public string Barva; | ||
public bool MaSpecialniDisky; | ||
|
||
public void PopisSe() | ||
{ | ||
Console.WriteLine($"Na sklade mam {Vyrobce}, pocet sedadel {PocetSedadel}, rok vyroby {RokVyroby} a barvy {Barva}. Mam specialni disky : {MaSpecialniDisky}."); | ||
} | ||
} | ||
|
||
static void Main(string[] args) | ||
{ | ||
Console.WriteLine("Hello, World!"); | ||
|
||
Auto ferrari = new Auto(); | ||
ferrari.Vyrobce = "Ferrari"; | ||
ferrari.PocetSedadel = 2; | ||
ferrari.RokVyroby = 2012; | ||
ferrari.Barva = "Cervena"; | ||
ferrari.MaSpecialniDisky = true; | ||
|
||
/* | ||
string ferrariVyrobce = "Ferrari"; | ||
int ferrariPocetSedadel = 2; | ||
int ferrariRokVyroby = 2012; | ||
string ferrariBarva = "Cervena"; | ||
*/ | ||
|
||
//Console.WriteLine($"Na sklade mam {ferrari.Vyrobce}, pocet sedadel {ferrari.PocetSedadel}, rok vyroby {ferrari.RokVyroby} a barvy {ferrari.Barva}"); | ||
ferrari.PopisSe(); | ||
|
||
/* | ||
string skodaVyrobce = "Skoda"; | ||
int skodaPocetSedadel = 4; | ||
int skodaRokVyroby = 2013; | ||
string skodaBarva = "Cerna"; | ||
Console.WriteLine($"Na sklade mam {skodaVyrobce}, pocet sedadel {skodaPocetSedadel}, rok vyroby {skodaRokVyroby} a barvy {skodaBarva}"); | ||
*/ | ||
|
||
Auto skoda = new Auto(); | ||
skoda.Vyrobce = "Skoda"; | ||
skoda.PocetSedadel = 4; | ||
skoda.RokVyroby = 2015; | ||
skoda.Barva = "Cerna"; | ||
|
||
skoda.PopisSe(); | ||
|
||
Console.WriteLine(default(int)); | ||
Console.WriteLine(default(bool)); | ||
Console.WriteLine(default(string)); | ||
} | ||
} |
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,27 @@ | ||
internal class Program | ||
{ | ||
private static void Main(string[] args) | ||
{ | ||
// toto se zapomene | ||
VypocitejMujVek(1975); | ||
// vysledek volani si musim ulozit do promenne | ||
int mujVek = UzivatelZadaSvujRokNarozeniAVypocitaSeJehoVek(); | ||
Console.WriteLine($"Muj vek je {mujVek}."); | ||
} | ||
|
||
public static int VypocitejMujVek(int rokNarozeni) | ||
{ | ||
int vek = 2025 - rokNarozeni; | ||
return vek; | ||
} | ||
|
||
public static int UzivatelZadaSvujRokNarozeniAVypocitaSeJehoVek() | ||
{ | ||
Console.WriteLine("Napis rok narozeni"); | ||
string text = Console.ReadLine(); | ||
int rokNarozeni = int.Parse(text); | ||
int vek = VypocitejMujVek(rokNarozeni); | ||
return vek; | ||
} | ||
|
||
} |