1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
BigorU [14]
3 years ago
7

Type (dog, cat, budgie, lizard, horse, etc.) Create a class that keeps track of the attributes above for pet records at the anim

al clinic. Decide what instance variables are needed and their data types. Make sure you use int, double, and String data types. Make the instance variables private. Write 2 constructors, one with no parameters and one with many parameters to initialize all the instance variables. Write accessor (get) methods for each of the instance variables. Write mutator (set) methods for each of the instance variables. In the main method of the Animal Clinic class, create 3 Pet objects by calling their constructors. Then call the accessor methods, mutator methods and toString() methods to test all of your methods.
Computers and Technology
1 answer:
Alenkinab [10]3 years ago
5 0

Answer:

If you did the exercise with two Dog objects, it was a bit boring, right? After all, we have nothing to separate the dogs from each other and no way of knowing, without looking at the source code, which dog produced which bark.

In the previous article, I mentioned that when you create objects, you call a special method called a constructor. The constructor looks like the class name written as a method. For example, for a Dog class, the constructor would be called Dog().

The special thing about constructors is that they are the path to any new object, so they are a great place to call code that initializes an object with default values. Further, the return value from a constructor method is always an object of the class itself, which is why we can assign the return value of the constructor to a variable of the type of class we create.

However, so far, we have not actually created a constructor at all, so how come we can still call that method?

In many languages, C# included, the language gives you a free and empty constructor without you having to do anything. It is implied that you want a constructor; otherwise there would be no way of using the class for anything, so the languages just assume that you have written one.

This invisible and free constructor is called the default constructor, and, in our example, it will look like this:

public Dog(){ }

Notice that this syntax is very similar to the Speak() method we created earlier, except that we do not explicitly return a value nor do we even declare the return type of the method. As I mentioned earlier, a constructor always returns an instance of the class to which it belongs.

In this case, that is the class Dog, and that is why when we write Dog myDog = new Dog(), we can assign the new object to a variable named myDog which is of type Dog.

So let’s add the default constructor to our Dog class. You can either copy the line above or, in Visual Studio, you can use a shortcut: type ctor and hit Tab twice. It should generate the default constructor for you.

The default constructor doesn’t actually give us anything new because it is now explicitly doing what was done implicitly before. However, it is a method, so we can now add content inside the brackets that will execute whenever we call this constructor. And because the constructor runs as the very first thing in an object’s construction, it is a perfect place to add initialization code.

For example, we could set the Name property of our objects to something by adding code such as this:

public Dog()

{

   this.Name = "Snoopy";

}

This example will set the Name property of any new objects to “Snoopy”.

Of course, that’s not very useful because not all dogs are called “Snoopy”, so instead, let us change the method signature of the constructor so that it accepts a parameter.

The parentheses of methods aren’t just there to look pretty; they serve to contain parameters that we can use to pass values to a method. This function applies to all methods, not just constructors, but let’s do it for a constructor first.

Change the default constructor signature to this:

public Dog(string dogName)

This addition allows us to send a string parameter into the constructor, and that when we do, we can refer to that parameter by the name dogName.

Then, add the following line to the method block:

this.Name = dogName;

This line sets this object’s property Name to the parameter we sent into the constructor.

Note that when you change the constructor’s signature, you get a case of the red squigglies in your Program.cs file.When we add our own explicit constructors, C# and .NET will not implicitly create a default constructor for us. In our Program.cs file, we are still creating the Dog objects using the default parameter-less constructor, which now no longer exists.

To fix this problem, we need to add a parameter to our constructor call in Program.cs. We can, for example, update our object construction line as such:

Dog myDog = new Dog(“Snoopy”);

Doing so will remove the red squigglies and allow you to run the code again. If you leave or set your breakpoint after the last code line, you can look at the Locals panel and verify that your object’s Name property has indeed been? Got it?

You might be interested in
Which customers are typical for the Argriculture,Food, and Natural Resources career cluster?
Ahat [919]

Ecosystem developers

8 0
4 years ago
Which command entered without arguments is used to display a list of processes running in the current shell
Talja [164]

Answer:

ps

Explanation:

In Unix and Unix-like operating system, the command used to display the list of processes running in the current shell is ps. For each of these processes, the following details are displayed;

i. <em>PID </em>which indicates the id of the process

ii. <em>TTY </em>which indicates the type of terminal from which the process is running.

iii. <em>TIME</em> which represents the CPU time consumed by the the process and its sub-processes.

iv. <em>CMD</em> which represents the command that runs as the current process.

6 0
3 years ago
What are the major features of React?
marysya [2.9K]

<em>JSX - JavaScript Syntax Extension. JSX is a syntax extension to JavaScript. </em>

<em>Virtual DOM. React keeps a lightweight representation of the “real” DOM in the memory, and that is known as the “virtual” DOM (VDOM)</em>

<em>Performance. ...</em>

<em>Extensions. ...</em>

<em>One-way Data Binding. ...</em>

<em>Debugging. ..</em><em>.</em>

<em>Components. ...</em>

<em>State.</em>

3 0
3 years ago
you have a small network in your business with just a few network devices connected along with 22 linux computers and you want t
alekssr [168]

Answer: traceroute

Explanation: Hope this helps <3

8 0
4 years ago
Write a function that is named times_ten and accepts a number as an argument. When the function is called, it should return the
Stells [14]

It changes a little depending on what programming language you're using, but in C you could say

int times_ten (int num) {

    num = num*10;

    return num;

}

Or, in general terms:

Integer Function times_ten (Integer num)

    Set num = num * 10

    Return num

This is all done assuming the number used as an argument is an integer and that you are returning an integer value, not a decimal. The main thing to notice is that since you have to return a value, you must have two things: a return statement, and a type declaration for the function, otherwise you'll get an error.

4 0
3 years ago
Other questions:
  • Where can you find additional commands to include in menu options?
    12·1 answer
  • What are two methods for playing a slide show from the first slide?
    9·2 answers
  • Within a single program, __________________ allows multiple parts, or threads, to run simultaneously.
    15·1 answer
  • Which of the following is NOT a project management cause of failed projects? (Points : 2) Shortcuts taken during the project
    8·1 answer
  • A(n) ___________ operating system provides process and memory management services that allow two or more tasks, jobs, or program
    6·1 answer
  • Which of the following statements represents a scientific bias?
    15·1 answer
  • Help...! Why might you trace an image<br> A. To edit an image<br> B. To make drawing easier
    14·1 answer
  • Match each career to its various job roles. digital media coordinator digital media specialist photographer sound producer creat
    13·1 answer
  • If Jake wants to find out if the size of a fruit has any effect on the total sales for the week of that particular fruit, what c
    15·1 answer
  • Based on the following quote from Leonardo Da Vinci, what would be his definition of a fine artist? “Principles for the Developm
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!