Write a C# Class that will hold animal data in a file called animal.cs. The clas
ID: 3730817 • Letter: W
Question
Write a C# Class that will hold animal data in a file called animal.cs.
The class should have appropriate data type fields for animal type, breed, color, gender, and cost.
There should be properties for all fields.
Create a default constructor that will set the fields to “Cat”, “Siamese”, “Seal Point”, “Male”, 5000.00. Values match the order of fields above.
Also, build a constructor that will accept the all field values to instantiate when needed.
Add a field to store sales tax. Do not add this field to the constructors built in the instructions above. You will need to build a method to calculate sales tax of 7.5 percent based on the cost and store that amount in the field.
Your gender public property should look for the values “F” or “M” and change the value to “Female” or “Male”.
You do NOT have to create a program that uses this class; only create the class in your Visual Studio project.
Thank you for any help you can provide.
Explanation / Answer
using System;
class Animal {
private string type;
public string Type {
get {
return this.type;
}
set {
this.type = value;
}
}
private string breed;
public string Breed {
get {
return this.breed;
}
set {
this.breed = value;
}
}
private string color;
public string Color {
get {
return this.color;
}
set {
this.color = value;
}
}
private string gender;
public string Gender {
get {
return this.gender;
}
set {
if(value=="F")
this.gender = "Female";
else
this.gender = "Male";
}
}
private double cost;
public double Cost {
get {
return this.cost;
}
set {
this.cost = value;
}
}
private double salesTax;
public Animal(){
type=“Cat”;
breed=“Siamese”;
color=“Seal Point”;
gender=“Male”;
cost=5000.00;
}
public Animal(string t,string b,string c,string g,double co){
type=t;
breed=b;
color=c;
gender=g;
cost=co;
}
public void claculateSalesTax(){
salesTax=cost*7.5/100;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.