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.

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

// Private instance variables (data members)
private String breed;
private String size;
private String color;
private int age;

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

// Method to simulate eating (functional)
public void eat() {
System.out.println(breed + " is happily eating!");
}

// Method to simulate running (functional)
public void run() {
System.out.println(breed + " has got the zoomies. Look at them go!");
}

// Method to simulate sleeping (functional)
public void sleep() {
System.out.println(breed + " must be tired.");
}

// Method to display the dog's name (assuming name is derived from breed)
public void name() {
System.out.println("This dog is a " + breed);
}

public static void main(String[] args) {
// Create Dog objects

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


}
}
23 changes: 14 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +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; // instance variable string type
private int rollNo; // instance variable int type

Student(String s, int r)
// Instance method Constructor
Student(String s, int r) // Parameters are String and int
{
name = s;
rollNo = r;
name = s; // instance variable set with "Rambo"
rollNo = r; // instance variable set with "21"
}

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

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

A static method can be called without making an object of the class. To call a public method you need to first create an object and then call the method with that object.


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