-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rozwiązanie do lekcji drugiej - klasa Interfejs, która pozwala wczyty…
…wać dane z klwiatury; komentarze do kodu
- Loading branch information
Showing
5 changed files
with
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package pl.kobietydokodu.koty; | ||
|
||
import java.util.Scanner; | ||
|
||
import pl.kobietydokodu.koty.domain.Kot; | ||
|
||
|
||
/** | ||
* Interfejs aplikacji - klasa, którą można uruchomić dzięki metodzie main(...) | ||
*/ | ||
public class Interfejs { | ||
|
||
/** | ||
* Obiekt typu Scanner do wczytywania wejścia z klawiatury. | ||
*/ | ||
static Scanner inputScanner = new Scanner(System.in); | ||
|
||
/** | ||
* Metoda main, pozwalająca na uruchomienie klasy jako aplikacji. | ||
* @param args Argumenty konsoli - nieużywane | ||
*/ | ||
public static void main(String[] args) { | ||
Kot kot = new Kot(); | ||
|
||
System.out.print("Podaj imię kota: "); | ||
kot.setImie(getUserInput()); | ||
|
||
System.out.print("Podaj, kto jest opiekunem kota: "); | ||
kot.setImieOpiekuna(getUserInput()); | ||
|
||
System.out.println("Dziękuję, teraz już wiem prawie wszystko o kocie!"); | ||
} | ||
|
||
/** | ||
* Pomocnicza metoda pozwalająca pobrać jedną linijkę wpisaną przez użytkownika. | ||
* @return Wczytana linijka. | ||
*/ | ||
public static String getUserInput() { | ||
return inputScanner.nextLine().trim(); | ||
} | ||
|
||
} |
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
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 @@ | ||
Ten plik istenieje tylko po to, aby Git widział ten katalog. Po umieszczeniu plików w tym katalogu, należy go usunąć. |
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 @@ | ||
Ten plik istenieje tylko po to, aby Git widział ten katalog. Po umieszczeniu plików w tym katalogu, należy go usunąć. |
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 @@ | ||
Ten plik istenieje tylko po to, aby Git widział ten katalog. Po umieszczeniu plików w tym katalogu, należy go usunąć. |