Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add Exercise 10
  • Loading branch information
pasindulakshan committed Aug 6, 2021
commit ba9e0df2f34730f615f3780045fa6eba9621a5d8
11 changes: 11 additions & 0 deletions Lab Sheets/Lab Sheet 03/Lakshan/Exercise 10/Cat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Cat extends Pet{
private int livesLeft;
public Cat(String n, String o, int a, int l) {
super(n, o, a);
this.livesLeft = l;
}
public Cat(String n, String o) {
super(n, o);
this.livesLeft = 7;
}
}//end of the pet class
11 changes: 11 additions & 0 deletions Lab Sheets/Lab Sheet 03/Lakshan/Exercise 10/Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
public class Dog extends Pet{
int noOfMasters;
public Dog(String n, String o, int a, int m) {
super(n, o, a);
this.noOfMasters = m;
}
public Dog(String n, String o) {
super(n, o);
this.noOfMasters = 0;
}
}
19 changes: 19 additions & 0 deletions Lab Sheets/Lab Sheet 03/Lakshan/Exercise 10/Pet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
public class Pet {
private String name;
private String owner;
private int age;

public Pet(String n, String o, int a) {
this.name = n;
this.owner = o;
this.age = a;
}
public Pet(String n, String o) {
this.name = n;
this.owner = o;
this.age = 0;
}
public void showDetails(){
System.out.println("I am a pet. My name is " +this.name+". My owner is "+this.owner);
}
}//end of the pet class