Question

In: Computer Science

In C# please Exercise #4: Create a two (2) instances of the “Dog” class in your...

In C# please

Exercise #4:

Create a two (2) instances of the “Dog” class in your “Main” method. One will be created using the default constructor and the other should be made using the overloaded constructor. That means that you should pass the overloaded constructor arguments that come from user input.

Print out each of the dog’s three attributes using the accessors. Then call the “UpdateBark” method for both and print out their fields again, but this time through the “ToString” method.

Example (blue is default dog’s attributes, green is the user’s dog’s):

Creating a default dog…

Finished creating a default dog!

Default dog bark sound is Yelp!

Default dog size is 20 inches.

Default dog’s cuteness is cute dog.

Continued on third page…

Please enter the sound of your dog’s bark: “MOOOOOO!”

Please enter the size of your dog: “10”

Please enter the cuteness of your dog: “ugly dog.”

Your dog bark sound is MOOOOOO!

Your dog size is 10 inches.

Your dog’s cuteness is ugly dog.

Both dogs are doing a scary bark! Their cuteness has been affected!

Default dog bark sound is Yelp!

Default dog size is 20 inches.

Default dog’s cuteness is average.

Your dog bark sound is MOOOOOO!

Your dog size is 10 inches.

Your dog’s cuteness is average.

Solutions

Expert Solution

using System;

class Dog
{
   private string barkSound;
   private int size;
   private string cuteness;
  
   public Dog()
   {
       Console.WriteLine("Creating a default dog…");
      
       barkSound = "Yelp!";
       size = 20;
       cuteness = "cute";
       Console.WriteLine("Finished creating a default dog!");

   }
   public Dog(string barkSound,int size,string cuteness)
   {
       this.barkSound = barkSound;
       this.size = size;
       this.cuteness = cuteness;
   }
  
   public string getBarkSound()
   {
       return barkSound;
   }
   public int getSize()
   {
       return size;
   }
   public string getCuteness()
   {
       return cuteness;
   }
  
   public void updateBark()
   {
       cuteness = "average";
   }
   public override string ToString()
   {
       return "dog bark sound is "+getBarkSound()+
       "\ndog size is "+getSize()+" inches."+
       "\ndog’s cuteness is "+getCuteness()+".";
      
   }
  
}
public class Test
{
   public static void Main()
   {
       Dog d1 = new Dog();
      
       Console.WriteLine("Default dog bark sound is "+d1.getBarkSound());
       Console.WriteLine("Default dog size is "+d1.getSize()+" inches.");
       Console.WriteLine("Default dog’s cuteness is "+d1.getCuteness()+" dog.");

       Console.WriteLine("Please enter the sound of your dog’s bark: ");
       string sound = Console.ReadLine();

       Console.WriteLine("Please enter the size of your dog: ");
       int size = Convert.ToInt32(Console.ReadLine());

       Console.WriteLine("Please enter the cuteness of your dog: ");
       string cuteness = Console.ReadLine();
      
       Dog d2 = new Dog(sound,size,cuteness);
       Console.WriteLine("Your dog bark sound is "+d2.getBarkSound());
       Console.WriteLine("Your dog size is "+d2.getSize()+" inches.");
       Console.WriteLine("Your dog’s cuteness is "+d2.getCuteness()+" dog.");
      
       d1.updateBark();
       d2.updateBark();
      
       Console.WriteLine(d1.ToString());
       Console.WriteLine(d2.ToString());
      
   }
}

Output:

Creating a default dog…
Finished creating a default dog!
Default dog bark sound is Yelp!
Default dog size is 20 inches.
Default dog’s cuteness is cute dog.
Please enter the sound of your dog’s bark: MOOOOOO!
Please enter the size of your dog: 10
Please enter the cuteness of your dog: ugly
Your dog bark sound is MOOOOOO!
Your dog size is 10 inches.
Your dog’s cuteness is ugly dog.
dog bark sound is Yelp!
dog size is 20 inches.
dog’s cuteness is average.
dog bark sound is MOOOOOO!
dog size is 10 inches.
dog’s cuteness is average.

Do ask if any doubt. Please up-vote.


Related Solutions

1: Create a class Circle 2: Create two instances of the Circle class 1: Based on...
1: Create a class Circle 2: Create two instances of the Circle class 1: Based on Program 13-1 (see attachment Pr13-1.cpp) in the textbook, create a class name “Circle” with the following declarations (hint: you can use PI=3.14): //Circle class declaration class Circle { private: double radius; public: void setRadius(double); double getRadius() const; double getArea() const; double getPerimeter() const; }; 2: Based on Program 13-2 (see attachment Pr13-2.cpp) in the textbook, create two instances of the Circle class, pizza1 and...
Make Animal an abstract class. Create a Kennel Class Create 2-3 Dog objects Create 2-3 Cat...
Make Animal an abstract class. Create a Kennel Class Create 2-3 Dog objects Create 2-3 Cat objects Put your Dog and Cat objects in an Array of Animals Loop over your Animals and print the animal with Species, Age, and the status of the appropriate vaccines. Using the code below: public class Animal { //Declaring instance variables private int age; private boolean RabiesVaccinationStatus; private String name; private String ownerName; //Zero argumented constructor public Animal() { } //Parameterized constructor public Animal(int...
Challenge: Dog Description: Create a Dog class that contains specified properties and methods. Create an instance...
Challenge: Dog Description: Create a Dog class that contains specified properties and methods. Create an instance of Dog and use its methods. Purpose: This application provides experience with creating classes and instances of objects in C#. Requirements: Project Name: Dog Target Platform: Console Programming Language: C# Documentation: Types and variables (Links to an external site.) (Microsoft) Classes and objects (Links to an external site.) (Microsoft) Enums (Links to an external site.) (Microsoft) Create a class called Dog. Dog is to...
C++ * Program 2:      Create a date class and Person Class.   Compose the date class...
C++ * Program 2:      Create a date class and Person Class.   Compose the date class in the person class.    First, Create a date class.    Which has integer month, day and year    Each with getters and setters. Be sure that you validate the getter function inputs:     2 digit months - validate 1-12 for month     2 digit day - 1-3? max for day - be sure the min-max number of days is validate for specific month...
IN C++!! Exercise #2: Design and implement class Radio to represent a radio object. The class...
IN C++!! Exercise #2: Design and implement class Radio to represent a radio object. The class defines the following attributes (variables) and methods: Assume that the station and volume settings range from 1 to 10. A private variable of type int named station to represent a station number. Set to A private variable of type int named volume to represent the volume setting. Set to 1. A private variable of type boolean named on to represent the radio on or...
C++ Data Structures 4. Write a client function that merges two instances of the Sorted List...
C++ Data Structures 4. Write a client function that merges two instances of the Sorted List ADT using the following specification. MergeLists(SortedType list1, SortedType list2, SortedType& result) Function: Merge two sorted lists into a third sorted list. Preconditions: list1 and list2 have been initialized and are sorted by key using function ComparedTo. list1 and list2 do not have any keys in common. Postconditions: result is a sorted list that contains all of the items from list1 and list2. c. Write...
In C++, there are 4 students that are running for class president. Create three arrays: the...
In C++, there are 4 students that are running for class president. Create three arrays: the candidate’s name, the number of votes the candidate receives, and the candidate’s percentage of the total votes. Your program should be broken down into at least 3 functions: find the total number of votes, calculate values for the percentage each candidate received, and sort the number of votes from highest to lowest. Write the candidate’s name, the total number of votes they received, and...
Exercise 2: Try-Catch Exercise Write a Java code that does the following: Create a class MyClass...
Exercise 2: Try-Catch Exercise Write a Java code that does the following: Create a class MyClass and create three methods myMethod1(), Method2() and Method3(). Invoke Method2() from Method1() and Method3() from Method2(). Write a code that can throw an exception inside myMethod3() and compile: File file=new File("filename.txt"); Scanner sc=new Scanner(file); You will get compilation errors now, as you are not handling a checked exception FileNotFoundException. Declare throws over myMethod3() and myMethod2(). You will need to add throws FileNotFoundException on myMethod()...
In C++ ifdef QUESTION2    /*    2. Create a header and implementation for a class...
In C++ ifdef QUESTION2    /*    2. Create a header and implementation for a class named bottle. bottle objects should be able    to set and get their size in ounces, the type of liquid it contains(as a string), the amount of    liquid it contains and whether they are less than another bottle object(based on the amount    of liquid they contain). Do not comment your code.    */    std::cout << "QUESTION 2: " << std::endl <<...
2. Create two class, a student class, and a course class, take advantage of the codes...
2. Create two class, a student class, and a course class, take advantage of the codes provided in the class slides and sample codes. python Student Course __Username:str __Courses:list __courseName:str __students: list addCourse():None dropCourse():None getCourse():list addStudent:None dropStudent:None getStudents():list getNumber of students:int 3. Create a student object for every student in the UD.txt (you can use a loop for this) 4. Create 6 course objects: 1. CS131 2. CS132 3. EE210 4. EE310 5. Math320 6. Math220 5. After the student...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT