Skip to content

Commit bd8a7dd

Browse files
authored
Merge pull request #16 from SahanPunchihewa/main
Other Assignment
2 parents 9cd44ca + 307961e commit bd8a7dd

File tree

31 files changed

+689
-0
lines changed

31 files changed

+689
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
interface A{ // Inteface class A
2+
3+
void meth1(); // meth 1
4+
void meth2(); // meth 2
5+
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
public class MyClass implements A { // MyClass class implements A class
2+
3+
public void meth1(int meth1){ // meth 1
4+
5+
6+
7+
}
8+
9+
public void meth2(int meth2){ // meth 2
10+
11+
12+
13+
}
14+
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
public class InheritanceDemo { // Begining of the Class
3+
4+
public static void main(String[] args) { // Begining of the Method
5+
6+
Person p1 = new Person();
7+
p1.showDetails(); // Default Constructor Called
8+
System.out.println("");
9+
10+
Student s1 = new Student("Sahan", "Colombo", "IT2011470");
11+
s1.showDetails();
12+
System.out.println("");
13+
14+
PartTimeStudent pts = new PartTimeStudent("Kamal", "Kurunagala", "IT01117",6);
15+
pts.showDetails();
16+
17+
} // End of the Method
18+
19+
} // End of the Class
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public class PartTimeStudent extends Student{
2+
3+
private int workHours;
4+
5+
public PartTimeStudent(String name, String Address, String StudentID, int workHours) {
6+
7+
super(name, Address, StudentID);
8+
this.workHours = workHours;
9+
}
10+
11+
public void showDetails() {
12+
13+
super.showDetails();
14+
System.out.println("Working Hours :" +this.workHours);
15+
16+
}
17+
18+
19+
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
public class Person {
3+
4+
private String name;
5+
private String Address;
6+
7+
public Person() {
8+
9+
name = null;
10+
Address = null;
11+
}
12+
13+
public Person(String name, String Address) {
14+
15+
this.name = name;
16+
this.Address = Address;
17+
}
18+
19+
public void showDetails() {
20+
21+
System.out.println("Name :" +this.name);
22+
System.out.println("Address :" +this.Address);
23+
24+
}
25+
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public class Student extends Person {
2+
3+
private String StudentID;
4+
5+
public Student(String name, String Address, String StudentID) {
6+
7+
super(name,Address);
8+
this.StudentID = StudentID;
9+
}
10+
11+
public void showDetails() {
12+
13+
super.showDetails();
14+
System.out.println("Student ID :" +this.StudentID);
15+
16+
}
17+
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
public class Arithmetic implements Test { // Arithmetic class
2+
3+
public void Square(int x) { // Square method
4+
5+
6+
7+
}
8+
9+
10+
11+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
interface Test{ // implement test class
2+
3+
void Square(); // Square method
4+
5+
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
public class TestInt{ // Test Int class
2+
3+
public static void main(String[] args) { // main method
4+
5+
Arithmetic arithmetic = new Arithmetic(); // object of Arithmetic class
6+
7+
arithmetic.Square();
8+
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class Main{ // Main Class
2+
3+
public static void main(String args[]) { // method
4+
try { // try catch block
5+
6+
int c[] = {1};
7+
c[42] = 99;
8+
9+
} catch (ArrayIndexOutOfBoundsException e) { // exception
10+
System.out.println("Array index oob: " + e);
11+
}
12+
}
13+
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
public class MutipleCatch {
2+
3+
public static void main(String args[]) {
4+
5+
try{
6+
7+
// int a = args.length;
8+
// System.out.println("a = " +a);
9+
// int b =42 /a;
10+
int c[] = {1};
11+
c[42] = 99;
12+
13+
} catch (ArithmeticException e3) {
14+
15+
System.out.println("Divide by 0 :" +e);
16+
}catch (ArrayIndexOutOfBoundsException ex) {
17+
18+
System.out.println("Array index oob :" +ex);
19+
}
20+
21+
22+
System.out.println("After try/ catch block");
23+
}
24+
25+
26+
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
public class Main { // Beiginng of the Main Class
2+
public static void main(String[] args) { // Beiginng of the method
3+
4+
try { // try catch block
5+
6+
String number = "123a";
7+
int value = Integer.parseInt(number); // Type Casting
8+
9+
} catch (NumberFormatException ex) { // Exception
10+
11+
System.out.println("Wrong number format"); // Display Exception
12+
}
13+
} // End of the method
14+
} // End of the Main Class
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
class TestFinallyBlock{ // Test Finally Class
2+
public static void main(String args[]){ // Method
3+
4+
try{ // Try Catch block
5+
6+
int data=25/0;
7+
8+
System.out.println(data);
9+
10+
} catch(ArithmeticException e){ // Exception
11+
12+
System.out.println(e); // Print Excpetion
13+
14+
} finally{ // Final block
15+
16+
System.out.println("finally block is always executed"); // display finally block execution
17+
18+
}
19+
20+
System.out.println("rest of the code...");
21+
}
22+
23+
}
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import java.io.*;
2+
3+
public class Demo {
4+
5+
public static void main(String[] args) throws IOException {
6+
7+
int number;
8+
9+
EvenOddNumber eon = new EvenOddNumber();
10+
11+
// boolean result = eon.findEvenOrOdd(8);
12+
13+
InputStreamReader isr = new InputStreamReader(System.in);
14+
15+
BufferedReader bf = new BufferedReader(isr);
16+
17+
System.out.print("Enter the number :");
18+
number = Integer.parseInt(bf.readLine());
19+
20+
if (eon.findEvenOrOdd(number)) { // if(result == true)
21+
22+
System.out.print("This is an Even Number");
23+
24+
}
25+
26+
else {
27+
28+
System.out.print("This is an Odd Number");
29+
30+
}
31+
32+
}
33+
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public class SoundException extends Exception { // Sound Exception class
2+
3+
public SoundException(String message) {
4+
super(message);
5+
}
6+
} // End of the Sound exception class
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Question 02
2+
3+
// Write a program that input, calculates and prints the product of three integers
4+
5+
6+
import java.util.Scanner; // Import java Scanner class
7+
8+
9+
public class Main{ // Beginning of the Main class
10+
11+
public static void main(String[] args) { // Beginning of the Method
12+
13+
Scanner scanner = new Scanner(System.in); // Create Object for Scanner Class
14+
15+
System.out.print("Input Number 1 :"); // Input Number 1
16+
int Number1 = scanner.nextInt(); // User Input Number 1
17+
18+
System.out.print("Input Number 2 :"); // Input Number 2
19+
int Number2 = scanner.nextInt(); // User Input Number 2
20+
21+
int sum = Number1 + Number2; // Calculate the Sum of two numbers
22+
23+
System.out.println("Input First Number is :" + Number1); // Display first Number user input
24+
System.out.println("Input Second Number is :" + Number2); // Display second Number user input
25+
System.out.println("Calculate of Two Numbers is : " +sum); // Display Calculate of two Numbers user input
26+
27+
} // End of the Method
28+
29+
}// End of the Main class
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Question 03
2+
3+
// Write a program that converts a Fahrenheit degree to Celsius using the formula (input values)
4+
5+
6+
import java.util.*; // Import Java Scanner Class
7+
8+
public class Main{ // Beginnging of the Main Class
9+
10+
public static void main(String[] args) { // Beginnging of the method
11+
12+
Scanner scanner = new Scanner(System.in); // Creeate object for Scanner Class
13+
14+
// Declare variable fahremheit and celsius
15+
int fahrenheit;
16+
int celsius;
17+
18+
System.out.print("Input Fahrenheit :"); // Input Fahrenheit Values
19+
fahrenheit = scanner.nextInt(); // User Input
20+
21+
celsius = (9/5) * (fahrenheit -32); // Calculation
22+
23+
System.out.print("Celsius :" + celsius); // Display the Converted Celsius Value
24+
25+
} // end of the method
26+
27+
} // end of the Main Class
+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Question 04
2+
3+
// Write an application that inputs three integers from the user and displays the sum, average,
4+
// product, smallest and largest of the numbers.
5+
6+
import java.util.*; // Import java Util class
7+
8+
9+
public class Main{ // Beginning of the Main calss
10+
11+
public static void main(String[] args) { // Beginning of the Method
12+
13+
Scanner scanner = new Scanner(System.in); // Create a object for Scanner Calss
14+
15+
System.out.print("Input Number 1 : "); // Input Number 1
16+
int Number1 = scanner.nextInt(); // User Input Number 1
17+
18+
System.out.print("Input Number 2 : "); // Input Number 2
19+
int Number2 = scanner.nextInt(); // User Input Number 2
20+
21+
System.out.print("Input Number 3 : "); // Input Number 3
22+
int Number3 = scanner.nextInt(); // User Input Number 3
23+
24+
int sum = Number1 + Number2 + Number3; // Calculation of three Integer values
25+
26+
System.out.println("Sum of three Integer Number is : "+sum); // Display the three Integer values
27+
28+
int average = sum / 3; // Calculate the average value three Integer values
29+
30+
System.out.println("Average of three Integer Number is : "+average); // Display the average of three Integer values
31+
32+
if(Number1 > Number2 && Number2 > Number3) { // Check the Condtion
33+
34+
System.out.println("The Largest Number :" + Number1); // Display the Largest Number
35+
System.out.println("The Smallest Number :" + Number3); // Display the Smallest Number
36+
37+
}
38+
39+
else if (Number1 < Number2 && Number2 > Number3) { // Check the Condtion
40+
41+
System.out.println("The Largest Number :" +Number2); // Display the Largest Number
42+
System.out.println("The Smallest Number" + Number3); // Display the Smallest Number
43+
}
44+
else if (Number1< Number2 && Number2 < Number3) { // Check the Condtion
45+
46+
System.out.println("The Largest Number :" + Number3); // Display the Largest Number
47+
System.out.println("The Smallest Number :" +Number1); // Display the Smallest Number
48+
49+
}
50+
51+
} // End of the method
52+
53+
} // End of the Main Class

0 commit comments

Comments
 (0)