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.

29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,27 @@
6. All the instance methods for the class **Student**

```java
class Student{
private String name;
private int rollNo;
class Student{ //class name = Student
//instance variables/fields
private String name; //sting variable that stores students name
private int rollNo; //int variable that stores students roll number

Student(String s, int r)
//Constructor and the Constructor Parameters
Student(String s, int r) //constructor with parameters
{
name = s;
rollNo = r;
name = s; //setter name
rollNo = r; //setter roll number
}

void methodForDisplay()
//Instance method for the class Student
void methodForDisplay() //method that displays students details
{
System.out.println(name+"'s Roll No: "+rollNo);
}

// student object is created
public static void main(String[] args) {
Student obj1=new Student("Rambo",21);
obj1.methodForDisplay();
Student obj1=new Student("Rambo",21); // creating student object
//the instance variables get set and where its values are
obj1.methodForDisplay(); //values assigned with the object while being created. Method that gets called to display students details.
}
}
```
Expand All @@ -37,6 +40,10 @@ 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 is a method that can be accessed without creating an object of the class.

Public method can only be accessed by objects.

## 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
44 changes: 44 additions & 0 deletions images/Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@

public class Dog {

private String name;
private String breed;
private in age;
private String size;
private boolean isHungry;

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

void eat(String food) {
System.out.println(name + " is eating " + food + ".");
isHungry = false;
}

void run() {
System.out.println(name + " is running.");
}

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

public static void main(String[] args) {
Dog dog1 = new Dog("Ripjaw", "Bulldog", 5, "Large");
Dog dog2 = new Dog("Updog", "Beagle", 6, "Large");
Dog dog3 = new Dog("Billy", "German Shepherd", 6, "Large");

dog1.eat("Dog Food");
dog2.run();
dog3.sleep();
}

}