diff --git a/.idea/misc.xml b/.idea/misc.xml index 639900d..cbbff6a 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..7e08c11 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..88b81bc 100644 --- a/README.md +++ b/README.md @@ -10,24 +10,24 @@ 6. All the instance methods for the class **Student** ```java -class Student{ +class Student{ //class name private String name; private int rollNo; - Student(String s, int r) + Student(String s, int r) //constructor w/ parameter string s and int r { - name = s; - rollNo = r; + name = s; //name is assigned to the variable s + rollNo = r; //rollNo is assigned to the variable r } - void methodForDisplay() + void methodForDisplay()// method { System.out.println(name+"'s Roll No: "+rollNo); } public static void main(String[] args) { - Student obj1=new Student("Rambo",21); - obj1.methodForDisplay(); + Student obj1=new Student("Rambo",21); //new Student object is created + obj1.methodForDisplay();//calls for methodForDisplay method } } ``` @@ -36,6 +36,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. +- In java the static method is particularly useful because it's easy to access later in the program, whereas the public method is more difficult to access without something else in the program . The difference between static and public is that the static method can be used without already having an object in the code and the public method is only useful for existing objects. ## Part 3 - Dogs diff --git a/Work/Work.iml b/Work/Work.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/Work/Work.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Work/src/Dog.java b/Work/src/Dog.java new file mode 100644 index 0000000..b44bc50 --- /dev/null +++ b/Work/src/Dog.java @@ -0,0 +1,68 @@ +/** + * @author Jenny Li + * @Version 1.0 + * @date 4/14/24 + */ +public class Dog { + private String Breed; + private String size; + private String color; + private int age; + + public Dog(String b, String s, String c, int a) { + Breed = b; + size = s; + color = c; + age = a; + } + + static void eat(int Food, int Weight) { + Food = 0; + while (Food < 23) { + System.out.println("eating, eating, eating..."); + Food++; + } + Weight = 90; + if (Food >= 23) { + Weight++; + System.out.println("Has gained" + Weight); + } + + } + void run() { + + } + + static void sleep(int s) { + s = 0; + while (s < 8) { + System.out.println("zzzzz..."); + s++; + } + if (s > 8) { + System.out.println("Has energy"); + } + else { + System.out.println("Is tired"); + } + + } + + void name() { + + } + + public static void main(String[] args) { + 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); + + System.out.println(dog1.Breed + " " + dog1.size + " " + dog1.color + " " + dog1.age); + System.out.println(dog2.Breed + " " + dog2.size + " " + dog2.color + " " + dog2.age); + System.out.println(dog3.Breed + " " + dog3.size + " " + dog3.color + " " + dog3.age); + + eat(23, 2); + sleep(5); + + } +} \ No newline at end of file diff --git a/images/Student.java b/images/Student.java new file mode 100644 index 0000000..eca10cd --- /dev/null +++ b/images/Student.java @@ -0,0 +1,20 @@ +class Student{ + private String name; + private int rollNo; + + Student(String s, int r) + { + name = s; + rollNo = r; + } + + void methodForDisplay() + { + System.out.println(name+"'s Roll No: "+rollNo); + } + + public static void main(String[] args) { + Student obj1=new Student("Rambo",21); + obj1.methodForDisplay(); + } +} \ No newline at end of file