Guest 666
Ученик
(107),
на голосовании
1 год назад
Задание: “Создать класс "дом". Перенести в него восстановление настроения и здоровья. Добавить новые фишки(Минимум 3 шт.). Прописать добавленные возможности в комментарии” помогите плиз а то спать хочу.. заранее спасибо import java.util.Random;
public class Person { Random random = new Random(); String name; int age; String job; boolean working; int health = 100; int days = 0; int money = 0; int depression = 0; int home = 0;
void goToWork() { if (working) { System.out.println("I'm working now!"); } else { System.out.println("Time for work!"); int r = random.nextInt(100); if (r < depression) { hit(); } int gop = random.nextInt(100); if (gop < 5) { battle(); }
void goHome() { if (working) { System.out.println("Time to go home");
if (money >= 400) { market(); System.out.println(); }
int buy = random.nextInt(100);
if (money >= 20) { if (buy < 10) { lottery(); } }
int tv = random.nextInt(100); if (tv < 10) { System.out.println("I saw a movie"); depression -= 5; } working = false; System.out.println("My health: " + health); days++; depression += 1; } else { System.out.println("I'm at home now! Get off!"); } }
void hit() { System.out.println("OUCH!"); health -= random.nextInt(20); }
помогите плиз а то спать хочу.. заранее спасибо
import java.util.Random;
public class Person {
Random random = new Random();
String name;
int age;
String job;
boolean working;
int health = 100;
int days = 0;
int money = 0;
int depression = 0;
int home = 0;
public Person(String name, int age, String job, boolean working) {
this.namе = name;
this.age = age;
this.job = job;
this.working = working;
}
void goToWork() {
if (working) {
System.out.println("I'm working now!");
} else {
System.out.println("Time for work!");
int r = random.nextInt(100);
if (r < depression) {
hit();
}
int gop = random.nextInt(100);
if (gop < 5) {
battle();
}
money += 50 - depression / 2;
broke();
working = true;
}
}
void goHome() {
if (working) {
System.out.println("Time to go home");
if (money >= 400) {
market();
System.out.println();
}
int buy = random.nextInt(100);
if (money >= 20) {
if (buy < 10) {
lottery();
}
}
int tv = random.nextInt(100);
if (tv < 10) {
System.out.println("I saw a movie");
depression -= 5;
}
working = false;
System.out.println("My health: " + health);
days++;
depression += 1;
} else {
System.out.println("I'm at home now! Get off!");
}
}
void hit() {
System.out.println("OUCH!");
health -= random.nextInt(20);
}
void broke() {
if (health <= 0) {
System.out.println(days);
System.exit(0);
}
}
void market() {
if (health < 100) {
System.out.println("I bought doner");
health += 25;
money -= 400 + (days % 30) * 5;
}
}
void battle() {
int r = random.nextInt(100);
System.out.println("I meet bandits");
if (r < 15) {
System.out.println("I won");
money += 50;
depression = 0;
} else {
System.out.println("I lost");
health -= 10;
depression += 4;
}
}
void lottery() {
int lot = random.nextInt(100);
if (lot < 2) {
System.out.println("I winner!!!");
money += 500;
} else {
System.out.println("I loose this game!");
money -= 20;
}
}
}