assignmentS1

This commit is contained in:
k0rrluna 2025-02-19 00:21:28 +03:00
parent 1702b10d27
commit 2c4a3a53b9
4 changed files with 141 additions and 0 deletions

View File

@ -0,0 +1,25 @@
package assignments.AssigmentS1;
class Dachshund extends Dog {
int length = 1000;
Dachshund() {
name = "German Sausage";
color = "Sausage Red";
breed = "Sausage Dog";
hungry = 0; // If 1 then hungry
}
public String SausageLength() {
return length + " cm";
}
void setLength(int length) {
this.length = length;
}
public String wag_tail() {
return "No wag, doing plank!!!";
}
}

View File

@ -0,0 +1,50 @@
package assignments.AssigmentS1;
class Dog {
String name;
String color; // colour ?
String breed;
int hungry; // If 1 then hungry
Dog() {
name = "John Dog";
color = "Brown";
breed = "Street dog";
hungry = 1;
}
public String bark() {
return "Woof! Woof!";
}
public String fetch() {
if (hungry != 1) { // In C if(!hungry) {}
return "Here's stick!";
} else {
return "Too hungry!";
}
}
public String wag_tail() {
return "Little wag!";
}
void setName(String name) {
this.name = name;
}
void setHungry(int hungry) {
this.hungry = hungry;
}
void setColor(String color) {
this.color = color;
}
void setBreed(String breed) {
this.breed = breed;
}
}

View File

@ -0,0 +1,39 @@
package assignments.AssigmentS1;
class DogDemo {
public static void main(String[] args) {
Kangal dog1 = new Kangal();
Dog dog2 = new Kangal();
Dog dog3 = new Dog();
Dachshund dog4 = new Dachshund();
System.out.println();
System.out.println(dog1.name);
dog1.setHungry(1);
System.out.println(dog1.wag_tail());
dog1.protectedAnimal("Chicken");
System.out.println(dog1.guard());
System.out.println();
dog2.setName("Kaplan Korur");
System.out.println(dog2.name + ", " + dog2.breed + ", " + dog2.color);
dog2.setHungry(0);
System.out.println(dog2.wag_tail());
// System.out.println(dog2.guard()); --> ERROR
System.out.println();
System.out.println(dog3.name);
dog3.setHungry(0);
System.out.println(dog3.wag_tail());
System.out.println(dog3.fetch());
System.out.println();
System.out.println(dog4.name +", " + dog4.color);
dog4.setHungry(1);
System.out.println(dog4.wag_tail()+ " Current length: " + dog4.SausageLength());
System.out.println(dog4.fetch());
}
}

View File

@ -0,0 +1,27 @@
package assignments.AssigmentS1;
class Kangal extends Dog {
String Protects;
Kangal() {
name = "Aslan Korur";
color = "Yellow";
breed = "Protect Dog";
hungry = 0; // If 1 then hungry
Protects = "Sheep";
}
public String guard() {
return "ON DUTY! and Protects: " + Protects;
}
public String wag_tail() {
return "No wag!";
}
void protectedAnimal(String Protects) {
this.Protects = Protects;
}
}