Skip to content

Instantly share code, notes, and snippets.

@lislon
Created August 3, 2019 10:09
Show Gist options
  • Save lislon/eab0b63114bdeda37796432011f4170b to your computer and use it in GitHub Desktop.
Save lislon/eab0b63114bdeda37796432011f4170b to your computer and use it in GitHub Desktop.
import java.awt.*;
public class Cat
{
// Константы
public static final int NUMBER_EYES = 2;
public static final double MIN_WEIGHT = 1000.0;
public static final double MAX_WEIGHT = 9000.0;
private double originWeight;
private double weight;
private double minWeight;
private double maxWeight;
public static int count; // Статическая переменная count
public double weightCat;
public String color;
public String name;
public Cat()
{
weight = 1500.0 + 3000.0 * Math.random();
originWeight = weight;
minWeight = 1000.0;
maxWeight = 9000.0;
}
// 3.7 Копирование объектов
public double getOriginWeight() {
return originWeight;
}
public void setOriginWeight(double originWeight) {
this.originWeight = originWeight;
}
public void setWeight(double weight) {
this.weight = weight;
}
public double getMinWeight() {
return minWeight;
}
public void setMinWeight(double minWeight) {
this.minWeight = minWeight;
}
public double getMaxWeight() {
return maxWeight;
}
public void setMaxWeight(double maxWeight) {
this.maxWeight = maxWeight;
}
public Cat clone() throws CloneNotSupportedException {
return (Cat) super.clone();
}
// 3.6 Создать у кошки геттер и сеттер для окраса.
ColoringCat myColor = ColoringCat.GRAY;
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
// 3.5 Создание объектов и конструктор
public Cat(Double weightCat)
{
weight = weightCat;
}
public void meow()
{
weight = weight - 1;
System.out.println("Meow");
}
public void feed(Double amount)
{
weight = weight + amount;
}
public void drink(Double amount)
{
weight = weight + amount;
}
public Double getWeight()
{
return weight;
}
// Создания метода который будет возвращать массу съеденной еды
public Double getEaten()
{
Double result = weight - originWeight;
return (result <0 ? 0 :result);
}
// Создания метода сходить в туалет
public void toToilet()
{
weight = weight - 100.0;
System.out.println("Хорошо то, как стало");
}
public void counting()
{
if (weight > maxWeight){
count = count -1;
}
if (weight < minWeight){
count = count -1;
}
}
public static int getCount(int count)
{
return count;
}
public String getStatus()
{
if(weight < minWeight) {
return "Dead";
}
else if(weight > maxWeight) {
return "Exploded";
}
else if(weight > originWeight) {
return "Sleeping";
}
else {
return "Playing";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment