From 675f76913ca15472f71ce6eea108bc8e3ad90198 Mon Sep 17 00:00:00 2001 From: Jaime Ortiz Date: Sun, 14 Apr 2024 20:05:53 -0700 Subject: [PATCH] assignment010 finished --- .idea/misc.xml | 2 +- Main.java | 42 ++++++++++++++++++++++++++++++++++++++++++ README.md | 13 +++++++++---- 3 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 Main.java 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/Main.java b/Main.java new file mode 100644 index 0000000..d539030 --- /dev/null +++ b/Main.java @@ -0,0 +1,42 @@ +public class Dog { + private String name; + private int age; + private double weight; + + public Dog(String name, int age, double weight) { + this.name = name; + this.age = age; + this.weight = weight; + } + public void eat(Food food) { + this.weight += food.getWeight(); + food.setWeight(0); + } + public void run() { + } + public void sleep() { + } + public String getName(){ + } + public static void main(String[] args) { + Dog dog1 = new Dog("Fido", 5, 20.0); + Dog dog2 = new Dog("Rex", 7, 25.0); + Dog dog3 = new Dog("Spot", 3, 15.0); + + Food food = new Food(5); + dog1.eat(food); + } +} +class food { + private double weight; + + public Food(double weight){ + this.weight = weight; + } + public double getWeight() { + retunr this.weight; + } + public void setWeight(double weight) { + this.weight = weight; + } +} \ No newline at end of file diff --git a/README.md b/README.md index 833cd8b..63863a3 100644 --- a/README.md +++ b/README.md @@ -10,22 +10,26 @@ 6. All the instance methods for the class **Student** ```java +// 1. Class name - Student class Student{ - private String name; - private int rollNo; - + // 2. Instance variables/fields and their data-types + private String name; // Instance variable name to data type string + private int rollNo; // Instance variable rollNO to data type int + // 3. Constructor and the constructor parameters Student(String s, int r) { + // 5. Where the instance variables value gets set and what its values are name = s; rollNo = r; } - + // 6. Instance methods for the class Student void methodForDisplay() { System.out.println(name+"'s Roll No: "+rollNo); } public static void main(String[] args) { + // 4. Where a student object gets created Student obj1=new Student("Rambo",21); obj1.methodForDisplay(); } @@ -36,6 +40,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. +1. Static methods are more of a class itself and they are accessed directly with the class name without the need for a new instance of the class. Public methods are instance methods that belong to each object created from the class. ## Part 3 - Dogs