Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Week3 #1

Open
wants to merge 17 commits into
base: week3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
53 changes: 53 additions & 0 deletions Week3/Abstraction/Shirt.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Abstract means that you can't create a object of this class, only it's children
public abstract class Shirt {
public String color;

public 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 {
private String size;
private double price;

public T_Shirt(String color, String size, double price) {
super(color);
this.size = size;
this.price = price;
}

@Override
public void getDescription() {
System.out.println("\n\nT-Shirt:\nColor: " + color + "\nSize: " + size + "\nPrice: $" + price);
}
}

class Jacket extends Shirt {
private double price;
private String brand;

public Jacket(String color, String brand, double price) {
super(color);
this.brand = brand;
this.price = price;
}

@Override
public void getDescription() {
System.out.println("\n\nJacket:\nColor: " + color + "\nBraand: " + brand + "\nPrice: $" + price);
}
}
10 changes: 10 additions & 0 deletions Week3/Arrays/Array.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
public class Array {
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]);
}
}
}

File renamed without changes.
21 changes: 21 additions & 0 deletions Week3/Classes&Objects/Me.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
30 changes: 30 additions & 0 deletions Week3/Classes&Objects/Pokemon.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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.println(name + "attack!");
}

public static void main(String[] args) {

Pokemon p1 = new Pokemon("Pikachu", 15);

System.out.print(p1.name + "\nLevel:" + p1.level);

Pokemon p2 = new Pokemon("Vaporeon", 69);

p2.attack();
}
}
File renamed without changes.
37 changes: 37 additions & 0 deletions Week3/Encapsulation/Information.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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;}
// 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;}
}
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());
}
}
File renamed without changes.
16 changes: 16 additions & 0 deletions Week3/Inheritance/Child.java
Original file line number Diff line number Diff line change
@@ -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.");
}
}
38 changes: 38 additions & 0 deletions Week3/Inheritance/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
public class Main {

public static void main(String[] args) {
Child Jim = new Child("Jim", "Smithson", "blue");
Jim.getLastName();
Jim.parentEyeColor();
}
}

// 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);
// }
// }

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.");
}
}
12 changes: 12 additions & 0 deletions Week3/Inheritance/Parent.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
File renamed without changes.
23 changes: 23 additions & 0 deletions Week3/Inheritance/Vehicle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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 {

}
20 changes: 20 additions & 0 deletions Week3/Polymorphism/Calculator.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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);
}
}
File renamed without changes.
28 changes: 28 additions & 0 deletions Week3/Polymorphism/Sample.java
Original file line number Diff line number Diff line change
@@ -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?");
}
}
18 changes: 18 additions & 0 deletions Week3/Polymorphism/SlowCalculator.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
16 changes: 16 additions & 0 deletions pokemon/Jigglypuff.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
18 changes: 18 additions & 0 deletions pokemon/Main.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
16 changes: 16 additions & 0 deletions pokemon/Pikachu.java
Original file line number Diff line number Diff line change
@@ -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);
};
}
Loading