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
1 change: 1 addition & 0 deletions .idea/Java-Assignment-010.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.

18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,30 @@
6. All the instance methods for the class **Student**

```java
//class name is student
class Student{
//instance variables named 'name' and it is a String data type
private String name;
//instance variable named 'rollNo' with an integer data type
private int rollNo;

//Constructor named 'Student' with parameter's 's' a String type variable and 'r' an integer
Student(String s, int r)
{
//variable name gets set to parameter of s
name = s;
//variable rollNo gets set to parameter of r
rollNo = r;
}

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

public static void main(String[] args) {
public static void main(String[] args) {//
// Create object Student
Student obj1=new Student("Rambo",21);
// This initiate the settings of the variables
obj1.methodForDisplay();
}
}
Expand All @@ -36,7 +43,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.

```
static methods can be accesed by using the class name and method
, while public instance methods require you to acces them via an object of the class
```
## 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 src/Dog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
public class Dog {
private final String breed;
private final String size;
private final String color;
private final int age;
private final String name;

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

public void eat() {
System.out.println(name + ": is eating.");
}

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

public void sleep() {
System.out.println(name + ": is now sleeping, ZZZZZzzzz");
for (int i = 1; i <= 3; i++) {
System.out.println(i);
}
System.out.println(name + ": is awake now!");
}

public String getName() {
return name;
}

public static void main(String[] args) {
Dog dog1 = new Dog("Bulldog", "large", "light gray", 5, "Buddy");
Dog dog2 = new Dog("Beagle", "large", "orange", 6, "Max");
Dog dog3 = new Dog("German Shepherd", "large", "white & orange", 6, "Rocky");
dog1.eat();
dog2.run();
dog3.sleep();
}
}