-
-
Save mariiaKolokolova/8872706ced8f0066acfc07feb2845615 to your computer and use it in GitHub Desktop.
OOP_HomeWork1A
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
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 + "]"; | |
} | |
} |
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
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