Skip to content

Commit 1bbcbea

Browse files
Add Comments to Lab sheet 3 Exercises
1 parent b45a3d4 commit 1bbcbea

File tree

7 files changed

+25
-6
lines changed

7 files changed

+25
-6
lines changed

Lab Sheets/Lab Sheet 03/Lakshan/Exercise 1/Test.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
public class Test {
22
public static void main(String[] args) {
3+
// Create Students Objects
34
Student s1 = new Student();
45
Student s2 = new Student();
56

7+
// Assign values to the objects
68
s1.name = "Pasindu";
79
s1.ditno = "IT20123456";
810
s1.address = "Galle";
911

1012
s2.name = "Lakshan";
1113
s2.ditno = "IT20123457";
1214
s2.address = "Matara";
15+
16+
// Display the values
1317
System.out.println("Student 1");
1418
System.out.println("Name: " + s1.name + "\nDitno: " + s1.ditno + "\nAddress: " + s1.address + "\n");
1519
System.out.println("Student 2");

Lab Sheets/Lab Sheet 03/Lakshan/Exercise 2/Student.Java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ public class Student {
33
private String ditno;
44
private String address;
55

6-
6+
//default constructor
77
public Student() {
88
this.name = null;
99
this.ditno = null;
1010
this.address = null;
1111
}
12-
12+
//constructor with parameters
1313
public Student(String name, String ditno, String address) {
1414
this.name = name;
1515
this.ditno = ditno;

Lab Sheets/Lab Sheet 03/Lakshan/Exercise 2/Test.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
public class Test {
22
public static void main(String[] args) {
3+
//Create Objects using the constructor
34
Student s1 = new Student("Pasindu","IT20123456","Galle");
45
Student s2 = new Student("Lakshan","IT20123457","Matara");
56
}

Lab Sheets/Lab Sheet 03/Lakshan/Exercise 3/Student.Java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@ public class Student {
33
private String ditno;
44
private String address;
55

6-
6+
//default constructor
77
public Student() {
88
this.name = null;
99
this.ditno = null;
1010
this.address = null;
1111
}
12-
12+
//constructor with parameters
1313
public Student(String name, String ditno, String address) {
1414
this.name = name;
1515
this.ditno = ditno;
1616
this.address = address;
1717
}
18+
19+
//Mutator methods
1820
public void setName(String name) {
1921
this.name = name;
2022
}
@@ -24,6 +26,8 @@ public class Student {
2426
public void setAddress(String address) {
2527
this.address = address;
2628
}
29+
30+
//Accessor methods
2731
public String getName() {
2832
return this.name;
2933
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
public class Test {
22
public static void main(String[] args) {
3+
//Create Objects using the constructor
34
Student s1 = new Student("Pasindu","IT20123456","Galle");
45

6+
//Change values using mutator methods
57
s1.setName("Lakshan");
68
s1.setDitno("IT20657567");
79
s1.setAddress("Colombo");
10+
11+
//Dislplay changed values
812
System.out.println("Name: " + s1.getName()+ "\nDitno: " + s1.getDitno() + "\nAddress: " + s1.getAddress());
913
}
1014
}

Lab Sheets/Lab Sheet 03/Lakshan/Exercise 4/Student.Java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,20 @@ public class Student {
33
private String ditno;
44
private String address;
55

6-
6+
//default constructor
77
public Student() {
88
this.name = null;
99
this.ditno = null;
1010
this.address = null;
1111
}
12-
12+
//constructor with parameters
1313
public Student(String name, String ditno, String address) {
1414
this.name = name;
1515
this.ditno = ditno;
1616
this.address = address;
1717
}
18+
19+
//Mutator methods
1820
public void setName(String name) {
1921
this.name = name;
2022
}
@@ -24,6 +26,8 @@ public class Student {
2426
public void setAddress(String address) {
2527
this.address = address;
2628
}
29+
30+
//Accessor methods
2731
public String getName() {
2832
return this.name;
2933
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
public class Test {
22
public static void main(String[] args) {
3+
//Create Objects using the constructor
34
Student s1 = new Student("Pasindu","IT20123456","Galle");
45

6+
//Desplay Values using getDetails() method
57
System.out.println(s1.getDetails());
68
}
79
}

0 commit comments

Comments
 (0)