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.

48 changes: 48 additions & 0 deletions Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
public class Dog {

private String breed;
private String size;
private String color;
private int age;

public Dog(String breed, String size, String color, int age) {
this.breed = breed;
this.size = size;
this.color = color;
this.age = age;
}

public void eat()
System.out.println("The dog is eating.");
}
public void run() {
System.out.println("The dog is running.");
}

public void sleep() {
System.out.println("The dog is sleeping.");
}
public void name()
System.out.println("The dog's name is: ");
}
public String toString() {
return "Breed: " + breed + "\nSize: " + size + "\nColor: " + color + "\nAge: " + age;
}
public static void main(String[] args) {
Dog dog1 = new Dog("Bulldog", "large", "light gray", 5);
Dog dog2 = new Dog("Beagle", "large", "orange", 6);
Dog dog3 = new Dog("German Shepherd", "large", "white & orange", 6);

System.out.println("Dog 1:");
System.out.println(dog1.toString());

System.out.println("\nDog 2:");
System.out.println(dog2.toString());

System.out.println("\nDog 3:");
System.out.println(dog3.toString());

dog1.run();
dog3.eat();
}
}
21 changes: 12 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,25 @@
6. All the instance methods for the class **Student**

```java
class Student{
private String name;
private int rollNo;
class Student{ //class name
private String name; //name of student
private int rollNo; //roll number of student

//constructor
Student(String s, int r)
{
name = s;
rollNo = r;
name = s; //constructor parameters: String s (name)
rollNo = r; //constructor parameters: int r (roll number)
}

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

public static void main(String[] args) {
Student obj1=new Student("Rambo",21);
obj1.methodForDisplay();
public static void main(String[] args) { //Student object gets created
Student obj1=new Student("Rambo",21); // object with name Rambo with roll number 21
obj1.methodForDisplay(); //displays student's name and roll number
}
}
```
Expand All @@ -37,6 +38,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.

The difference between static and public methods is that with a static method it is not necessary to make an object in the class in order to be accessed. With a public method, objects are necessary in order to be accessed. Static refers to the method that is defined for the class itself. Public refers to instances of a class.

## 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