diff --git a/.idea/misc.xml b/.idea/misc.xml index 639900d..172df7b 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/Dog.java b/Dog.java new file mode 100644 index 0000000..a5ce7e3 --- /dev/null +++ b/Dog.java @@ -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); + + + } +} diff --git a/README.md b/README.md index 833cd8b..4656edc 100644 --- a/README.md +++ b/README.md @@ -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(); } } @@ -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.