Skip to content

Commit

Permalink
Adding all examples
Browse files Browse the repository at this point in the history
  • Loading branch information
NiiSV811 committed Oct 12, 2022
1 parent 671cd32 commit 85a41aa
Show file tree
Hide file tree
Showing 17 changed files with 451 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Java Essentials/src/essentials/Operators/ArithmeticOperators.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package essentials.Operators;

public class ArithmeticOperators {
public static void main(String[] args) {

// Addition [ + ]
int aIntegerSum = 10 + 5; //15
double aDecimalSum = 14.5 + 2.3; //16.8

// Subtraction [ - ]
int aIntegerSub = 50 - 15; //35
double aDecimalSub = 10.2 - 3.6; //6.6

// Multiply [ * ]
int aSimplyMulti = 10 * 2; //20
double aComplexMulti = 100.6 * 294.7; //29646.819999999996

// Division [ / ]
double aNormalDivision = 20.23 / 5.86; // 3.4522184300341294

// Remainder [ % ]
int aDivisionRemainder = 10 % 3; // 1
// 3 * 3 = 9 + 1 = 10
}
}
39 changes: 39 additions & 0 deletions Java Essentials/src/essentials/Operators/Assignment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package essentials.Operators;

public class Assignment {
public static void main(String[] args) {

// Assignment [ = ]
double gravityValue = 9.8;

// variable = variable + something
String vowels = "aei";
vowels += "ou";

// Increase a number variable
int counter = 0;
counter++;
// Now, counter is 1

// variable = variable - something
int decreaseCounter = 10;
decreaseCounter -= 2;
//Now decreaseCounter is 8

// variable = variable * something
int multiplyCounter = 2;
multiplyCounter *= 4;
// Now multiplyCounter is 8;

// variable = variable / something
int divCounter = 20;
divCounter /= 5;
// divCounter now is 4

//variable = variable % something
int remainderCounter = 10;
remainderCounter %= 3;
//Now remainderCounter is 1

}
}
18 changes: 18 additions & 0 deletions Java Essentials/src/essentials/Operators/LogicalOperators.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package essentials.Operators;

public class LogicalOperators {
public static void main(String[] args) {

//Not [ ! ]
boolean negation = !true; //false

//AND [ && ]
boolean logicalAnd = true && true; //true

//OR [ || ]
boolean logicalOR = false || false; //false


}

}
24 changes: 24 additions & 0 deletions Java Essentials/src/essentials/Operators/comparisonOperators.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package essentials.Operators;

public class comparisonOperators {
public static void main(String[] args) {

// Equal to [ == ]
boolean isEqualTo = 10 == 10; //true

// Different to [ != ]
boolean isDifferentTo = 2 != 2; //false

// Greater than [ > ]
boolean greaterThan = 24 > 12; //true

// Less than [ < ]
boolean lessThan = 10 < -29; //false

//Greater than or equal to [ >= ]
boolean GreatThanOrEqual = 56 >= 20; //true

// Less than or equal to [ >= ]
boolean LessThanEqual = 10 <= 9; // false
}
}
29 changes: 29 additions & 0 deletions Java Essentials/src/essentials/arrays/ArraysBasics.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package essentials.arrays;

public class ArraysBasics {
public static void main(String[] args) {

//creating arrays

//creating with elements
char [] myCharArray = new char[]{'a', 'b', 'c'};

//creating void array
int [] myNumberArray = new int[4];

// Filling out my Number array

for (int i = 0; i < myNumberArray.length; i++){
myNumberArray[i] = 1;
}

// Printing my Number array
for (int i = 0; i < myNumberArray.length; i++){
System.out.println(myNumberArray[i]);
}

// Editing my char array
myCharArray[1] = 'v';
// [ 'a' , 'v', 'c']
}
}
31 changes: 31 additions & 0 deletions Java Essentials/src/essentials/basic/DataTypes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package essentials.basic;

public class DataTypes {
public static void main(String[] args) {

//Integers -> whole numbers
byte myByte = 8; // store maximum 8 bits
short aLittleNum = 16; // Store maximum 16 bits
int aSimpleInt = 32; // Store maximum 32 bits
long aLooongNumber = 64; // Store maximum 64 bits

//Floating Point numbers -> Decimal numbers

float myMathGrade = 4.5f; //Store 32 bits, at the end put [ f ]
double pi = 3.141596; //Store 64 bits

//Boolean
boolean isLeapYear = false; //Store a truth value: true or false
boolean is2022Year = true;

//Char
char aSingleCharacter = 'a'; //Store a single character[ letters, symbols, numbers]
char aCharNumber = '3'; // Uses single quote
char aSymbol = '#';

//String
String favoriteFood = "pizza"; //It is a character collection
String safetyPassword = "P@ssword4321"; // Uses double quotes

}
}
8 changes: 8 additions & 0 deletions Java Essentials/src/essentials/basic/FirstHelloWorld.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package essentials.basic; //The name of the package

public class FirstHelloWorld {
public static void main(String[] args) { // Java runs the main function
System.out.println("Hello World"); // this line allow to show a console output
// All code lines end with semicolon [ ; ]
}
}
38 changes: 38 additions & 0 deletions Java Essentials/src/essentials/basic/Input.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package essentials.basic;

import javax.swing.*; //Import JOption Pane

public class Input {
public static void main(String[] args) {
//Method 1: Using JOption Pane this is a library
//Exists other methods... You can search for others

String nameInput; //Create a var to store the input
//JOption Pane store Strings

nameInput = JOptionPane.showInputDialog("What's your Name");

//Output using JOP
JOptionPane.showMessageDialog(null, "Hi " + nameInput );

//Console output
System.out.println("Hi " + nameInput);

//If you want to store a number, you can cast

String booksNumber;
String calculusGrade;

booksNumber = JOptionPane.showInputDialog("How many books you have?");
calculusGrade = JOptionPane.showInputDialog("What is your calculus grade?");

int numberOfBooks = Integer.parseInt(booksNumber);
double gradeOfCalculus = Double.parseDouble(calculusGrade);

//Now you can operate your inputs




}
}
31 changes: 31 additions & 0 deletions Java Essentials/src/essentials/conditionals/IfStatement.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package essentials.conditionals;

public class IfStatement {
public static void main(String[] args) {

// Simple Condition IF
if ( 10 < 20){
//This executes because 10 is less than 20
}

// IF-ELSE
if ("Hola" != "Hola"){
//Don't Execute
}else {
//Execute
}

// IF ELSE-IF
int age = 10;

if (age > 10){
//Don't Execute
} else if (age<=10 && age >5) {
//Execute
} else if (age <= 5 ) {
//Don't Execute
}else {
//Don't Execute
}
}
}
28 changes: 28 additions & 0 deletions Java Essentials/src/essentials/conditionals/SwitchCase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package essentials.conditionals;

public class SwitchCase {
public static void main(String[] args) {

//Switch Case
int optionMenu = 0;

switch (optionMenu){
case 1:
// Do something if optionMenu is 1
break;
case 2:
// Do something if optionMenu is 2
break;
case 5:
// Do something if optionMenu is 5
break;
default:
// Do something if optionMenu is different to the
// previous cases
}

// Switch needs break; in its cases to exit
// If you don't use break, switch execute the following cases

}
}
22 changes: 22 additions & 0 deletions Java Essentials/src/essentials/loops/ForLoop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package essentials.loops;

public class ForLoop {
public static void main(String[] args) {

//For Loop
int timesToRun = 10;

//for ( a ; b ; c)
// a -> it runs once, uses for define a counter
// b -> this is the condition to execute the for loop
// c -> this run at the end of each iteration, uses to increment

for (int i = 0; i < timesToRun; i++){
// Code to execute 10 times
}

// you can name the counter as you want, name i for iteration
// But there's no problem to give another name.

}
}
15 changes: 15 additions & 0 deletions Java Essentials/src/essentials/loops/WhileLoop.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package essentials.loops;

public class WhileLoop {
public static void main(String[] args) {

//While Loop
int iterator = 10;
while ( iterator > 4){
// Code to execute

iterator--; //When use While, don't forget to change the variable
// If you don't update variable, you could fall in an infinite loop
}
}
}
20 changes: 20 additions & 0 deletions Java Essentials/src/essentials/matrices/BasicMatrix.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package essentials.matrices;

public class BasicMatrix {
public static void main(String[] args) {
//create matrices
boolean [][] theTruthMatrix = new boolean[2][2];

String [][] wordMatrix = new String[][]{{"Hey", "How"}, {"It's", "Going"}};

//Iterate on Matrices
for (int y = 0; y < wordMatrix.length; y++){ // x is an Array
for(int x = 0; x < wordMatrix[y].length; x++){ //We can iterate x because is an array
theTruthMatrix[y][x] = true;
System.out.println(wordMatrix[y][x]);
}
}


}
}
51 changes: 51 additions & 0 deletions Java Essentials/src/essentials/oop/catclass/Cat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package essentials.oop.catclass;

public class Cat {
//Define Attributes
private String catName;
private double catWeightKg;
private String furColor;
private boolean isVaccinated;

//Define methods

//builder
public Cat(String catName, double catWeightKg, String furColor, boolean isVaccinated){
//set attributes to build a neeko jsjsj
this.catName = catName;
this.catWeightKg = catWeightKg;
this.furColor = furColor;
this.isVaccinated = isVaccinated;

System.out.println(" Meow Meow ");
}

public void setCatName( String catName){
this.catName = catName;
}

public void setCatWeight( double catWeightKg){
this.catWeightKg = catWeightKg;
}

public void setFurColor(String furColor){
this.furColor = furColor;
}

public void setIsVaccinated(boolean isVaccinated){
this.isVaccinated = isVaccinated;
}

public void jump(){
System.out.println("* Cat jumps *");
}

public void eat(){
System.out.println(" * yummi sounds *");
}

public void sleep(){
System.out.println(" * cat goes to sleep * ");
}

}
Loading

0 comments on commit 85a41aa

Please sign in to comment.