Create a class named GirlScout that containsfields for a GirlScout\'s name, troo
ID: 3618981 • Letter: C
Question
Create a class named GirlScout that containsfields for a GirlScout's name, troopnumber, and dues owed. Include a constant static field that containsthe last words of the GirlScout motto ("to obeythe Girl Scout law"). Include overloaded constructors thatallow you to set all three nonstatic GirlScout fields to defaultvalues or to parameter values. Also include properties foreach field. Create a class named DemoScouts that instantiatestwo GirlScoutobjects and displays their values. Create one object to usethe default constructor and the other to use the constructor thatrequires arguments. Also display the GirlScout motto.Explanation / Answer
using System; using System.Collections.Generic; using System.Text; namespace Test { class DemoScout { static void Main() { GirlScout objScout1 = new GirlScout(); objScout1.Name = "YYYYY"; objScout1.TroopNumber = "1211"; objScout1.DuesOwed = 2111.12; GirlScout objScout2 = new GirlScout("XXX", "232", 123.23); //Displaying Scout 1 Console.WriteLine("Scout 1"); Console.WriteLine("Name : " + objScout1.Name); Console.WriteLine("Troop Number : " +objScout1.TroopNumber); Console.WriteLine("Dues Owed : " +objScout1.DuesOwed); Console.WriteLine("Motto : " + GirlScout.motto); Console.WriteLine(" "); //Displaying Scout 2 Console.WriteLine("Scout 2"); Console.WriteLine("Name : " + objScout2.Name); Console.WriteLine("Troop Number : " +objScout2.TroopNumber); Console.WriteLine("Dues Owed : " +objScout2.DuesOwed); Console.WriteLine("Motto : " + GirlScout.motto); Console.Read(); } } class GirlScout { private string name; private stringtroopNumber; private doubleduesOwed; public static stringmotto = "to obey the Girl Scout law"; public GirlScout() { name = string.Empty; troopNumber = string.Empty; duesOwed = 0.0; } public GirlScout(stringstrName, string strNumber, double dues) { name = strName; troopNumber = strNumber; duesOwed = dues; } public string Name { get { return name; } set { name = value; } } public stringTroopNumber { get { return troopNumber; } set { troopNumber = value; } } public doubleDuesOwed { get { return duesOwed; } set { duesOwed = value; } } } }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.