Skip to content
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
2 changes: 1 addition & 1 deletion .idea/Java-Assignment-010.iml

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

2 changes: 1 addition & 1 deletion .idea/misc.xml

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

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ class Student{

* Read the W3Schools page on class methods: [W3Schools Java Class Methods](https://www.w3schools.com/java/java_class_methods.asp)
* In your own words, write a few sentences below explaining the difference between static and public methods in relation to a class.
* * public and static methods are similar but your invocation for them differ. With a static method you can call it anytime within that class to use it. As opposed to public methods where you must first create and object and then invoke it with dot notation( . )
* * depending on your use a static or public method will be more efficient than the other.

## Part 3 - Dogs

Expand Down
60 changes: 60 additions & 0 deletions src/Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Dog {

private String breed;
private DogSize size;
private List<String> color;
private int age;
private String name;

public Dog(String breed, DogSize size, String[] color, int age, String name) {
this.breed = breed;
this.size = size;
this.color = new ArrayList<>();
for (int i=0; i<color.length; i++) {
this.color.add(color[i]);
}
this.age = age;
this.name = name;
}

public void eat() {

}

public void run() {
Random r = new Random();
System.out.printf("Running at speed %d%n", r.nextInt());
}

public void sleep() {

}

public void name() {

}


public String getName() {
return name;
}

@Override
public String toString() {
return this.name;
}

@Override
public boolean equals(Object o) {
Dog other = (Dog)o;
return this.size == other.size;
}

public void setName(String name) {
this.name = name;
}
}
56 changes: 56 additions & 0 deletions src/DogPark.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class DogPark {

private ArrayList<Dog> dogsInPark;

public DogPark() {
//this.dogsInPark = new HashSet<>();
this.dogsInPark = new ArrayList<>();
}

public void play() {
/*
for (Dog d : dogsInPark) {
System.out.printf("Dog %s is ", d); //uses override method in Dog.java for `d`
d.run();
}
*/
Dog d1 = dogsInPark.get(0);
Dog d2 = dogsInPark.get(0);
if (d1.equals(d2)) {
System.out.printf("Dog %s is", d1);
d1.run();
System.out.printf("Dog %s is", d2);
d2.run();
}
}

public void dogEnter(Dog d) {
dogsInPark.add(d);
}

public static void main(String[] args) {

DogPark fortunaDp = new DogPark(); //Fortuna Dog Park

Dog dog1Object = new Dog("Bulldog", DogSize.LARGE,
new String[]{"light gray"}, 5, "Max");
Dog dog2Object = new Dog("Beagle", DogSize.MEDIUM,
new String[]{"Orange"}, 6, "Butch");
Dog dog3Object = new Dog("German Shepherd", DogSize.XTRALARGE,
new String[]{"White", "Orange"}, 6, "Kyle");

fortunaDp.dogEnter(dog1Object);
fortunaDp.dogEnter(dog2Object);
fortunaDp.play();
fortunaDp.dogEnter(dog3Object);
fortunaDp.play();


}

}
6 changes: 6 additions & 0 deletions src/DogSize.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
public enum DogSize {
XTRALARGE,
LARGE,
MEDIUM,
SMALL
}
19 changes: 19 additions & 0 deletions src/Student.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Student { // Class name

private String name; // Instance Variable/field
private int rollNo; // Instance Variable/field

Student(String s, int r) { // Constructor (+ constructor parameters)
name = s; // instance variable gets value
rollNo = r; // instance variable gets value
}

void methodForDisplay() { // instance method
System.out.println(name+"'s Roll No: "+rollNo);
}

public static void main(String[] args) {
Student obj1=new Student("Rambo",21); // Student object gets created
obj1.methodForDisplay();
}
}