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.

1 change: 1 addition & 0 deletions .idea/modules.xml

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

15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
```
Expand All @@ -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

Expand Down
11 changes: 11 additions & 0 deletions Work/Work.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
68 changes: 68 additions & 0 deletions Work/src/Dog.java
Original file line number Diff line number Diff line change
@@ -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);

}
}
20 changes: 20 additions & 0 deletions images/Student.java
Original file line number Diff line number Diff line change
@@ -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();
}
}