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/misc.xml

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

1 change: 1 addition & 0 deletions .idea/modules.xml

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

11 changes: 11 additions & 0 deletions Dog/Dog.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
45 changes: 45 additions & 0 deletions Dog/src/Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
public class Dog {
private String breed;
private String size;
private String color;
private int age;
private String dogName;
public Dog(String breed, String size, String color, int age, String dogName) {
this.breed = breed;
this.size = size;
this.color = color;
this.age = age;
this.dogName = dogName;
}
public void name() {
System.out.println("the "+ size +" and "+ color +" dog is a "+ breed +" named "+ dogName +" and is "+ age +" years old");
}
public void eat() {
System.out.println(dogName +" is eating.");
}
public void run(int distance) {
distance = 2 * age - distance;
if (distance < 0) {
distance = 0;
}
System.out.println(dogName +" ran "+ distance +" miles today.");
}
public void sleep() {
System.out.println(dogName +" is sleeping.");
}

public static void main(String[] args) {
Dog Dog1Object = new Dog("Bulldog", "large", "light gray", 5, "Meatloaf");
Dog Dog2Object = new Dog("Beagle", "large", "orange", 6, "Buddy");
Dog Dog3Object = new Dog("German Shepherd", "large", "white & orange", 6, "Chop");

Dog1Object.name();
Dog1Object.run(6);

Dog2Object.name();
Dog2Object.run(6);

Dog3Object.name();
Dog3Object.sleep();
}
}
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,33 +10,34 @@
6. All the instance methods for the class **Student**

```java
//Class name: Student
class Student{
private String name;
private int rollNo;

private String name; //Instance variable/fields: name, data type is String
private int rollNo; //Instance variable/fields: rollNo, data type int
// Constructor: Parameters are (String s. int r)
Student(String s, int r)
{
name = s;
rollNo = r;
name = s; //instance variable name set to value of parameter s
rollNo = r; //instance variable rollNo set to value of parameter r
}

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

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

## Part 2 - Public VS Static

* 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.

* In your own words, write a few sentences below explaining the difference between static and public methods in relation to a class.<br>
The main difference I notice between static and public methods are the way they are called. public methods require you to create an object to call it while static methods do not.
## Part 3 - Dogs

* View the image below, and from the image, construct a Java file **Dog** that mirrors the diagrammed class and the 3 dog objects.
Expand Down