Skip to content

Commit

Permalink
Section 2 Added
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohaned Yossry Abdulaziz committed Nov 2, 2020
1 parent 95cde44 commit 838c93f
Show file tree
Hide file tree
Showing 10 changed files with 261 additions and 0 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,32 @@ This repository will contain all materials used throughout the OS course 20/21
[Switch](https://www.w3schools.com/java/java_switch.asp)


### 📖 Section 2 - Methods, Loops and more.
-------
[🎞 Section Presentation](https://drive.google.com/file/d/1D_Kw3wwqueCrFKgalFBcLgvomxcvn8rr/view?usp=sharing)

[‍💻 Section Project](https://www.geeksforgeeks.org/loops-in-java/)

[Increment and Decrement operators in Java](https://www.geeksforgeeks.org/interesting-facts-increment-decrement-operators-java/)

[Type Casting](https://www.w3schools.com/java/java_type_casting.asp)

[User Input (Scanner)](https://www.w3schools.com/java/java_user_input.asp)

[Methods](https://www.w3schools.com/java/java_methods.asp)

[Method Parameters](https://www.w3schools.com/java/java_methods_param.asp)

[Method Overloading](https://www.w3schools.com/java/java_methods_overloading.asp)

[Method Scope](https://www.w3schools.com/java/java_scope.asp)

[Naming Conventions](https://www.geeksforgeeks.org/java-naming-conventions/)

[Loops in Java](https://www.geeksforgeeks.org/loops-in-java/)



## 🍕 Additional Links

<details>
Expand Down
8 changes: 8 additions & 0 deletions Section2-Project/.idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Section2-Project/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Section2-Project/.idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions Section2-Project/.idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Section2-Project/.idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions Section2-Project/Section2Project.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
Binary file not shown.
Binary file not shown.
72 changes: 72 additions & 0 deletions Section2-Project/src/Section2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import java.util.Scanner;

public class Section2 {
//Class Scope
// Can be accessed in any method inside this class
public static int myInteger = 15;

public static void main(String[] args) {

// How to define constant (Final Variable)
final double PI = 3.145;

}

// This game will show to the user two numbers and will loop till the user enter the correct answer
public static void sumGame() {
int num1 = (int) (Math.random() * 10);
int num2 = (int) (Math.random() * 10);
System.out.println(num1 + " + " + num2 + " = ");
// To take input from user we have to define the scanner object
Scanner scanner = new Scanner(System.in);
// After defining the object we can us it like this to take input from user in Integer type
int result = scanner.nextInt();
while ((num1 + num2) != result) {
System.out.println("Try again");
result = scanner.nextInt();
}
System.out.println("Correct Answer");
}

public static void testLoop() {
// While loop
int i = 0; // Control Variable
while (i < 100) { // Condition
System.out.println(i + " Hello Java");
i++; //Control Variable Adjustment
}
// Do While loop
// int i = 0;
// do {
// System.out.println(i + " Hello Java");
// i++;
// }while (i < 100);

// For Loop
// for(int i = 0;i<100;i++)
// System.out.println(i + " Hello Java");
}

//The variable inside this method can only be accessed inside it's curly braces
public static void scopeTest() {

int myInteger = 15;
}

//Method Overloading With 2 Integer Parameter Example
public static int getMax(int num1, int num2) {
System.out.println("inside int parameter method");
if (num1 > num2)
return num1;
return num2;
}

//Method Overloading With 2 Double Parameter Example
// Changing return type will have no effect on the overloading
public static int getMax(double num1, double num2) {
System.out.println("inside double parameter method");
if (num1 > num2)
return (int) num1; //This is example of Explicit Casting from double (Large Data Type) => int (Smaller Data Type)
return (int) num2;
}
}

0 comments on commit 838c93f

Please sign in to comment.