Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

//Program.cs using System; namespace Midterm { /// /// Midterm - complete the mi

ID: 3657396 • Letter: #

Question

//Program.cs using System; namespace Midterm { /// /// Midterm - complete the missing pieces. /// The program displays information for two players. /// class Program { /// /// Required Main method to begin the application. /// static void Main() { // Replace John Doe with your name in the line below: Console.WriteLine("CS 201 Midterm - John Doe "); // player1 has been created using the default constructor Player player1 = new Player(); // set player1 properties (his name is Arlo, he's male, his // lot is 150' x 180', and he earned 250 gold coins this year): // create a second player using a non-default constructor // of your choice so that her name is Betty, she's female, // she's a farmer, // her lot is the standard 100' x 130', // and she earned the standard 234 gold pieces. // Call the method below to display results for Arlo: // Call it again to display the results for Betty: // Increase the number of gold coins Arlo has by 25: // Increase the number of gold coins Betty has by 25: // Redisplay the full set of results for each player: // Write a command that will keep the console open // so you can check your results. Copy them into your } // Modify the display results method to accept a player argument. static void DisplayResults() { // Add statements to create a complete set of output // for one player as shown below - make sure the formatting matches // the first set of results for Arlo as shown below. } } } // Replace the following with your complete output: // (not all answers have been included) :-) /* CS 201 Midterm - John Doe The player's name is: Arlo The player's wages are: $25,000 The player's tax due is: $1,750.00 The player's surcharge is: $2,700.00 The player's gender is: M The player's lot size is: 27,000.0 The player's name is: Betty The player's wages are: $23,400 The player's tax due is: The player's surcharge is: The player's gender is: The player's lot size is: The player's name is: Arlo The player's wages are: $27,500 The player's tax due is: The player's surcharge is: The player's gender is: The player's lot size is: The player's name is: Betty The player's wages are: $25,900 The player's tax due is: $1,813.00 The player's surcharge is: $1,300.00 The player's gender is: F The player's lot size is: 13,000.0 */ /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Player.cs using System; namespace Midterm { /// /// Midterm - code the player class as described below. /// class Player { // Private Variables - create 6 variables to hold: // the player's name // the player's gender (either M or F - default to F) // the width of the player's homestead lot in ft (default to 100) // the length of the player's homestead lot in ft (default to 130) // the annual number of gold coins the player earns in a year (default to 234 & use an integer) // is this player a farmer? (e.g. isFarmer) default to yes - the player is a farmer // Define 3 private constant class variables: // Define the current value of a gold coin to be equal to 100 dollars. // Define the king's tax rate to be 7% of annual income. // Define a land surcharge to be 10 cents per square foot. // Public Properties - create 6 public properties // Use accessors & mutators to allow all 6 properties to be retrieved and modified. // Create a seventh public property (read-only!) to provide the annual wages in dollars: // Constructors - the default constructor has been created for you. // Create 2 additional constructors: // One with just the name supplied // One with all inputs supplied public Player() { } // Method 1: // Create a method to calculate the king's tax in dollars given the integer number of coins. // Call the method KingsTaxOwed and return a double. // Since doing it this way won't require any instance variables, make it a class method. // Method 2: // Create a method to calculate land surcharge in dollars without using any arguments. // Call the method SurchargeAssessed and return a double. } }

Explanation / Answer

//player.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Midterm { /// /// Midterm - code the player class as described below. /// class Player { //// Private Variables - create 6 variables to hold: private string Name; // the player's name private char Gender;// the player's gender (either M or F - default to F) private double HomeWidth;// the width of the player's homestead lot in ft (default to 100) private double HomeLength;// the length of the player's homestead lot in ft (default to 130) private int AnnualCoin;// the annual number of gold coins the player earns in a year (default to 234 & use an integer) private bool Farmer;// is this player a farmer? (e.g. isFarmer) default to yes - the player is a farmer // Define 3 private constant class variables: const int GoldToDollar =100;// Define the current value of a gold coin to be equal to 100 dollars. const double KingTax = 0.07;// Define the king's tax rate to be 7% of annual income. const double LandSurcharge = 0.10;// Define a land surcharge to be 10 cents per square foot. // Public Properties - create 6 public properties // Use accessors & mutators to allow all 6 properties to be retrieved and modified. //accessors string getName() { return Name; } char getGender() { return Gender; } double getHomeWidth() { return HomeWidth; } double getHomeLength() { return HomeLength; } int getAnnualCoin() { return AnnualCoin; } bool IsFarmer() { return Farmer; } //mutator void setName(string name) { Name = name; } void setGender(char gender) { Gender = gender ; } void setHomeWidth(double homeWidth) { HomeWidth = homeWidth; } void setHomeLength(double homeLength) { HomeLength = homeLength; } void setAnnualCoin(int annualCoin) { AnnualCoin = annualCoin; } void IsFarmer(bool isfarmer) { Farmer = isfarmer; } // Create a seventh public property (read-only!) to provide the annual wages in dollars: double getWageInDollars() { return GoldToDollar * AnnualCoin;} // Constructors - the default constructor has been created for you. // Create 2 additional constructors: // One with just the name supplied // One with all inputs supplied public Player() { Name="No name"; // the player's name Gender='F';// the player's gender (either M or F - default to F) HomeWidth=100;// the width of the player's homestead lot in ft (default to 100) HomeLength=130;// the length of the player's homestead lot in ft (default to 130) AnnualCoin=234;// the annual number of gold coins the player earns in a year (default to 234 & use an eger) Farmer=true;// is this player a farmer? (e.g. isFarmer) default to yes - the player is a farmer } public Player(string name) { Name = name; Gender = 'F'; HomeWidth = 100; HomeLength = 130; AnnualCoin = 234; Farmer = true; } public Player(string name, char gender, double homeWidth, double homeLength, int annualCoin, bool isfarmer) { Name = name; // the player's name Gender = gender; HomeWidth = homeWidth; HomeLength = homeLength; AnnualCoin = annualCoin; Farmer = isfarmer; } // Method 1: // Create a method to calculate the king's tax in dollars given the integer number of coins. // Call the method KingsTaxOwed and return a double. // Since doing it this way won't require any instance variables, make it a class method. double KingsTaxOwed(int coins) { return KingTax * coins; } // Method 2: // Create a method to calculate land surcharge in dollars without using any arguments. // Call the method SurchargeAssessed and return a double. double SurchargeAssessed() { return LandSurcharge*HomeLength*HomeWidth; } } }