From 17bab6728fdc0c1673e1786fc1ad328e78dad020 Mon Sep 17 00:00:00 2001 From: JustinQ-DNHS Date: Thu, 10 Oct 2024 18:39:02 -0700 Subject: [PATCH 01/17] it kinda works dw about it --- {Week 3 => Week3}/Abstraction/README.md | 0 Week3/Arrays/Array.java | 7 +++++++ {Week 3 => Week3}/Arrays/README.txt | 0 {Week 3 => Week3}/Classes & Objects/README.md | 0 {Week 3 => Week3}/Encapsulation/README.md | 0 {Week 3 => Week3}/Inheritance/README.md | 0 {Week 3 => Week3}/Polymorphism/README.md | 0 7 files changed, 7 insertions(+) rename {Week 3 => Week3}/Abstraction/README.md (100%) create mode 100644 Week3/Arrays/Array.java rename {Week 3 => Week3}/Arrays/README.txt (100%) rename {Week 3 => Week3}/Classes & Objects/README.md (100%) rename {Week 3 => Week3}/Encapsulation/README.md (100%) rename {Week 3 => Week3}/Inheritance/README.md (100%) rename {Week 3 => Week3}/Polymorphism/README.md (100%) diff --git a/Week 3/Abstraction/README.md b/Week3/Abstraction/README.md similarity index 100% rename from Week 3/Abstraction/README.md rename to Week3/Abstraction/README.md diff --git a/Week3/Arrays/Array.java b/Week3/Arrays/Array.java new file mode 100644 index 0000000..10aa284 --- /dev/null +++ b/Week3/Arrays/Array.java @@ -0,0 +1,7 @@ +public class Array { + public static void main(String[] args) + { + System.out.println("sus"); + } +} + diff --git a/Week 3/Arrays/README.txt b/Week3/Arrays/README.txt similarity index 100% rename from Week 3/Arrays/README.txt rename to Week3/Arrays/README.txt diff --git a/Week 3/Classes & Objects/README.md b/Week3/Classes & Objects/README.md similarity index 100% rename from Week 3/Classes & Objects/README.md rename to Week3/Classes & Objects/README.md diff --git a/Week 3/Encapsulation/README.md b/Week3/Encapsulation/README.md similarity index 100% rename from Week 3/Encapsulation/README.md rename to Week3/Encapsulation/README.md diff --git a/Week 3/Inheritance/README.md b/Week3/Inheritance/README.md similarity index 100% rename from Week 3/Inheritance/README.md rename to Week3/Inheritance/README.md diff --git a/Week 3/Polymorphism/README.md b/Week3/Polymorphism/README.md similarity index 100% rename from Week 3/Polymorphism/README.md rename to Week3/Polymorphism/README.md From bb802d7c1fc429bde5df9a570171f023da855d64 Mon Sep 17 00:00:00 2001 From: JustinQ-DNHS Date: Thu, 17 Oct 2024 16:53:08 -0700 Subject: [PATCH 02/17] created class homework --- Week3/Classes&Objects/Pokemon.java | 18 ++++++++++++++++++ .../README.md | 0 2 files changed, 18 insertions(+) create mode 100644 Week3/Classes&Objects/Pokemon.java rename Week3/{Classes & Objects => Classes&Objects}/README.md (100%) diff --git a/Week3/Classes&Objects/Pokemon.java b/Week3/Classes&Objects/Pokemon.java new file mode 100644 index 0000000..1fa97ba --- /dev/null +++ b/Week3/Classes&Objects/Pokemon.java @@ -0,0 +1,18 @@ +public class Pokemon { + String name; + int level; + + void attack(){ + System.out.print(name + "attack!"); + } + + public static void main(String[] args) { + + Pokemon p1 = new Pokemon(); + p1.name = "Pikachu"; + p1.level = 100; + + System.out.println(p1.name + " " + p1.level); + p1.attack(); + } +} diff --git a/Week3/Classes & Objects/README.md b/Week3/Classes&Objects/README.md similarity index 100% rename from Week3/Classes & Objects/README.md rename to Week3/Classes&Objects/README.md From 99e8115715395b9d2675199a03edaafca0cd2a05 Mon Sep 17 00:00:00 2001 From: JustinQ-DNHS Date: Thu, 17 Oct 2024 17:20:43 -0700 Subject: [PATCH 03/17] did the array homework on time --- Week3/Arrays/Array.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Week3/Arrays/Array.java b/Week3/Arrays/Array.java index 10aa284..3f132ba 100644 --- a/Week3/Arrays/Array.java +++ b/Week3/Arrays/Array.java @@ -1,7 +1,10 @@ public class Array { - public static void main(String[] args) - { - System.out.println("sus"); - } + public static void main(String[] args) { + String[] randomRoboticInformation = {"Software", "blah blah blah"}; + + for (int i = 0; i < randomRoboticInformation.length; i++) { + System.out.println(randomRoboticInformation[i]); + } + } } From f75279ce53a5f6809b1e5404fed07fb1619e1fb5 Mon Sep 17 00:00:00 2001 From: JustinQ-DNHS Date: Thu, 17 Oct 2024 17:35:16 -0700 Subject: [PATCH 04/17] finished class homework --- Week3/Classes&Objects/Me.java | 21 +++++++++++++++++++++ Week3/Classes&Objects/Pokemon.java | 24 ++++++++++++++++++------ 2 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 Week3/Classes&Objects/Me.java diff --git a/Week3/Classes&Objects/Me.java b/Week3/Classes&Objects/Me.java new file mode 100644 index 0000000..1849d80 --- /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; + } + void name() { + System.out.println(this.name); + } + void age() { + System.out.println(this.age); + } + + public static void main(String[] args) { + Me justin = new Me("Justin", 17); + justin.name(); + justin.age(); + } +} diff --git a/Week3/Classes&Objects/Pokemon.java b/Week3/Classes&Objects/Pokemon.java index 1fa97ba..ee9ab4e 100644 --- a/Week3/Classes&Objects/Pokemon.java +++ b/Week3/Classes&Objects/Pokemon.java @@ -2,17 +2,29 @@ public class Pokemon { String name; int level; + + Pokemon(){ + level = 1; + } + + Pokemon(String pName, int pLevel){ + // Use variables defined in class (at top of page) rather than local variables (this statements) + this.name = pName; + this.level = pLevel; + } + void attack(){ - System.out.print(name + "attack!"); + System.out.println(name + "attack!"); } public static void main(String[] args) { - Pokemon p1 = new Pokemon(); - p1.name = "Pikachu"; - p1.level = 100; + Pokemon p1 = new Pokemon("Pikachu", 15); - System.out.println(p1.name + " " + p1.level); - p1.attack(); + System.out.print(p1.name + "\nLevel:" + p1.level); + + Pokemon p2 = new Pokemon("Vaporeon", 69); + + p2.attack(); } } From 8f94d8a99ced1ceed75b60e94ef5dfb69f57be05 Mon Sep 17 00:00:00 2001 From: JustinQ-DNHS Date: Thu, 17 Oct 2024 17:35:25 -0700 Subject: [PATCH 05/17] inheritance activitiy start --- Week3/Inheritance/Vehicle.java | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Week3/Inheritance/Vehicle.java diff --git a/Week3/Inheritance/Vehicle.java b/Week3/Inheritance/Vehicle.java new file mode 100644 index 0000000..207ab25 --- /dev/null +++ b/Week3/Inheritance/Vehicle.java @@ -0,0 +1,25 @@ +package Week3.Inheritance; + +public class Vehicle { + double speed; + + void go() { + System.out.println("This vehicle is moving!"); + } + + void stop() { + System.out.println("This vehicle is stopped!"); + } + public static void main(String[] args) { + Car ferrari = new Car(); + ferrari.go(); + } +} + +class Car extends Vehicle { + +} + +class Bicycle extends Vehicle { + +} \ No newline at end of file From fd95cd83d1a84a70592867ed326c8e0f2de4ac54 Mon Sep 17 00:00:00 2001 From: JustinQ-DNHS Date: Tue, 22 Oct 2024 08:54:50 -0700 Subject: [PATCH 06/17] did the inheritance homework --- Week3/Inheritance/Main.java | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Week3/Inheritance/Main.java diff --git a/Week3/Inheritance/Main.java b/Week3/Inheritance/Main.java new file mode 100644 index 0000000..540e98f --- /dev/null +++ b/Week3/Inheritance/Main.java @@ -0,0 +1,33 @@ +public class Main { + + public static void main(String[] args) { + Child Jim = new Child("Jim"); + Jim.getLastName(); + Jim.parentEyeColor(); + } +} + +class Parent { + String last_name = "Smithson"; + String eye_color = "Blue"; + + void getLastName() { + System.out.println("This person's last name is " + this.last_name); + } +} + +class Child extends Parent { + String first_name; + + Child(String first_name) { + this.first_name = first_name; + } + + void getFullName() { + System.out.println("This is" + first_name + " his last name is " + last_name + "."); + } + + void parentEyeColor() { + System.out.println("The parent has " + eye_color + " eyes."); + } +} \ No newline at end of file From 8cf904412aa16c5443d53a956ded81e1b8fc0c65 Mon Sep 17 00:00:00 2001 From: JustinQ-DNHS Date: Tue, 22 Oct 2024 16:00:26 -0700 Subject: [PATCH 07/17] fixed issue --- Week3/Inheritance/Vehicle.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/Week3/Inheritance/Vehicle.java b/Week3/Inheritance/Vehicle.java index 207ab25..770d1fc 100644 --- a/Week3/Inheritance/Vehicle.java +++ b/Week3/Inheritance/Vehicle.java @@ -1,5 +1,3 @@ -package Week3.Inheritance; - public class Vehicle { double speed; From 982c345ece543ff454ec2f317fd4cd89dd06ed7d Mon Sep 17 00:00:00 2001 From: JustinQ-DNHS Date: Tue, 22 Oct 2024 16:11:29 -0700 Subject: [PATCH 08/17] fixed mistake --- Week3/Inheritance/Main.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Week3/Inheritance/Main.java b/Week3/Inheritance/Main.java index 540e98f..bb33acc 100644 --- a/Week3/Inheritance/Main.java +++ b/Week3/Inheritance/Main.java @@ -1,16 +1,20 @@ public class Main { public static void main(String[] args) { - Child Jim = new Child("Jim"); + Child Jim = new Child("Jim", "Smithson", "blue"); Jim.getLastName(); Jim.parentEyeColor(); } } class Parent { - String last_name = "Smithson"; - String eye_color = "Blue"; + String last_name; + String eye_color; + Parent(String last_name, String eyeColor) { + this.last_name = last_name; + this.eye_color = eyeColor; + } void getLastName() { System.out.println("This person's last name is " + this.last_name); } @@ -19,7 +23,8 @@ void getLastName() { class Child extends Parent { String first_name; - Child(String first_name) { + Child(String first_name, String lastName, String eyeColor) { + super(lastName, eyeColor); this.first_name = first_name; } @@ -28,6 +33,6 @@ void getFullName() { } void parentEyeColor() { - System.out.println("The parent has " + eye_color + " eyes."); + System.out.println("The parent has " + super.eye_color + " eyes."); } } \ No newline at end of file From 24f68826beadfe4077d9ad8e5d2e787224d1f915 Mon Sep 17 00:00:00 2001 From: JustinQ-DNHS Date: Tue, 22 Oct 2024 17:10:05 -0700 Subject: [PATCH 09/17] finish the abstraction homework --- Week3/Abstraction/Shirt.java | 52 ++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Week3/Abstraction/Shirt.java diff --git a/Week3/Abstraction/Shirt.java b/Week3/Abstraction/Shirt.java new file mode 100644 index 0000000..cb0cf3a --- /dev/null +++ b/Week3/Abstraction/Shirt.java @@ -0,0 +1,52 @@ +// Abstract means that you can't create a object of this class, only it's children +public abstract class Shirt { + String color; + Shirt(String color) { + this.color = color; + } + + public String getColor() { + return this.color; + } + + abstract void getDescription(); + + public static void main(String[] args) { + Shirt[] myShirt = {new T_Shirt("Blue", "XL:", 29.99), new Jacket("Black", "Adidas", 49.99)}; + for (int i = 0; i < myShirt.length; i++) { + myShirt[i].getDescription(); + } + } +} + +class T_Shirt extends Shirt { + String size; + double price; + + T_Shirt(String color, String size, double price) { + super(color); + this.size = size; + this.price = price; + } + + @Override + void getDescription() { + System.out.println("\n\nT-Shirt:\nColor: " + color + "\nSize: " + size + "\nPrice: $" + price); + } +} + +class Jacket extends Shirt { + double price; + String brand; + + Jacket(String color, String brand, double price) { + super(color); + this.brand = brand; + this.price = price; + } + + @Override + void getDescription() { + System.out.println("\n\nJacket:\nColor: " + color + "\nBraand: " + brand + "\nPrice: $" + price); + } +} \ No newline at end of file From 5e1cdf6a3db6ae2e26f9d99d9d99f22c28bad951 Mon Sep 17 00:00:00 2001 From: JustinQ-DNHS Date: Tue, 22 Oct 2024 17:11:01 -0700 Subject: [PATCH 10/17] polymorphism homework and practuce done --- Week3/Polymorphism/Calculator.java | 33 ++++++++++++++++++++++++++++++ Week3/Polymorphism/Sample.java | 28 +++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 Week3/Polymorphism/Calculator.java create mode 100644 Week3/Polymorphism/Sample.java diff --git a/Week3/Polymorphism/Calculator.java b/Week3/Polymorphism/Calculator.java new file mode 100644 index 0000000..95bc1a5 --- /dev/null +++ b/Week3/Polymorphism/Calculator.java @@ -0,0 +1,33 @@ +public class Calculator { + public Integer division(int num1, int num2) { + return num1/num2; + } + + public double division(double num1, double num2) { + return num1/num2; + } + + public Integer multiply(int num1, int num2) { + return num1*num2; + } + + public static void main(String[] args) { + Calculator jim = new SlowCalculator(); + jim.multiply(10, 4); + jim.division(4.5, 1.5); + jim.division(4, 2); + } +} + +class SlowCalculator extends Calculator { + int num3; + + public Integer multiply(int num1, int num2) { + this.num3 = 0; + for (int i = 0; i < num2; i++) { + System.out.println(num3); + num3 = num1 + num3; + } + return this.num3; + } +} diff --git a/Week3/Polymorphism/Sample.java b/Week3/Polymorphism/Sample.java new file mode 100644 index 0000000..d277a94 --- /dev/null +++ b/Week3/Polymorphism/Sample.java @@ -0,0 +1,28 @@ +public class Sample { + String ice; + Sample(String ice) { + this.ice = ice; + } + + void saySomething() { + System.out.println("HEY!"); + } + + public static void main(String[] args) { + Sample[] bob = {new Polymorphism("ice"), new Sample("ice"), new Polymorphism("ice"), new Sample("Bob")}; + for (int i = 0; i < bob.length; i++) { + bob[i].saySomething(); + } + } +} + +class Polymorphism extends Sample { + Polymorphism(String ice) { + super(ice); + } + + @Override + void saySomething() { + System.out.println("Hey?"); + } +} From da94ca31f8fee755dec2fae2ad45788d5c4e71e6 Mon Sep 17 00:00:00 2001 From: JustinQ-DNHS Date: Tue, 22 Oct 2024 17:13:24 -0700 Subject: [PATCH 11/17] added public and private to promote better readability --- Week3/Abstraction/Shirt.java | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Week3/Abstraction/Shirt.java b/Week3/Abstraction/Shirt.java index cb0cf3a..b09cbaa 100644 --- a/Week3/Abstraction/Shirt.java +++ b/Week3/Abstraction/Shirt.java @@ -1,7 +1,8 @@ // Abstract means that you can't create a object of this class, only it's children public abstract class Shirt { - String color; - Shirt(String color) { + public String color; + + public Shirt(String color) { this.color = color; } @@ -20,33 +21,33 @@ public static void main(String[] args) { } class T_Shirt extends Shirt { - String size; - double price; + private String size; + private double price; - T_Shirt(String color, String size, double price) { + public T_Shirt(String color, String size, double price) { super(color); this.size = size; this.price = price; } @Override - void getDescription() { + public void getDescription() { System.out.println("\n\nT-Shirt:\nColor: " + color + "\nSize: " + size + "\nPrice: $" + price); } } class Jacket extends Shirt { - double price; - String brand; + private double price; + private String brand; - Jacket(String color, String brand, double price) { + public Jacket(String color, String brand, double price) { super(color); this.brand = brand; this.price = price; } @Override - void getDescription() { + public void getDescription() { System.out.println("\n\nJacket:\nColor: " + color + "\nBraand: " + brand + "\nPrice: $" + price); } } \ No newline at end of file From a4d0ba653ba04d01e03b670c3eac27a1df0b5536 Mon Sep 17 00:00:00 2001 From: JustinQ-DNHS Date: Tue, 22 Oct 2024 17:27:11 -0700 Subject: [PATCH 12/17] finished encapsulation homework --- Week3/Encapsulation/Information.java | 59 ++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Week3/Encapsulation/Information.java diff --git a/Week3/Encapsulation/Information.java b/Week3/Encapsulation/Information.java new file mode 100644 index 0000000..8ebeae1 --- /dev/null +++ b/Week3/Encapsulation/Information.java @@ -0,0 +1,59 @@ +public class Information { + // Private means variable cannot be accessed outside of class + private String name; + private int age; + private String gender; + + Information() { + this.name = "Jimmeh"; + this.age = 21; + this.gender = "Male"; + } + + Information(String name, int age, String gender) { + this.name = name; + this.age = age; + this.gender = gender; + } + + + + // Public means that there is permission for other classes to use this + public String getName() { + return name; + } + public void setName(String newName) { + this.name = newName; + } + + public int getAge() { + return age; + } + public void setAge(int newAge) { + this.age = newAge; + } + + public String getGender() { + return gender; + } + public void setGender(String newGender) { + this.gender = newGender; + } + + public boolean getOlderThan21() { + if (this.age > 21) { + return true; + } else { + return false; + } + } + + public static void main(String[] args) { + Information justin = new Information("Justin", 17, "Male"); + Information weston = new Information("Weston", 22, "Mouse"); + + System.out.println(justin.getOlderThan21()); + System.out.println(weston.getOlderThan21()); + } +} + From 76a6bfa9f0d5ede7d1e37d9aa3bfcb474ef197fa Mon Sep 17 00:00:00 2001 From: JustinQ-DNHS Date: Tue, 22 Oct 2024 17:32:05 -0700 Subject: [PATCH 13/17] removed white space --- Week3/Encapsulation/Information.java | 44 +++++++--------------------- 1 file changed, 11 insertions(+), 33 deletions(-) diff --git a/Week3/Encapsulation/Information.java b/Week3/Encapsulation/Information.java index 8ebeae1..98ad6e7 100644 --- a/Week3/Encapsulation/Information.java +++ b/Week3/Encapsulation/Information.java @@ -9,45 +9,24 @@ public class Information { this.age = 21; this.gender = "Male"; } - Information(String name, int age, String gender) { this.name = name; this.age = age; this.gender = gender; } - - - // Public means that there is permission for other classes to use this - public String getName() { - return name; - } - public void setName(String newName) { - this.name = newName; - } - - public int getAge() { - return age; - } - public void setAge(int newAge) { - this.age = newAge; - } - - public String getGender() { - return gender; - } - public void setGender(String newGender) { - this.gender = newGender; - } - + public String getName() {return name;} + public void setName(String newName) {this.name = newName;} + // Get Age + public int getAge() {return age;} + public void setAge(int newAge) {this.age = newAge;} + // Get gender + public String getGender() {return gender;} + public void setGender(String newGender) {this.gender = newGender;} + // Check older than 21 public boolean getOlderThan21() { - if (this.age > 21) { - return true; - } else { - return false; - } + if (this.age > 21) {return true;} else {return false;} } - public static void main(String[] args) { Information justin = new Information("Justin", 17, "Male"); Information weston = new Information("Weston", 22, "Mouse"); @@ -55,5 +34,4 @@ public static void main(String[] args) { System.out.println(justin.getOlderThan21()); System.out.println(weston.getOlderThan21()); } -} - +} \ No newline at end of file From ac776c4fbccaaf05c774ed545195217968617e15 Mon Sep 17 00:00:00 2001 From: JustinQ-DNHS Date: Thu, 24 Oct 2024 16:21:04 -0700 Subject: [PATCH 14/17] this breaks stuff --- Week3/Inheritance/Child.java | 16 ++++++++++++++++ Week3/Inheritance/Main.java | 22 +++++++++++----------- Week3/Inheritance/Parent.java | 12 ++++++++++++ Week3/Polymorphism/Calculator.java | 15 +-------------- Week3/Polymorphism/SlowCalculator.java | 18 ++++++++++++++++++ 5 files changed, 58 insertions(+), 25 deletions(-) create mode 100644 Week3/Inheritance/Child.java create mode 100644 Week3/Inheritance/Parent.java create mode 100644 Week3/Polymorphism/SlowCalculator.java diff --git a/Week3/Inheritance/Child.java b/Week3/Inheritance/Child.java new file mode 100644 index 0000000..b4599bd --- /dev/null +++ b/Week3/Inheritance/Child.java @@ -0,0 +1,16 @@ +public class Child extends Parent { + String first_name; + + Child(String first_name, String lastName, String eyeColor) { + super(lastName, eyeColor); + this.first_name = first_name; + } + + void getFullName() { + System.out.println("This is" + first_name + " his last name is " + last_name + "."); + } + + void parentEyeColor() { + System.out.println("The parent has " + super.eye_color + " eyes."); + } +} diff --git a/Week3/Inheritance/Main.java b/Week3/Inheritance/Main.java index bb33acc..dc22c54 100644 --- a/Week3/Inheritance/Main.java +++ b/Week3/Inheritance/Main.java @@ -7,18 +7,18 @@ public static void main(String[] args) { } } -class Parent { - String last_name; - String eye_color; +// class Parent { +// String last_name; +// String eye_color; - Parent(String last_name, String eyeColor) { - this.last_name = last_name; - this.eye_color = eyeColor; - } - void getLastName() { - System.out.println("This person's last name is " + this.last_name); - } -} +// Parent(String last_name, String eyeColor) { +// this.last_name = last_name; +// this.eye_color = eyeColor; +// } +// void getLastName() { +// System.out.println("This person's last name is " + this.last_name); +// } +// } class Child extends Parent { String first_name; diff --git a/Week3/Inheritance/Parent.java b/Week3/Inheritance/Parent.java new file mode 100644 index 0000000..d668216 --- /dev/null +++ b/Week3/Inheritance/Parent.java @@ -0,0 +1,12 @@ +public class Parent { + String last_name; + String eye_color; + + Parent(String last_name, String eyeColor) { + this.last_name = last_name; + this.eye_color = eyeColor; + } + void getLastName() { + System.out.println("This person's last name is " + this.last_name); + } +} diff --git a/Week3/Polymorphism/Calculator.java b/Week3/Polymorphism/Calculator.java index 95bc1a5..615f68e 100644 --- a/Week3/Polymorphism/Calculator.java +++ b/Week3/Polymorphism/Calculator.java @@ -17,17 +17,4 @@ public static void main(String[] args) { jim.division(4.5, 1.5); jim.division(4, 2); } -} - -class SlowCalculator extends Calculator { - int num3; - - public Integer multiply(int num1, int num2) { - this.num3 = 0; - for (int i = 0; i < num2; i++) { - System.out.println(num3); - num3 = num1 + num3; - } - return this.num3; - } -} +} \ No newline at end of file diff --git a/Week3/Polymorphism/SlowCalculator.java b/Week3/Polymorphism/SlowCalculator.java new file mode 100644 index 0000000..85c7803 --- /dev/null +++ b/Week3/Polymorphism/SlowCalculator.java @@ -0,0 +1,18 @@ +import java.lang.Math; + +class SlowCalculator extends Calculator { + int num3; + + public Integer multiply(int num1, int num2) { + this.num3 = 0; + for (int i = 0; i < num2; i++) { + System.out.println(num3); + num3 = num1 + num3; + } + return this.num3; + } + + public void exponent(int x, int y) { + System.out.println("I don't work"); + } +} \ No newline at end of file From d1170f94260e16ac08d83fd11680cbe4833e8061 Mon Sep 17 00:00:00 2001 From: JustinQ-DNHS Date: Thu, 24 Oct 2024 16:21:19 -0700 Subject: [PATCH 15/17] fix later --- Week3/Polymorphism/SlowCalculator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Week3/Polymorphism/SlowCalculator.java b/Week3/Polymorphism/SlowCalculator.java index 85c7803..3eb4748 100644 --- a/Week3/Polymorphism/SlowCalculator.java +++ b/Week3/Polymorphism/SlowCalculator.java @@ -1,4 +1,4 @@ -import java.lang.Math; +// import java.lang.Math; class SlowCalculator extends Calculator { int num3; From 04d7e6eab1cc9ad22e8b66df4d1f00ea6b381056 Mon Sep 17 00:00:00 2001 From: JustinQ-DNHS Date: Thu, 24 Oct 2024 17:16:22 -0700 Subject: [PATCH 16/17] did pokemon work --- pokemon/Jigglypuff.java | 16 ++++++++++++++++ pokemon/Main.java | 18 ++++++++++++++++++ pokemon/Pikachu.java | 16 ++++++++++++++++ pokemon/Pokemon.java | 28 ++++++++++++++++++++++++++++ pokemon/README | 19 +++++++++++++++++++ 5 files changed, 97 insertions(+) create mode 100644 pokemon/Jigglypuff.java create mode 100644 pokemon/Main.java create mode 100644 pokemon/Pikachu.java create mode 100644 pokemon/Pokemon.java create mode 100644 pokemon/README diff --git a/pokemon/Jigglypuff.java b/pokemon/Jigglypuff.java new file mode 100644 index 0000000..2057c7e --- /dev/null +++ b/pokemon/Jigglypuff.java @@ -0,0 +1,16 @@ +package pokemon; + +public class Jigglypuff extends Pokemon { + public Jigglypuff(int health, String name, int attack) { + super(health, name, attack); + } + + private Jigglypuff() { + super(50, "Jigglypuff", 8); + } + + @Override + public void attack(Pokemon target) { + target.damageTaken(this.attack); + } +} diff --git a/pokemon/Main.java b/pokemon/Main.java new file mode 100644 index 0000000..8679311 --- /dev/null +++ b/pokemon/Main.java @@ -0,0 +1,18 @@ +package pokemon; + +public class Main { + public static void main(String[] args) { + Pokemon pikachu = new Pikachu(100, "Ash's Pikachu", 20); + Pokemon jigglypuff = new Jigglypuff(121, "Demon Slapping Singer", 6); + + while (pikachu.getIsFainted() || jigglypuff.getIsFainted()) { + pikachu.attack(jigglypuff); + jigglypuff.attack(pikachu); + } + if (pikachu.getIsFainted()) { + System.out.println(jigglypuff.getName() + " wins"); + } else { + System.out.println(pikachu.getName() + " Wins"); + } + } +} diff --git a/pokemon/Pikachu.java b/pokemon/Pikachu.java new file mode 100644 index 0000000..97b5cda --- /dev/null +++ b/pokemon/Pikachu.java @@ -0,0 +1,16 @@ +package pokemon; + +public class Pikachu extends Pokemon { + public Pikachu(int health, String name, int attack) { + super(health, name, attack); + }; + + private Pikachu() { + super(50, "Pikachu", 12); + }; + + @Override + public void attack(Pokemon target) { + target.damageTaken(this.attack); + }; +} diff --git a/pokemon/Pokemon.java b/pokemon/Pokemon.java new file mode 100644 index 0000000..3901190 --- /dev/null +++ b/pokemon/Pokemon.java @@ -0,0 +1,28 @@ +package pokemon; + +abstract public class Pokemon { + private int health; + private String name; + public int attack; + // Sets a default value for all Pokemon of 50 + public Pokemon(int health, String name, int attack) { + this.health = health; + this.name = name; + this.attack = attack; + } + // Abstract method to reprogram for attack + abstract void attack(Pokemon target); + // Takes a number it deals that much damage to the Pokemon + public void damageTaken(int dmg) { + this.health = this.health - dmg; + } + // Checks the status of isFainted to see if Pokemon is fainted + public boolean getIsFainted() { + boolean isFainted = health <= 0; + return isFainted; + } + // Returns the value of Pokemon's name + public String getName() { + return this.name; + } +} \ No newline at end of file diff --git a/pokemon/README b/pokemon/README new file mode 100644 index 0000000..b1654d7 --- /dev/null +++ b/pokemon/README @@ -0,0 +1,19 @@ +a. Explain why Pokemon should be an abstract class + Since it doesn't make sense for their to be a Pokemon since it is a concept + +b. Explain why inheriting from Pokemon is useful + Inheriting from Pokemon means you require much less work as it all already exists in Pokemon + +c. Explain an example of method polymorphism in your code + There is an example of method Polymorphism in my code when I override the the attack function + +d. Explain an example of subtype polymorphism in your code + When I create the default constructor, due to it having different parameters it does not throw an error + +e. Explain why you made one of your methods public + I made attack public so that the main file could reference it + +f. Explain why you made one of your instance variables private + I made health and name private because health and name do not need to be changed or referenced by other classes just set in the super. + + \ No newline at end of file From 9d83eb4edc469abd8e10091303e33d7bdfff1e52 Mon Sep 17 00:00:00 2001 From: JustinQ-DNHS <142454003+JustinQ-DNHS@users.noreply.github.com> Date: Thu, 24 Oct 2024 22:06:09 -0700 Subject: [PATCH 17/17] Update README --- pokemon/README | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pokemon/README b/pokemon/README index b1654d7..1886181 100644 --- a/pokemon/README +++ b/pokemon/README @@ -1,19 +1,19 @@ a. Explain why Pokemon should be an abstract class - Since it doesn't make sense for their to be a Pokemon since it is a concept + Since it doesn't make sense for there to be a Pokemon class since it is a concept b. Explain why inheriting from Pokemon is useful Inheriting from Pokemon means you require much less work as it all already exists in Pokemon c. Explain an example of method polymorphism in your code - There is an example of method Polymorphism in my code when I override the the attack function + There is an example of method Polymorphism in my code when I override the attack function d. Explain an example of subtype polymorphism in your code When I create the default constructor, due to it having different parameters it does not throw an error e. Explain why you made one of your methods public - I made attack public so that the main file could reference it + I made the attack method public so that the main file could reference it f. Explain why you made one of your instance variables private I made health and name private because health and name do not need to be changed or referenced by other classes just set in the super. - \ No newline at end of file +