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
61 changes: 61 additions & 0 deletions Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
public class Dog {

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

private boolean isHungry;

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

void setName(String name) {
this.name = name;
}

String getName() {
return name;
}

void eat() {
if (isHungry) {
System.out.println(getName() + " is eating.");
isHungry = false;
} else {
System.out.println(getName() + " is not hungry right now.");
}
}

void run() {
System.out.println(getName() + " is running.");
isHungry = true;
}


void sleep() {
System.out.println(getName() + " is sleeping.");
}

public static void main(String[] args) {

Dog bulldog = new Dog("Bulldog", "Large", "Light Grey", 5);
bulldog.setName("Buddy");

Dog beagle = new Dog("Beagle", "Large", "Orange", 6);
beagle.setName("Max");

Dog germanShepherd = new Dog("German Shepherd", "Large", "White and Orange", 6);
germanShepherd.setName("Rocky");

bulldog.eat();
beagle.run();
germanShepherd.sleep();
}
}
18 changes: 10 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,24 @@
6. All the instance methods for the class **Student**

```java
class Student{
private String name;
class Student{ //class name (student)
private String name;
private int rollNo;
//Instance variables with their data types
Student(String s, int r)
{
name = s;
rollNo = r;
{
//Constructor and Constructor Parameters: S: string for students name and r: int for rollNo
name = s; //The name instance variable
rollNo = r;//The rollNo instance variable
}

//All the instance methods for the class student
void methodForDisplay()
{
System.out.println(name+"'s Roll No: "+rollNo);
}

public static void main(String[] args) {
//Where Student gets created
Student obj1=new Student("Rambo",21);
obj1.methodForDisplay();
}
Expand All @@ -36,7 +38,7 @@ 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.

- Static methods belong to the class and can be called using the class name without creating an object, while public methods belong to objects and require an instance of the class to be called.
## 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