Skip to content

THartmanOfTheRedwoods/Java-Assignment-010

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Java-Assignment-010 - Classes and Objects

Part 1 - Analyze

  • 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
    4. Where a Student object gets created.
    5. Where the instance variables value gets set and what its values are.
    6. All the instance methods for the class Student
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();
    }
}

Part 2 - Public VS Static

  • Read the W3Schools page on class methods: W3Schools Java Class Methods
  • 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

  • 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

  • Your class should be named Dog

  • You should have private instance variables/fields for all the data members.

  • You should have a constructor that sets the initial state of the data members via passed parameters.

    • Think about what data-types the fields and parameters will need!!!
  • You should have 4 instance methods for eat, run, sleep, and name

  • You should have a main method that creates the 3 Dog objects in the diagram.

  • Make at least 2 of your methods functional (i.e. perform some action)!!!

    • For Example: method eat might take a class parameter named Food (i.e. another class) that has a field weight, and your eat method might reduce the weight in Food.

Part 4 - Turn-In

  • Create a feature branch Feature1
  • Commit your code and push it back to your account.
  • Create a Pull request as you have been doing for all assignments.
  • Paste the Pull request URL back into the Canvass assignment page for credit.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors