From 235c1c28c9f6fc32ff7f6c0cc3400db1be57f0f5 Mon Sep 17 00:00:00 2001 From: Trevor Hartman <100978684+thartmanoftheredwoods@users.noreply.github.com> Date: Fri, 5 Apr 2024 21:09:06 -0700 Subject: [PATCH 1/3] Update README.md --- Dog.java | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 2 +- Student.java | 26 ++++++++++++++++++++ 3 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 Dog.java create mode 100644 Student.java diff --git a/Dog.java b/Dog.java new file mode 100644 index 0000000..f6df2db --- /dev/null +++ b/Dog.java @@ -0,0 +1,69 @@ +//Dog class +class Dog { + //Private Variables/Fields for Data Members + private String breed; + private String size; + private String color; + private int age; + //Constructor + private boolean isHungry; + + Dog(String breed, String size, String color, int age) { + this.breed = breed; + this.size = size; + this.color = color; + this.age = age; + //Constructor + this.isHungry = true; //Dog is hungry + } + + //Method to /set/ dog's name + void setName(String name) { + this.name = name; + } + + //Method to /get/ dog's name + String getName() { + return name; + } + + //4 Methods for eat, run, sleep, and name + + //Method for dog to eat + void eat() { + if (isHungry) { + System.out.println(getName() + " is eating."); + isHungry = false; //Dog already ate + } else { + System.out.println(getName() + " is not hungry right now."); + } + } + + //Method for dog to run + void run() { + System.out.println(getName() + " is running."); + } + + //Method for dog to sleep + void sleep() { + System.out.println(getName() + " is sleeping."); + } + + //Main Method: Dog objects and their behavior + public static void main(String[] args) { + //Three Dog objects + Dog bulldog = new Dog("Bulldog", "Large", "Light Grey", 5); + bulldog.setName("Buddy"); + + Dog beagle = new Dog("Beagle", "Large", "Orange", 6); + beagle.setName("Max"); + + Dog germanShepherd = new Dog("German Shepherd", "Large", "White and Orange", 6); + germanShepherd.setName("Rocky"); + + //Performing actions on the dogs + bulldog.eat(); + beagle.run(); + germanShepherd.sleep(); + } +} diff --git a/README.md b/README.md index 2a12f11..833cd8b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # Java-Assignment-010 - Classes and Objects ## Part 1 - Analyze -* Add Comments to the Code below and label the following: +* Add Comments to the Code below and label the following using comments: 1. Class name 2. All **instance variables/fields** and their data-types 3. The **Constructor** and the **Constructor Parameters** diff --git a/Student.java b/Student.java new file mode 100644 index 0000000..72f0ace --- /dev/null +++ b/Student.java @@ -0,0 +1,26 @@ +//i. Class name +class Student { + //ii. Instance variables/fields and their data-types + private String name; + private int rollNo; + + //iii. Constructor and the Constructor Parameters + Student(String s, int r) { + //v. Where the instance variables value gets set and what its values are + name = s; + rollNo = r; + } + + //vi. All the instance methods for the class Student + void methodForDisplay() { + System.out.println(name + "'s Roll No: " + rollNo); + } + + //iv. Where a Student object gets created + public static void main(String[] args) { + Student obj1 = new Student("Rambo", 21); //Student object creation + obj1.methodForDisplay(); + } +} + + From 3e493ffc51d1a1efc2887a09c5257e516a5eec0e Mon Sep 17 00:00:00 2001 From: Carma <92554780+dreamdroppin@users.noreply.github.com> Date: Sun, 14 Apr 2024 12:56:40 -0700 Subject: [PATCH 2/3] Update README.md --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 833cd8b..fbaa5b1 100644 --- a/README.md +++ b/README.md @@ -36,8 +36,9 @@ 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. - -## Part 3 - Dogs +* --------------------- +* Public can only be accessed by objects. +* Static can be accsed without needing to creat an object. * View the image below, and from the image, construct a Java file **Dog** that mirrors the diagrammed class and the 3 dog objects. ![Dog Class](images/ClassVSObject.png) From 1cf07394d919c0e7e72d635b1e0a2d0086ae75e7 Mon Sep 17 00:00:00 2001 From: Carma <92554780+dreamdroppin@users.noreply.github.com> Date: Sun, 14 Apr 2024 12:58:58 -0700 Subject: [PATCH 3/3] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index fbaa5b1..908f6fb 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ class Student{ * Public can only be accessed by objects. * Static can be accsed without needing to creat an object. +## 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. ![Dog Class](images/ClassVSObject.png)