File tree Expand file tree Collapse file tree 7 files changed +25
-6
lines changed
Lab Sheets/Lab Sheet 03/Lakshan Expand file tree Collapse file tree 7 files changed +25
-6
lines changed Original file line number Diff line number Diff line change 11public 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 + "\n Ditno: " + s1 .ditno + "\n Address: " + s1 .address + "\n " );
1519 System .out .println ("Student 2" );
Original file line number Diff line number Diff 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 ;
Original file line number Diff line number Diff line change 11public 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 }
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change 11public 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 ()+ "\n Ditno: " + s1 .getDitno () + "\n Address: " + s1 .getAddress ());
913 }
1014}
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff line change 11public 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}
You can’t perform that action at this time.
0 commit comments