Skip to content

Instantly share code, notes, and snippets.

@mariiaKolokolova
Created June 4, 2020 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mariiaKolokolova/8872706ced8f0066acfc07feb2845615 to your computer and use it in GitHub Desktop.
Save mariiaKolokolova/8872706ced8f0066acfc07feb2845615 to your computer and use it in GitHub Desktop.
OOP_HomeWork1A
package maricka.kolokolova;
public class Cat {
private String name;
private int age;
private double weight;
private String color;
public Cat(String name, int age, double weight, String color) {
super();
this.name = name;
this.age = age;
this.weight = weight;
this.color = color;
}
public Cat() {
super();
// TODO Auto-generated constructor stub
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public double getWeight() {
return weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
public void voice () {
System.out.println("Meow!");
}
public void eat () {
System.out.println("I want to eat!");
}
public void play () {
System.out.println("I want to play!");
}
public void sleep () {
System.out.println(name + " is sleeping!");
}
@Override
public String toString() {
return "Cat [name=" + name + ", age=" + age + ", weight=" + weight + ", color=" + color + "]";
}
}
package maricka.kolokolova;
public class Main {
public static void main(String[] args) {
// TODO Auto-generated method stub
Cat canOne = new Cat("Murzik", 2, 2.5, "White");
Cat canTwo = new Cat("Busya", 3, 4.0, "Red");
System.out.println("Hello! I'm " + canOne.getName()+ "!" );
canOne.eat();
canOne.play();
System.out.println("Hello! I'm " + canTwo.getName()+ "!" );
canTwo.voice();
canTwo.sleep();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment