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.

16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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

Expand Down
11 changes: 11 additions & 0 deletions src/src.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>
66 changes: 66 additions & 0 deletions src/src/Dog.java
Original file line number Diff line number Diff line change
@@ -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);



}
}