diff --git a/README.md b/README.md index 7e8137c..701c61e 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,9 @@ import java.util.Scanner; ```
+### H_03_Inheritance in Java +![Img](https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSyk64iUqsy8WjEdDJF-wW_f35s6YYJYfP8bg&s) + ## Message to Contributing Contributions are always welcome! Whether you want to add new problems, improve solutions, or enhance documentation, feel free to create a pull request. Also please make sure to update the tests as appropriate. diff --git a/src/A_01_Primitive_Data_Types.java b/src/A_01_Primitive_Data_Types.java deleted file mode 100644 index 0e0f0e8..0000000 --- a/src/A_01_Primitive_Data_Types.java +++ /dev/null @@ -1,36 +0,0 @@ -public class A_01_Primitive_Data_Types { - public static void main(String[] args) { - // In front of every datatypes there must be a Variable (e.g: int x = 1, where x is the Variable) - // Integers - System.out.println("Integers"); - byte b = 10; - short s = 20; - int i = -30; - long l = 1000; - System.out.println(b); - System.out.println(s); - System.out.println(i); - System.out.println(l); - - // Floating Point - System.out.println("Floating Point"); - float f = 10.54f; - double d = 20.12; - System.out.println(f); - System.out.println(d); - System.out.println(f+d); - - // Character - System.out.println("Characters"); - char ch = 'A'; - System.out.println(ch); - - // Boolean - System.out.println("Boolean"); - boolean bool = true; - boolean flag = false; - System.out.println(bool); - System.out.println(flag); - - } -} \ No newline at end of file diff --git a/src/A_02_Identifiers_Variable_Rules.java b/src/A_02_Identifiers_Variable_Rules.java deleted file mode 100644 index e5ff412..0000000 --- a/src/A_02_Identifiers_Variable_Rules.java +++ /dev/null @@ -1,34 +0,0 @@ -public class A_02_Identifiers_Variable_Rules { - public static void main(String[] args) { - // keyboard tip: Alt + z = To view all the contents - // keyboard tip: Ctrl + / = Comment a line - - // Rules: - // 1) Variable Names can contain letters, digits, underscores, and dollar signs - // 2) Variable Names must begin with a letter, $ or _ (doesn't matter Uppercase or Lowercase) - // 3) Variable Names best practice should start with lowercase letter, and cannot contain whitespace - // 4) Variable Names are case-sensitive (e.g: "Name" and "name" are different variables) - // 5) Reserved words like Java keywords (e.g: int, boolean, char) cannot be used as Variable Names. - - int a_1$ = 10; - int A_1$ = 10; - - // as you can see there is an error as it has a white spacing in between. -// int a_ 3$ = 10; - - System.out.println(a_1$); - System.out.println(A_1$); - - // this file will not run as there is an error -// System.out.println(a_ 3$); - - // similarly there will be an error cause you cannot use reserved words as Variable Names. -// String int = 'Hello World!' -// int String = 10; - - // however, why does it work for this? It's cause the string is not a data type keyword *String* is not string. Hence, it why Java is case sensitive. - int string = 10; - System.out.println(string); - - } -} diff --git a/src/A_03_Type_Casting.java b/src/A_03_Type_Casting.java deleted file mode 100644 index 39b33d2..0000000 --- a/src/A_03_Type_Casting.java +++ /dev/null @@ -1,21 +0,0 @@ -public class A_03_Type_Casting { - // Implicit Type Casting (automatic by compiler) - // byte -> short -> char -> int -> long -> float -> double - - // Explicit Type Casting - // double -> float -> long -> int -> char -> short -> byte - - public static void main(String[] args) { - // Implicit - int number1 = 10; - double number2 = number1; - - System.out.println(number2); - - // Explicit - double num1 = 20.44; - int num2 = (int)num1; - - System.out.print(num2); - } -} diff --git a/src/A_04_Arithmetic_Operators.java b/src/A_04_Arithmetic_Operators.java deleted file mode 100644 index 5d0d51a..0000000 --- a/src/A_04_Arithmetic_Operators.java +++ /dev/null @@ -1,28 +0,0 @@ -public class A_04_Arithmetic_Operators { - public static void main(String[] args) { - // using the '+' operator you can join 2 Variable string together as shown below - String msg1 = "Hello World!"; - String msg2 = "My name is Ang Jianming."; - - System.out.println(msg1 + " " + msg2); - - // Arithmetic Operator (+, -, *, /, %) - int a = 10; - int b = 20; - - int c = a + b; // Addition - System.out.println(c); - - int d = a - b; // Subtraction - System.out.println(d); - - int e = a * b; // Multiply - System.out.println(e); - - int f = b / a; // Divide - System.out.println(f); - - int g = a % b; // Modulus - System.out.println(g); - } -} diff --git a/src/A_05_User_Input.java b/src/A_05_User_Input.java deleted file mode 100644 index daccbc3..0000000 --- a/src/A_05_User_Input.java +++ /dev/null @@ -1,51 +0,0 @@ -/* -* Author AngJianming -* -*/ - -// it is a must to import java.util.Scanner; to access some external files which has the functionality to read input from the console. In Java this is the way to get certain functionalities which is not build in therefore, needing to import them. - -import java.util.Scanner; - -public class A_05_User_Input { - public static void main(String[] args) { - Scanner user_input = new Scanner(System.in); - System.out.print("Enter your name: "); - - String name = user_input.nextLine(); - System.out.println("My name is " + name); - - - // Example Calculator - Scanner scanner = new Scanner(System.in); - - // Prompt the user to enter the first number - System.out.print("Enter the first integer: "); - int x = scanner.nextInt(); - - // Prompt the user to enter the second number - System.out.print("Enter the second integer: "); - int y = scanner.nextInt(); - - // Perform arithmetic operations - int sum = x + y; // Addition - int difference = x - y; // Subtraction - int product = x * y; // Multiplication - - // To handle division by zero, you can check if b == 0 - // but for simplicity, we assume b != 0 in this example - double quotient = (double) x / y; // Division - int modulus = x % y; // Modulus (remainder) - - // Print the results - System.out.println("\n--- Results ---"); - System.out.println(x + " + " + y + " = " + sum); - System.out.println(x + " - " + y + " = " + difference); - System.out.println(x + " × " + y + " = " + product); - System.out.println(x + " ÷ " + y + " = " + quotient); - System.out.println(x + " % " + y + " = " +"R"+ modulus); - - // Close the scanner - scanner.close(); - } -} diff --git a/src/B_01_Assignment_Operators.java b/src/B_01_Assignment_Operators.java deleted file mode 100644 index a33eb7c..0000000 --- a/src/B_01_Assignment_Operators.java +++ /dev/null @@ -1,24 +0,0 @@ -public class B_01_Assignment_Operators { - public static void main(String[] args) { - // Assignment Operators (=, +=, -=, /=, *=) - - int a = 10; - int b = 5; - - a += b; // meaning a = a+b or a = 10+b - System.out.println(a); - // a = 15 this should be the expected result - - a -= 2; // meaning a = a-2; - System.out.println(a); - - a /= 2; // meaning a = a/2 - System.out.println(a); - - a *= 2; // meaning a = a*2 - System.out.println(a); - - a %= 5; // meaning a = a%5 - System.out.println(a); - } -} diff --git a/src/B_02_Relational_Operators.java b/src/B_02_Relational_Operators.java deleted file mode 100644 index 6cf6b6f..0000000 --- a/src/B_02_Relational_Operators.java +++ /dev/null @@ -1,28 +0,0 @@ -public class B_02_Relational_Operators { - // ture, false (boolean) - // Relational Operators ( ==, !=, <, >, <=, >=) - - public static void main(String[] args) { - int a = 10; - int b = 15; - - System.out.println(a == b); // if a is equal to b true, otherwise false - System.out.println(a != b); // 10 is not equal to 15 true, otherwise false - System.out.println(a < b); // 10 is less than 15 true, otherwise false - System.out.println(b > a); // 10 is more than 15 true, otherwise false - - System.out.println(a <= b); // 10 is less or equal to 15 true, otherwise false - - System.out.println(b >= a); // 10 is more than or equal to 15 true, otherwise false - -// 10 is less than, or equal to 10 true, otherwise false. - System.out.println(10 < 10); // is false because it cannot 10 cannot be less than 10 - System.out.println(10 <= 10); // is true because it can be less than or EQUAL to 10 (Keyword 'equal') - - System.out.println(10 > 10); // is false because it cannot 10 cannot be more than 10 - System.out.println(10 >= 10); // is true because it can be more than or EQUAL to 10 (Keyword 'equal') - - - - } -} diff --git a/src/B_03_Logical_Operators.java b/src/B_03_Logical_Operators.java deleted file mode 100644 index fc423ef..0000000 --- a/src/B_03_Logical_Operators.java +++ /dev/null @@ -1,49 +0,0 @@ -import java.security.spec.RSAOtherPrimeInfo; - -public class B_03_Logical_Operators { - public static void main(String[] args) { - // Logical Operator ( &&, ||, !) - - - // AND (&&) - is all condition is true then return true. -// true && true = true -// true && false = false -// false && true = false -// false && false = false - System.out.println(10>5); - System.out.println(20>14); - System.out.println((10>5) && (20>14)); - - - // OR (||) - if any condition is true, then return true. -// true || true = true -// true || false = true -// false || true = true -// false || false = false - System.out.println((10>5) || (20<14)); - System.out.println((10<5) || (20<14) || (10<2) || (1000<999) || (1<0)); - // false, false, false, false, true. Hence, it's true still. - - System.out.println((10<5) || (20<14) || (10<2) || (1000<999) || true); - // If at the end is true then all is true. - - System.out.println((10<5) || (20<14) || (10<2) || (1000<999) || false); - // If at the end is all is false then false. - - - // NOT(!) - vice-versa -// true = false -// false = true - - System.out.println(!(100>99)); // Not true. Therefore, false - - System.out.println(!(100>99) && (2>0)); - // !true AND true = false - - System.out.println(!(20>20) || !(10<=20)); - // !false OR !true = true - - - - } -}