#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2013
    Posts
    1
    Rep Power
    0

    Java homework help


    Can anyone please help me with this problem? Thanks

    The Dog Class

    Develop and implement a Dog class for use in an application being developed to support a veterinarian business. You will have two .java files, Dog.java and BillSmill_VetApp.java (where BillSmill is replaced by your name).



    Each of the two files should be in your c:\jwork folder, and should be compiled there. Only the application file will execute (run) using the java command; use of the Dog class file should be accomplished through the execution of the application file.



    Specifications – Dog class



    For the Dog class, create a file similar to the Monster class provided in this unit. A Dog should have the following attributes (instance variables):



    private int breed;

    // breed = 1 means mutt

    // = 2 means terrier

    // = 3 means Irish setter

    // = 4 means Bloodhound

    private String sound;

    // sound can be “ruff”, “arf”,

    // “woof”, and “bow wow”



    The methods for the Dog class should be



    public Dog() // Default constructor

    // initialize breed to 1

    // sound to “ruff”

    // will print out

    // “default constructor”

    public Dog(int b, String s)

    // alternate constructor

    // set breed to b

    sound to s

    // will print out

    // “alternate constructor”

    public int setBreed(int b)

    // parameter will be passed so

    // b will be set to a

    // legal breed

    // will print out “called

    // setBreed” and then print out

    // the new breed value

    public void setSound(String s)

    // parameter will be passed so

    // that s will be set to a

    // “legal” sound

    // will print out “called

    // setSound” and then print out

    // the new sound value



    public void print()

    // will print the current

    // contents of the both

    // instance variables





    Specifications – BillSmill_VetApp application class



    For the BillSmill_VetApp application, the main method should do the following:

    create two Dog objects – it should use both constructors (the initial breed and sound do not matter as long as they are legal) – please check out the constructors provided below in the discussion.

    it should print out each Dog object (using the print method)

    it should change each Dog’s breed (using the setBreed method) – note that it should input the new breed for each dog using the Scanner

    it should print out each Dog object (using the print method)

    it should change each Dog’s sound (using the setSound method) – note that it should input the new sound for each dog using the Scanner and also remember that the sound is of type String

    it should print out each Dog object (using the print method)



    Discussion

    For this lab you will use the example programs provided in the lecture-ettes on the unit 3 CD as models to start with. It is important that you become familiar with these models as you will be using one or the other and sometimes both from here on out to create your programs.



    In the class definition you will need to define at least two user defined constructors. The first constructor should create a dog with default values for both the breed and sound (default constructor) 2, Ruff. The other should handle the creation of a dog with a String parameter passed for both the breed and the sound. What follows is a reasonable example of what the constructors might look like:



    public Dog ( )

    {

    breed = 2;

    sound = “Ruff”;

    {

    public dog (int b, String s)

    {

    breed = b;

    sound = s;

    }





    The user will also need to have the right to change what the breed and sound of their dog is so again they will need access to the private instance variables. To accomplish this you will need to write set access methods for breed and sound.



    Method Headers

    public void setBreed(int b)

    public void setSound(String s)



    The user will need a print method to print the animal defined in the class definition So that it prints in the following manner



    The dog has breed 2 and it goes RUFF



    Method Header

    Public void print()



    You are free to add more content to the lab and create more than 2 dogs but you must accomplish at least the above in order to receive full credit for the lab.



    Remember to insert appropriate comment blocks above each section of code, include your class standard file header to the top of the source code, and to name your file according to the naming convention standard to your class.



    Discussion of application code (BillSmill_VetApp.java)



    While you are creating your main method in the application java file, you might have code similar to:



    Dog f = new Dog();

    // create a new dog and

    // call the default constructor

    Dog g = new Dog(3, “woof”);

    // create a new dog and

    // call the alternate constructor

    // passing it breed = 3 and sound

    // = “woof”

    f.print(); // print out the instance variables

    // Dog f

    g.print(); // print out the instance variables

    // Dog g

    f.setBreed(1); // set f’s breed to the value of 1

    g.setSound(“arf”);

    // set g’s sound to the value of “arf”

    f.print();

    g.print();



    Sample output



    Sample output for the above example code would be similar to:



    default constructor

    alternate constructor

    current Dog has breed = 2 Sound = ruff

    current Dog has breed = 3 Sound = woof

    called setBreed new breed = 1

    called setSound new sound = ruff

    current Dog has breed = 1 Sound = ruff

    current Dog has breed = 3 Sound = arf



    Remember, your main method should input the new breed and sound before using setBreed and setSound to make the changes. This means that your main method will be different from the main method given above and your output may not look exactly the same as the output given above.
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,713
    Rep Power
    348
    Please edit your post and wrap the code in code tags:
    [code]
    >>>>>>> the code here
    [/code]

    What have you tried?

    Can you explain the problems you are having?

IMN logo majestic logo threadwatch logo seochat tools logo