Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
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;
}
}
9 changes: 9 additions & 0 deletions Lab Sheets/Lab Sheet 03/Lakshan/Exercise 10/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class Main {
public static void main(String[] args){

Dog dog1 = new Dog("Lissie","Smith",10,3);
dog1.showDetails();
Dog dog2 = new Dog("Kyan","Silva");
dog2.showDetails();
}
}//end of the demo class
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
16 changes: 16 additions & 0 deletions Lab Sheets/Lab Sheet 03/Lakshan/Exercise 11/Cat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
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;
}
public void showDetails(){
super.showDetails();
System.out.println("I am a cat. " +
this.livesLeft + " lives remain for me.");
}
}//end of the pet class
15 changes: 15 additions & 0 deletions Lab Sheets/Lab Sheet 03/Lakshan/Exercise 11/Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
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 = 1;
}
public void showDetails(){
super.showDetails();
System.out.println("I am a dog. I have "+this.noOfMasters+" masters at home");
}
}
8 changes: 8 additions & 0 deletions Lab Sheets/Lab Sheet 03/Lakshan/Exercise 11/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public class Main {
public static void main(String[] args){
Cat cat1 = new Cat("Kitty", "James");
cat1.showDetails();
Dog dog1 = new Dog("Jimi", "Jhon");
dog1.showDetails();
}
}//end of the demo class
19 changes: 19 additions & 0 deletions Lab Sheets/Lab Sheet 03/Lakshan/Exercise 11/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
11 changes: 11 additions & 0 deletions Lab Sheets/Lab Sheet 03/Lakshan/Exercise 9/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
13 changes: 13 additions & 0 deletions Lab Sheets/Lab Sheet 03/Lakshan/Exercise 9/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
public class Main {
public static void main(String[] args){
Pet p = new Pet("Lissie","Smith",3);
p.showDetails();
Cat c = new Cat("Kyan", "Silva", 4, 4);
c.showDetails();

Pet p2 = new Pet("Kitty","Jhon");
p2.showDetails();
Cat c2 = new Cat("Jimi","James");
c2.showDetails();
}
}//end of the demo class
19 changes: 19 additions & 0 deletions Lab Sheets/Lab Sheet 03/Lakshan/Exercise 9/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