-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Session 8 minor changes * Session3 Answers added * Session4 code Rebasing * Session 4 Minor Corrections * Session5 minor Changes
- Loading branch information
Showing
42 changed files
with
299 additions
and
2,675 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package school; | ||
|
||
public class Driver{ | ||
public static void main(String ar[]){ | ||
School sc1 = new School("School ABC", "Colombo Road, Kandy", 5); | ||
sc1.addStudent("Student 1", 16, 3.2); | ||
sc1.addStudent("Student 2", 18, 3.8); | ||
sc1.addStudent("Student 3", 16, 2.7); | ||
|
||
sc1.display(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package school; | ||
|
||
import student.Student; | ||
|
||
public class School{ | ||
private String sName; | ||
private String address; | ||
private Student students []; | ||
|
||
public School(String sn, String ad, int scount){ | ||
this.sName = sn; | ||
this.address = ad; | ||
this.students = new Student[scount]; | ||
} | ||
|
||
public void setName(String name){ | ||
this.sName = name; | ||
} | ||
|
||
public String getName(){ | ||
return this.sName; | ||
} | ||
|
||
public void setAddress(String addr){ | ||
this.address = addr; | ||
} | ||
|
||
public String getAddress(){ | ||
return this.address; | ||
} | ||
|
||
public void addStudent(String name, int age, double gpa){ | ||
for(int i =0; i< students.length; i++){ | ||
if(i == students.length-1 && students[i] != null){ | ||
System.out.println("Students full"); | ||
break; | ||
} | ||
if(students[i] == null){ | ||
students[i] = new Student(name, age, gpa); | ||
break; | ||
} | ||
} | ||
} | ||
|
||
public void display(){ | ||
System.out.println("School Name: " + this.sName + "\nAddress: " + this.address + "\nStudent Details: "); | ||
for(Student s : students){ | ||
if(s != null){ | ||
s.display(); | ||
} | ||
System.out.println(""); | ||
} | ||
if(students[0] != null) | ||
System.out.println("Average GPA: " + students[0].calAverage(students)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package student; | ||
|
||
public class Student{ | ||
private String name; | ||
private int age; | ||
private double gpa; | ||
|
||
public Student(String n, int a, double g){ | ||
this.name = n; | ||
this.age = a; | ||
this.gpa = g; | ||
} | ||
|
||
public void setName(String nme){ | ||
this.name = nme; | ||
} | ||
|
||
public String getName(){ | ||
return this.name; | ||
} | ||
|
||
public void setAge(int ag){ | ||
this.age = ag; | ||
} | ||
|
||
public int getAge(){ | ||
return this.age; | ||
} | ||
|
||
public void setGPA(double gp){ | ||
this.gpa = gp; | ||
} | ||
|
||
public double getGPA(){ | ||
return this.gpa; | ||
} | ||
|
||
public double calAverage(Student s []){ | ||
double avg = 0.0; | ||
|
||
for (Student stu : s){ | ||
if(stu != null) | ||
avg += stu.getGPA(); | ||
} | ||
return avg/s.length; | ||
|
||
} | ||
|
||
public void display(){ | ||
System.out.println("Name: " + this.name + "\nAge: " + this.age + "\ngpa: " + this.gpa); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package Individual; | ||
|
||
import Individual.matrix.Matrix; | ||
|
||
public class Main | ||
{ | ||
public static void main(String[] args) | ||
{ | ||
Matrix m1 = new Matrix(2, 3); | ||
m1.init_matrix(); | ||
m1.print(); | ||
System.out.println("-----------------------------------------------"); | ||
|
||
Matrix m2 = new Matrix(2, 3); | ||
m2.init_matrix(); | ||
m2.print(); | ||
System.out.println("-----------------------------------------------"); | ||
|
||
Matrix m3 = new Matrix(1, 2); | ||
m3.init_matrix(); | ||
m3.print(); | ||
System.out.println("-----------------------------------------------"); | ||
|
||
System.out.println("m1 + m2: "); | ||
m1.add_matrix(m2); | ||
System.out.println("-----------------------------------------------"); | ||
|
||
System.out.println("m1 + m3: "); | ||
m1.add_matrix(m3); | ||
System.out.println("-----------------------------------------------"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package Individual.matrix; | ||
|
||
import java.util.Arrays; | ||
import java.util.Scanner; | ||
|
||
/** | ||
* The Matrix class represents a matrix using a 2D Java array. | ||
* | ||
* A Matrix object will have set dimensions defined at creation time. | ||
*/ | ||
public class Matrix | ||
{ | ||
double[][] matrix; | ||
Scanner scanner = new Scanner(System.in); // Not required in the assignment, but will be used to test the program. | ||
|
||
/** | ||
* The constructor method. | ||
* | ||
* Creates a Matrix object containing an array of the specified dimensions | ||
* @param m Number of rows of the matrix. | ||
* @param n Number of columns of the matrix. | ||
*/ | ||
public Matrix(int m, int n) | ||
{ | ||
this.matrix = new double[m][n]; | ||
} | ||
|
||
/** | ||
* Method to print out the Matrix. | ||
*/ | ||
public void print() | ||
{ | ||
// We will be using two nested loops to access each element of the 2D array. The first loop iterates through | ||
// rows, while the second loop iterates through the columns. "matrix.length" yields the number of rows and | ||
// "matrix[i].length" yields the number of columns in row i. | ||
for (int i = 0; i < this.matrix.length; i++) | ||
{ | ||
for (int j = 0; j < this.matrix[i].length; j++) | ||
{ | ||
System.out.print(this.matrix[i][j] + " "); // Note the use of the print method instead of the println | ||
// method. | ||
} | ||
System.out.println(); // Print a new line at the end of each row. | ||
} | ||
} | ||
|
||
/** | ||
* Method to get the dimensions of the matrix of the Matrix object. | ||
* @return Integer array containing the dimensions of the matrix. | ||
*/ | ||
public int[] get_dimensions() | ||
{ | ||
int[] dims = new int[2]; | ||
dims[0] = this.matrix.length; | ||
dims[1] = this.matrix[0].length; | ||
|
||
return dims; | ||
} | ||
|
||
/** | ||
* Method to add another matrix to the current matrix. | ||
* @param m2 The Matrix to be added to the current matrix. | ||
*/ | ||
public void add_matrix(Matrix m2) | ||
{ | ||
// Checking whether the dimensions allow matrix addition. | ||
if (Arrays.equals(this.get_dimensions(), m2.get_dimensions())) // Arrays.equals() checks the equality of arrays | ||
{ | ||
for (int i = 0; i < this.matrix.length; i++) | ||
{ | ||
for (int j = 0; j < this.matrix[i].length; j++) | ||
{ | ||
this.matrix[i][j] += m2.matrix[i][j]; | ||
} | ||
} | ||
this.print(); | ||
} | ||
else | ||
{ | ||
System.out.println("Matrix dimensions do not match."); | ||
} | ||
} | ||
|
||
/** | ||
* Method to initialize values for the matrix. | ||
* | ||
* Not required for the assignment, but will be used to test the program. | ||
*/ | ||
public void init_matrix() | ||
{ | ||
for (int i = 0; i < this.matrix.length; i++) | ||
{ | ||
for (int j = 0; j < this.matrix[i].length; j++) | ||
{ | ||
System.out.println("Enter value for (" + i + ", " + j + "): "); | ||
this.matrix[i][j] = scanner.nextInt(); | ||
} | ||
} | ||
} | ||
} |
2 changes: 0 additions & 2 deletions
2
...asswordApp/src/lk/ac/pdn/AccessLevel.java → Session4/AccessLevel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
package lk.ac.pdn; | ||
|
||
public enum AccessLevel{ | ||
FULL_ACCESS("***"), | ||
LIMITED_ACCESS("**"), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
public class Main{ | ||
|
||
public void validateRegNo(String regNo) { | ||
if(regNo.length()==8 && (regNo.charAt(0)=='S' || regNo.charAt(0)=='s') && (regNo.charAt(1)=='/') && (regNo.charAt(4)=='/') && Character.isDigit(regNo.charAt(2)) && Character.isDigit(regNo.charAt(3)) && Character.isDigit(regNo.charAt(5)) && Character.isDigit(regNo.charAt(6)) && Character.isDigit(regNo.charAt(7))){ | ||
System.out.println("Valid RegNo"); | ||
} | ||
else { | ||
System.out.println("Invalid RegNo"); | ||
} | ||
} | ||
|
||
public static void main(String[] args) | ||
{ | ||
|
||
final String accessLevel= AccessLevel.FULL_ACCESS.symbol; | ||
AccessLevel.checkAccess(accessLevel); | ||
//AccessLevel.checkAccess(s); | ||
Personnel p1 = new Personnel(); | ||
|
||
if (p1.validateLogin()) | ||
System.out.println("Success"); | ||
else | ||
System.out.println("Failed"); | ||
|
||
|
||
} | ||
|
||
} |
2 changes: 0 additions & 2 deletions
2
...mPasswordApp/src/lk/ac/pdn/Personnel.java → Session4/Personnel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,3 @@ | ||
package lk.ac.pdn; | ||
|
||
import java.security.SecureRandom; | ||
import java.util.Arrays; | ||
import java.util.Scanner; | ||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.