diff --git a/.idea/misc.xml b/.idea/misc.xml index 639900d..47478b9 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml index bdef184..496a538 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,6 +3,7 @@ + \ No newline at end of file diff --git a/README.md b/README.md index 833cd8b..13bace0 100644 --- a/README.md +++ b/README.md @@ -10,22 +10,29 @@ 6. All the instance methods for the class **Student** ```java +//i.Class name: Student class Student{ + //ii. Instance variables/fields: String name and int rollNo private String name; private int rollNo; - + //iii. Constructor: Student with parameters(String s, int r) Student(String s, int r) { + /*v. The values of the instance variables are set here they + are set to name="Rambo" and rollNo=21, when obj1 is + created in main. + */ name = s; rollNo = r; } - + //vi. The only instance method for the student class is methodForDisplay(). void methodForDisplay() { System.out.println(name+"'s Roll No: "+rollNo); } public static void main(String[] args) { + //iv. Student object gets created below and named obj1 Student obj1=new Student("Rambo",21); obj1.methodForDisplay(); } @@ -36,6 +43,11 @@ 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 the need of creating an object to call that method, whereas in a public method + you would need to create an object and call the method using that object. For example, if I have a static method called + myData, I would simply need to call it in the main method using myData(); but if I had a nonstatic method called myPublic() + I would need to create the object first in my main method, such as Data obj = new Data(); then type in obj.myPublic(); to call + my nonstatic method within my class, Data, and my object, obj. ## Part 3 - Dogs diff --git a/src/src.iml b/src/src.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/src/src.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/src/Dog.java b/src/src/Dog.java new file mode 100644 index 0000000..20dac00 --- /dev/null +++ b/src/src/Dog.java @@ -0,0 +1,66 @@ +public class Dog{ + private String size; + private String color; + private double age; + private String breed; + private int ran; + + public Dog (String breed, String size, String color, double age){ + this.size=size; + this.color=color; + this.breed=breed; + this.age=age; + } + + private String eat(){ + if(size.equalsIgnoreCase("large")){ + return "This large dog should eat about 3 to 4.5 cups of food per day."; + } + else if (size.equalsIgnoreCase("medium")){ + return "This medium sized dog should eat about 1.75 to 2.67 cups of food per day."; + } + else{ + return "This small sized dog should eat about 0.75 to 1.5 cups of food per day."; + } + + } + + private String run(){ + this.ran=30; + return "This dog needs to run/walk for at least "+ran+" minutes per day."; + } + + //https://www.rover.com/blog/how-much-sleep-do-dogs-need/ + // + private String sleep(){ + if (age<1){ + return "This dog is a puppy and should sleep for an average of 20 hours per day"; + } + if(age<5 && age>1){ + return "A dog of age "+age+" should sleep for an average of 12 to 15 hours per day."; + } + else { + return "This dog of age " + age + " should sleep for an average of 18 hours per day."; + } + } + + private String name(){ + return "The breed of this dog is "+breed+" and of color "+color+"."; + } + + public String toString(){ + return name()+"\n"+sleep()+"\n"+eat()+"\n"+run(); + } + + public static void main(String[] args) { + Dog dog1Object= new Dog("Bulldog", "large","light gray",5); + Dog dog2Object= new Dog("Beagle","large","orange",6); + Dog dog3Object= new Dog("German Shepard","large","white & orange",6); + System.out.println(dog1Object); + System.out.println("\n"+dog2Object); + System.out.println("\n"+dog3Object); + + + + } + }