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]
2 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]2 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
What is the following file format called? inv_nbr, inv_name, inv_cost 876521,battery,45.00
kiruha [24]

The  following file format of  inv_nbr, inv_name, inv_cost is called delimited format.

<h3>What is a delimited file in Excel?</h3>

The term "Delimited" is known to be a term that connote a form of  an  TXT file that tends to make use of tabs or an  CSV file that uses commas to  be able to separate and group your data.

Note also that a  delimited file is seen as a form of a given sequential file that is made up of column delimiters.

Therefore, The  following file format of  inv_nbr, inv_name, inv_cost is called delimited format.

Learn more about text format from

brainly.com/question/16397886

#SPJ1

Multiple Choice

fixed-width format

extensible markup

delimited format

hypertext format

6 0
1 year ago
Atheel tests a program and gets a NameError. How can this be fixed?
Oksana_A [137]

Answer:

You can't call a function unless you've already defined it. Move the def createDirs(): block up to the top of your file, below the imports.

Explanation:

Some languages allow you to use functions before defining them. For example, javascript calls this "hoisting". But Python is not one of those languages.

7 0
3 years ago
Read 2 more answers
Which phrase best describes a scenario in Excel 2016?
Airida [17]

Answer:

what are the phrases?

Explanation:

6 0
3 years ago
In the maintenance phase of the waterfall model, the parts of a program are brought together into a smoothly functioning whole,
vivado [14]

Answer:

False

Explanation:

The maintenance phase of the waterfall model for software development involves making changes to the entire system or some parts of it for improved performance. Integration and testing is the step at which  all units developed at the implementation stage are brought together to form a whole functioning system. At this stage, the system is constantly checked for proper functionality so it can be deployed.

7 0
3 years ago
for java ?(Business: check ISBN-13)ISBN-13 is a new standard for identifying books. It uses 13 digits d1d2d3d4d5d6d7d8d9d10d11d1
ludmilkaskok [199]

Answer:

In Java:

import java.util.*;

public class Main{

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 String isbn;

 System.out.print("First 1:2 digits: ");

 isbn = input.nextLine();

 if(isbn.length()==12){

 int chksum = 0;

 for(int i = 0; i<12;i++){

     if((i+1)%2==0){      chksum+= 3 * Character.getNumericValue(isbn.charAt(i));          }

     else{          chksum+=Character.getNumericValue(isbn.charAt(i));          }  }

 chksum%=10;

 chksum=10-chksum;

 if(chksum==10){

 System.out.print("The ISBN-13 number is "+isbn+"0");}

 else{

 System.out.print("The ISBN-13 number is "+isbn+""+chksum);          }   }

 else{

     System.out.print("Invalid Input");

 }     }}

Explanation:

See attachment for explanation where comments are used to explain each line

Download txt
6 0
3 years ago
Other questions:
  • What are the example of dedicated computers?
    5·1 answer
  • Is anyone else experiencing the wording::nonifacation::glitch about the "5 hours ago" thingy to whenever you answer a question o
    7·2 answers
  • You use Cat5e twisted pair cable on your network. Cables are routed through walls and the ceiling. A user puts a screw in the wa
    9·1 answer
  • How does this app work?
    11·2 answers
  • What is hyper transport
    10·1 answer
  • As Juan sat in his biology lab, his instructor was droning on about the techniques of vivisection. Juan kept thinking about the
    5·1 answer
  • To add a new kind of information into the database you need to add a new table<br> true or false?
    7·2 answers
  • Whats the flow in this code, and whats the risk that its creating and what can i do to fix it? (c language)
    10·1 answer
  • How does a security information and event management system (SIEM) in a SOC help the personnel fight against security threats
    13·1 answer
  • What are 2 ways to send a message to your client when signed in as an accountant user?.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!