diff --git a/Week3/Abstraction/README.md b/Week3/Abstraction/README.md new file mode 100644 index 0000000..42b4eab --- /dev/null +++ b/Week3/Abstraction/README.md @@ -0,0 +1,29 @@ +# Abstraction 🍵 + +### Task 🐧 + - Create an abstract class called Shirt: + - Make an instance variable called color + - Make a constructor that takes a String for the color & sets it to the instance variable + - Make a public method called `getColor()` that returns the name of the color + - Make an empty abstract method called `getDescription()` + + - Create a default class called `T_Shirt` that extends Shirt: + - Make an instance variable called size + - Make an instance variable called price + - Make a constructor that takes in a color, size, price and sets the instance variables (Use super() to call the constructor of Shirt) + - Override the method called `getDescription()` that returns the color, size, and price of the T_Shirt + + - Create another default class called 'Jacket' that extends Shirt: + - Make an instance variable called price + - Make an instance variable called brand + - Make a constructor that takes in a color, and price, and sets the instance variables (Use super() to call the constructor of Shirt) + - Override the method called `getDescription()` that returns the color, brand, and price of the T_Shirt + +### Requirements 🏫 +``` +1. A .java file +2. Prints the color & size of a T_Shirt +3. Prints the color & size of a Jacket +4. Prints the isZip of a Jacket +5. Prints the total price of the items +``` \ No newline at end of file diff --git a/Week3/Arrays/Arrays.java b/Week3/Arrays/Arrays.java new file mode 100644 index 0000000..f7c8f5b --- /dev/null +++ b/Week3/Arrays/Arrays.java @@ -0,0 +1,24 @@ +// # Arrays 🍵 + +// ### Task 🐧 +// Create code that consists of an array with the following elements: +// - An element containing the name of your department +// - An element contianing the name of the oldest person in the world +// - An element contianing the name of the Rapid React world champion alliance captains +// - An element containing the name of the 2019 FRC game + +// - Then print each element, from last to first. + +// ### Requirements 🏫 +// ``` +// 1. A .java file +// 2. Creates an array and prints the elements as specified +// ``` +public class Arrays { + public static void main(String[] args) { + String[] robotics_array = {"software", "Tomiko", "Ferradermis", "Destination: Deep Space"}; + for (int i = 0; i < 4; i++) { + System.out.println(robotics_array[i]); + } + } +} \ No newline at end of file diff --git a/Week3/Arrays/README.txt b/Week3/Arrays/README.txt new file mode 100644 index 0000000..a732edc --- /dev/null +++ b/Week3/Arrays/README.txt @@ -0,0 +1,16 @@ +# Arrays 🍵 + +### Task 🐧 +Create code that consists of an array with the following elements: + - An element containing the name of your department + - An element contianing the name of the oldest person in the world + - An element contianing the name of the Rapid React world champion alliance captains + - An element containing the name of the 2019 FRC game + + - Then print each element, from last to first. + +### Requirements 🏫 +``` +1. A .java file +2. Creates an array and prints the elements as specified +``` diff --git a/Week3/Classes & Objects/Me.java b/Week3/Classes & Objects/Me.java new file mode 100644 index 0000000..4b9bb8f --- /dev/null +++ b/Week3/Classes & Objects/Me.java @@ -0,0 +1,21 @@ +public class Me { + String name; + int age; + + Me(String name, int age){ + this.name = name; + this.age = age; + } + + String getName(){ + return name; + } + + int getAge(){ + return age; + } + public static void main(String[] args) { + Me dhyan = new Me("dhyan", 14); + System.out.println("Name: " + dhyan.getName() + ", Age: " + dhyan.getAge()); + } +} diff --git a/Week3/Classes & Objects/Pokemon.java b/Week3/Classes & Objects/Pokemon.java new file mode 100644 index 0000000..f19d419 --- /dev/null +++ b/Week3/Classes & Objects/Pokemon.java @@ -0,0 +1,23 @@ +public class Pokemon { + String name; + int level; + + Pokemon(){ + level = 1; // default value + } + + Pokemon(String pName, int pLevel){ + name = pName; + level = pLevel; + } + + void attack(){ + System.out.println(name + " attack!"); + } + public static void main(String[] args) { + + Pokemon p1 = new Pokemon("andrew", "0"); + + System.out.println(p1.level); + } +} diff --git a/Week3/Classes & Objects/README.md b/Week3/Classes & Objects/README.md new file mode 100644 index 0000000..7b8465a --- /dev/null +++ b/Week3/Classes & Objects/README.md @@ -0,0 +1,13 @@ +# Classes and Objects 🍵 + +### Task 🐧 + - Create a class called "Me" & intialize variables name and age + - Create parameters for these variables and set them to the variables in the constructor + - Create 2 method that returns your name and age + - Create an object for this class in the main method, & use the method to print! + +### Requirements 🏫 +``` +1. A .java file +2. Prints your name and age from the Me object +``` \ No newline at end of file diff --git a/Week3/Encapsulation/README.md b/Week3/Encapsulation/README.md new file mode 100644 index 0000000..a66d63a --- /dev/null +++ b/Week3/Encapsulation/README.md @@ -0,0 +1,14 @@ +# Encapsulation 🍵 + +### Task 🐧 + - Create a class callsed Information: + - Make private variables for name, age, and gender + - Create getters and setters for each of the private variables + - Create a boolean getter for if they are above the age of 21 + - Create two instances of Information with different names & genders & ages either above or below 21 + +### Requirements 🏫 +``` +1. A .java file +2. Print out if people are above the age of 21 with their name and gender +``` diff --git a/Week3/Inheritance/Child.java b/Week3/Inheritance/Child.java new file mode 100644 index 0000000..d133f4e --- /dev/null +++ b/Week3/Inheritance/Child.java @@ -0,0 +1,43 @@ +// # Inheritance 🍵 + +// ### Task 🐧 +// - Create a class called Parent: +// - Make an instance variable called last_name +// - Make an instace variable called eye color +// - Create a constructor and set all the instace varaiables to the parameters passed in +// - Make a public method called `getLastName()` that returns the last name + +// - Create a class called 'Child' that inherits (extends) Parent: +// - Make an instance variable called first_name +// - Make a constructor that first, sets first_name, and second, calls the constructor of Parent (Make sure to pass in the last name and eye color) +// - Create a method that returns the first and last name in a String +// - Create a method that returns the eye color color of the parent + +// ### Requirements 🏫 +// ``` +// 1. A .java file +// 2. Prints the first and last name of the child +// 3. Prints the eye color of the parent +// ``` +package JavaTraining2024.Week3.Inheritance; + +public class Child extends Parent{ + String first_name; + String last_name; + String eye_color; + + public Child(String first_name, String last_name, String eye_color){ + super(last_name, eye_color); + this.last_name = last_name; + this.first_name = first_name; + this.eye_color = eye_color; + } + + public String getFullName(){ + return first_name + last_name; + } + + String getEyeColor(){ + return eye_color; + } +} \ No newline at end of file diff --git a/Week3/Inheritance/Main.java b/Week3/Inheritance/Main.java new file mode 100644 index 0000000..6ad7a7c --- /dev/null +++ b/Week3/Inheritance/Main.java @@ -0,0 +1,31 @@ + +// # Inheritance 🍵 + +// ### Task 🐧 +// - Create a class called Parent: +// - Make an instance variable called last_name +// - Make an instace variable called eye color +// - Create a constructor and set all the instace varaiables to the parameters passed in +// - Make a public method called `getLastName()` that returns the last name + +// - Create a class called 'Child' that inherits (extends) Parent: +// - Make an instance variable called first_name +// - Make a constructor that first, sets first_name, and second, calls the constructor of Parent (Make sure to pass in the last name and eye color) +// - Create a method that returns the first and last name in a String +// - Create a method that returns the eye color color of the parent + +// ### Requirements 🏫 +// ``` +// 1. A .java file +// 2. Prints the first and last name of the child +// 3. Prints the eye color of the parent +// ``` +package JavaTraining2024.Week3.Inheritance; + + +public class Main { + public static void main(String[] args){ + Child dhyan = new Child("dhyan", "soni", "brown"); + System.out.println(dhyan.getEyeColor()); + } +} \ No newline at end of file diff --git a/Week3/Inheritance/Parent.java b/Week3/Inheritance/Parent.java new file mode 100644 index 0000000..54f04d6 --- /dev/null +++ b/Week3/Inheritance/Parent.java @@ -0,0 +1,37 @@ +// # Inheritance 🍵 + +// ### Task 🐧 +// - Create a class called Parent: +// - Make an instance variable called last_name +// - Make an instace variable called eye color +// - Create a constructor and set all the instace varaiables to the parameters passed in +// - Make a public method called `getLastName()` that returns the last name + +// - Create a class called 'Child' that inherits (extends) Parent: +// - Make an instance variable called first_name +// - Make a constructor that first, sets first_name, and second, calls the constructor of Parent (Make sure to pass in the last name and eye color) +// - Create a method that returns the first and last name in a String +// - Create a method that returns the eye color color of the parent + +// ### Requirements 🏫 +// ``` +// 1. A .java file +// 2. Prints the first and last name of the child +// 3. Prints the eye color of the parent +// ``` +package JavaTraining2024.Week3.Inheritance; + +public class Parent { + String last_name; + String eye_color; + + Parent(String last_name, String eye_color){ + this.last_name = last_name; + this.eye_color = eye_color; + } + + String getLastName(){ + return last_name; + } +} + diff --git a/Week3/Inheritance/README.md b/Week3/Inheritance/README.md new file mode 100644 index 0000000..72f1e3d --- /dev/null +++ b/Week3/Inheritance/README.md @@ -0,0 +1,21 @@ +# Inheritance 🍵 + +### Task 🐧 + - Create a class called Parent: + - Make an instance variable called last_name + - Make an instace variable called eye color + - Create a constructor and set all the instace varaiables to the parameters passed in + - Make a public method called `getLastName()` that returns the last name + + - Create a class called 'Child' that inherits (extends) Parent: + - Make an instance variable called first_name + - Make a constructor that first, sets first_name, and second, calls the constructor of Parent (Make sure to pass in the last name and eye color) + - Create a method that returns the first and last name in a String + - Create a method that returns the eye color color of the parent + +### Requirements 🏫 +``` +1. A .java file +2. Prints the first and last name of the child +3. Prints the eye color of the parent +``` \ No newline at end of file diff --git a/Week3/Polymorphism/README.md b/Week3/Polymorphism/README.md new file mode 100644 index 0000000..9fb38a6 --- /dev/null +++ b/Week3/Polymorphism/README.md @@ -0,0 +1,17 @@ +# Polymorphism 🍵 + +### Task 🐧 + - Create a class called 'Calculator' + - Make the a method division that divides two ints & overload it to divide two doubles + - Make the a method multiplication that multiplies two ints + + - Create a class called 'SlowCalculator' that extends Calculator: + - Override the multiply method and use a loop to calculate the product of the two ints + +### Requirements 🏫 +``` +1. A .java file +2. Prints the exact qutient of 39 and 49 +3. Prints the rounded quotient of 37 and 49 +4. Prints the product of 37 and 49 +``` \ No newline at end of file diff --git a/Week3/Project/Charizard.java b/Week3/Project/Charizard.java new file mode 100644 index 0000000..2a35676 --- /dev/null +++ b/Week3/Project/Charizard.java @@ -0,0 +1,24 @@ +package JavaTraining2024.Week3.Project; + +public class Charizard extends Pokemon{ + int health; + String name; + + // overiding the attack class + @Override + public void attack(Pokemon opposite_pokemon){ + take_damage(5); + } + + // setting up default values + Charizard() { + super(20, "Charizard"); + } + + // non default constructor so you can set up values + Charizard(int health, String name) { + super(health, name); + this.health = health; + this.name = name; + } +} diff --git a/Week3/Project/Main.java b/Week3/Project/Main.java new file mode 100644 index 0000000..88e20ba --- /dev/null +++ b/Week3/Project/Main.java @@ -0,0 +1,19 @@ +package JavaTraining2024.Week3.Project; + +public class Main { + public static void main(String[] args) { + Pikachu pikachu = new Pikachu(40, "Pikachu"); + Charizard charizard = new Charizard(30, "AwesomeCharizard"); + + while (!pikachu.getIsFainted() && !charizard.getIsFainted()){ + pikachu.attack(charizard); + charizard.attack(pikachu); + } + if (pikachu.getIsFainted()){ + System.out.println(pikachu.getName() + " fainted :("); + } + if (charizard.getIsFainted()){ + System.out.println(charizard.getName() + " fainted :("); + } + } +} diff --git a/Week3/Project/Pikachu.java b/Week3/Project/Pikachu.java new file mode 100644 index 0000000..34fcd28 --- /dev/null +++ b/Week3/Project/Pikachu.java @@ -0,0 +1,24 @@ +package JavaTraining2024.Week3.Project; + +public class Pikachu extends Pokemon{ + int health; + String name; + + // overiding the attack class + @Override + public void attack(Pokemon opposite_pokemon){ + take_damage(5); + } + + // setting up default values + Pikachu() { + super(20, "Pikachu"); + } + + // non default constructor so you can set up values + Pikachu(int health, String name) { + super(health, name); + this.health = health; + this.name = name; + } +} diff --git a/Week3/Project/Pokemon.java b/Week3/Project/Pokemon.java new file mode 100644 index 0000000..4a01528 --- /dev/null +++ b/Week3/Project/Pokemon.java @@ -0,0 +1,37 @@ +package JavaTraining2024.Week3.Project; + +abstract class Pokemon { + // Private variables as per ReadMe (encapuslation) + private int health; + private String name; + + // non-default constructor enabling user to input a health and name value + Pokemon(int health, String name){ + this.health = health; + this.name = name; + } + + // method to calculate damage taken + public void take_damage(int damage){ + health = health - damage; + } + + // method to find out if the pokemon is fainted or not + public boolean getIsFainted(){ + if (health <= 0) { + return true; + } + else { + return false; + } + } + + // abstract method to be used when this class is used in another class and supposed to be overridden + public abstract void attack(Pokemon opposite_pokemon); + + // simple method to get the name of the pokemon + public String getName(){ + return name; + } + +}