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.

42 changes: 42 additions & 0 deletions Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
public class Dog {
private String name;
private int age;
private double weight;

public Dog(String name, int age, double weight) {
this.name = name;
this.age = age;
this.weight = weight;
}
public void eat(Food food) {
this.weight += food.getWeight();
food.setWeight(0);
}
public void run() {
}
public void sleep() {
}
public String getName(){
}
public static void main(String[] args) {
Dog dog1 = new Dog("Fido", 5, 20.0);
Dog dog2 = new Dog("Rex", 7, 25.0);
Dog dog3 = new Dog("Spot", 3, 15.0);

Food food = new Food(5);
dog1.eat(food);
}
}
class food {
private double weight;

public Food(double weight){
this.weight = weight;
}
public double getWeight() {
retunr this.weight;
}
public void setWeight(double weight) {
this.weight = weight;
}
}
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,26 @@
6. All the instance methods for the class **Student**

```java
// 1. Class name - Student
class Student{
private String name;
private int rollNo;

// 2. Instance variables/fields and their data-types
private String name; // Instance variable name to data type string
private int rollNo; // Instance variable rollNO to data type int
// 3. Constructor and the constructor parameters
Student(String s, int r)
{
// 5. Where the instance variables value gets set and what its values are
name = s;
rollNo = r;
}

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

public static void main(String[] args) {
// 4. Where a student object gets created
Student obj1=new Student("Rambo",21);
obj1.methodForDisplay();
}
Expand All @@ -36,6 +40,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.
1. Static methods are more of a class itself and they are accessed directly with the class name without the need for a new instance of the class. Public methods are instance methods that belong to each object created from the class.

## Part 3 - Dogs

Expand Down