Create a class to store data C#?
-
I need to write a C# class that has 5 data points, all of which have a default value, and need to store data in each. How would I go about this? Declaring the variables with the default values in them (string animalName = "whiskers"; for example) seems to eliminate the possibility of using an "if" statement, and I can't think of any other way to set default values..... The actual exam question: 1. Write a C# Class that will hold animal data in a file called animal.cs. The class should have appropriate data type of attributes for animal type, breed, color, gender, and cost. There should be attributes, properties, a default constructor that will set the default to “Cat”, “Siamese”, “Seal Point”, “Male”, 5000.00. There should also be a constructor that will accept the parameters to instantiate when needed. You will need to build a method to calculate sales tax of 7.5 percent based on the cost and store that amount in an attribute. 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. My Code so far: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ClassLibrary1 { public class animal { string animalType = "Cat"; string animalBreed = "Siamese"; string animalName = "Seal Point"; string animalGender = "Male"; decimal animalCost = 5000.00m; decimal totalCost; string animalType = Console.ReadLine(); string animalBreed = Console.ReadLine(); string animalName = Console.ReadLine(); string animalGender = Console.ReadLine(); decimal animalCost = Convert.ToDecimal(Console.ReadLine()); decimal totalCost = (animalCost * 1.07); if (string animalGender = "m") { string animalGender = "male"; } else if (string animalGender = "f") { string animalGender = female; } } }
-
Answer:
The class I created should be large that it fits for the Java coding... Good luck!
Deane C at Yahoo! Answers Visit the source
Related Q & A:
- How to construct a class diagram?Best solution by sourcemaking.com
- Why is the size of an empty class not zero in C++?Best solution by geeksforgeeks.org
- Is it correct to extend a bean class and write a class which holds logic to populate the bean we extend?Best solution by stackoverflow.com
- How to dynamically create a PHP class name on the fly?Best solution by stackoverflow.com
- How to store data in php and get data from php?Best solution by Stack Overflow
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.