Skip to content
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
3 changes: 1 addition & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

35 changes: 35 additions & 0 deletions Animals.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
public class Animals {
protected String name;
protected int runLimit = 0;
protected float jumpLimit = 0f;
protected int swimLimit = 0;

public Animals(String name) {
this.name = name;
}

public void info() {
System.out.println("name: " + name );
}
public void run(int i){
boolean a= false;
if(i<runLimit){
a=true;
}
System.out.println(a);
}
public void jump(float i){
boolean a= false;
if(i<jumpLimit){
a=true;
}
System.out.println(a);
}
public void swim(int i){
boolean a= false;
if(i<swimLimit){
a=true;
}
System.out.println(a);
}
}
11 changes: 11 additions & 0 deletions Cat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Cat extends Animals {
protected int catRunLimit = 200;
protected float catJumpLimit = 2f;
public Cat(String name) {
super(name);
runLimit = catRunLimit;
jumpLimit = catJumpLimit;
}


}
11 changes: 11 additions & 0 deletions Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Dog extends Animals {
protected int dogRunLimit = 500;
protected float dogJumpLimit = 0.5f;
protected int dofSwimLimit = 10;
public Dog(String name) {
super(name);
runLimit = dogRunLimit;
jumpLimit = dogJumpLimit;
swimLimit = dofSwimLimit;
}
}
3 changes: 3 additions & 0 deletions src/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: lesson4.GameXO

1 change: 1 addition & 0 deletions src/homework6
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

4 changes: 2 additions & 2 deletions src/lesson3/Methods.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ static void func(String data) {
static void func(int... args) {
int sum = 0;
for (int i = 0; i < args.length; i++) {
sum += args[i];
sum += args[i] + 5;
}
System.out.println(sum);
System.out.println(sum + 1);
}

static void func(Object... objects) {
Expand Down
71 changes: 71 additions & 0 deletions src/lesson3/homework.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package lesson3;

import java.util.Random;
import java.util.Scanner;

public class homework {
public static void GuessGame() {

Random rnd = new Random();
int keepPlaying = 1;
int answer;
while (keepPlaying == 1) {
answer = rnd.nextInt(10);
System.out.println("Загадано число, попробуйте отгадать");
Scanner in = new Scanner(System.in);
for (int i = 0; i < 3; i++) {
int userAnswer = in.nextInt();
if (userAnswer == answer) {
System.out.println("Поздравляю, вы угадали");
break;
}
if (userAnswer > answer) {
System.out.println("Ваш ответ был слишком большим");
}
if (userAnswer < answer) {
System.out.println("Ваш ответ был слишком маленьким");
}
}
System.out.println("Повторить игру еще раз? 1 – да / 0 – нет");
keepPlaying = in.nextInt();
}
}

public static void GuessTheWord() {
String[] words = {"apple", "orange", "lemon", "banana", "apricot", "avocado", "broccoli", "carrot", "cherry", "garlic", "grape", "melon", "leak", "kiwi", "mango", "mushroom", "nut", "olive", "pea", "peanut", "pear", "pepper", "pineapple", "pumpkin", "potato"};

Random rnd = new Random();
String answer;
answer = words[rnd.nextInt(words.length)];
System.out.println("Загадано слово, попробуйте отгадать");
Scanner in = new Scanner(System.in);
while (true) {
String userAnswer = in.nextLine();
if (userAnswer.equalsIgnoreCase(answer)) {
System.out.println("Поздравляю, вы угадали");
break;
} else {
String wrongGuess = "";
for (int i = 0; i < 9; i++) {
if (i < userAnswer.length() && i < answer.length()) {
if (userAnswer.charAt(i) == answer.charAt(i)) {
wrongGuess += userAnswer.charAt(i);
} else {
wrongGuess += "#";
}
}
else{
wrongGuess +="#";
}

}
System.out.println(wrongGuess);
}
}
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Хорошая работа

public static void main(String[] args) {
GuessTheWord();
GuessGame();
}
}
84 changes: 84 additions & 0 deletions src/lesson3/homework/WordsGame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package lesson3.homework;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

public class WordsGame {

private static String[] words = {"apple", "orange", "lemon", "banana",
"apricot", "avocado", "broccoli", "carrot", "cherry", "garlic", "grape",
"melon", "leak", "kiwi", "mango", "mushroom", "nut",
"olive", "pea", "peanut", "pear", "pepper", "pineapple",
"pumpkin", "potato"};
private final Random rnd = new Random();

public void game() {
System.out.println("Вам предстоит угадать слово");
System.out.println("Как вы думаете какое слово я загадал? " +
"Я буду открывать верные буквы!");
String word = words[rnd.nextInt(words.length)];
String random = word;
word = word + "#".repeat(15 - word.length());
//System.out.println(random);
//System.out.println(word);
char [] sym = word.toCharArray();
Arrays.fill(sym, '#');
Scanner in = new Scanner(System.in);
boolean inGame = true;
while (inGame) {
System.out.println("Введите ваше предположение");
String predict = in.next();
if (predict.equals(random)) {
System.out.println("Вы угадали! Я загадал слово: " + predict);
return;
}

for (int i = 0; i < word.length(); i++) {
if (i < predict.length() && predict.charAt(i) == word.charAt(i)) {
if (sym[i] == '#') {
sym[i] = word.charAt(i);
}
}
}
for(char ch : sym) System.out.print(ch);
System.out.println();
}
}

public static void main(String[] args) throws FileNotFoundException {
if (args != null && args.length == 1) {
if (args[0].equals("-h") || args[0].equals("-help")) {
System.out.println("use path to file or use list of param or don't use param");
return;
}
File file = new File(args[0]);
if (file.exists()) {
Scanner in = new Scanner(file);
ArrayList<String> list = new ArrayList<>();
while (in.hasNext()) {
list.add(in.next());
}
in.close();
//System.out.println(list);
String [] tmp = new String[list.size()];
for (int i = 0; i < list.size(); i++) {
tmp[i] = list.get(i);
}
words = tmp;
System.out.println(Arrays.toString(words));
new WordsGame().game();
}
} else {
if (args == null || args.length == 0) {
new WordsGame().game();
} else {
words = args;
new WordsGame().game();
}
}
}
}
Loading