Last active
August 11, 2016 14:20
-
-
Save OlexiyNasikovsky/198e83583eb24a6de87332594f2bba97 to your computer and use it in GitHub Desktop.
CatProj
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 CatProj; | |
public class Cat { | |
private String name; | |
private double weight; | |
private String colour; | |
private double speedOfEating; | |
private int age; | |
public Cat(String name, double weight, String colour, double speedOfEating, int age) { | |
super(); | |
this.name = name; | |
this.weight = weight; | |
this.colour = colour; | |
this.speedOfEating = speedOfEating; | |
this.age = age; | |
} | |
public Cat() { | |
super(); | |
} | |
public static void sayMeow() { | |
System.out.println("Meeeoooow!!!!!"); | |
} | |
public void eat(String food) { | |
Cat.sayMeow(); | |
System.out.println("That is my favorite " + food + ". I can eat it with speed: " + | |
speedOfEating + " " + food + "s per minute"); | |
weight++; | |
} | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public double getWeight() { | |
return weight; | |
} | |
public void setWeight(double weight) { | |
this.weight = weight; | |
} | |
public String getColour() { | |
return colour; | |
} | |
public void setColour(String colour) { | |
this.colour = colour; | |
} | |
public double getSpeedOfEating() { | |
return speedOfEating; | |
} | |
public void setSpeedOfEating(double speedOfEating) { | |
this.speedOfEating = speedOfEating; | |
} | |
} |
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 CatProj; | |
public class Flat { | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
Cat fred = new Cat("Fred", 3, "Red", 1.2, 2); | |
Cat carl = new Cat("Carl", 4.3, "Black", 2.0, 4); | |
Cat bradley = new Cat("Bradley", 10, "Green", 6.9, 5); | |
Cat sam = new Cat("Sam", 5, "White", 3, 3); | |
fred.eat("BigMac"); | |
carl.eat("Carrot"); | |
bradley.eat("Pig Leg"); | |
sam.eat("Rattatoe"); | |
} | |
} |
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
Описать класс «Cat» (в качестве образца можно взять домашнего питомца). | |
Наделить его свойствами и методами. Создать несколько экземпляров объектов этого | |
класса. Использовать эти объекты. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment