Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please do in C#10 if possible. The code needed from a2b_3_your-clid is below. Program.cs namespace a2b_3_C00010458; public class Program { static void Main() { //

image text in transcribedPlease do in C#10 if possible. The code needed from a2b_3_your-clid is below.

Program.cs

namespace a2b_3_C00010458; public class Program { static void Main() { // create three Dirt objects Dirt dirt1 = new Dirt(); Dirt dirt2 = new Dirt(10, 12); Dirt dirt3 = new Dirt(5, 6); Console.WriteLine("Dirt 1 object details: Amount of sand: {0} Amount of clay: {1} ", dirt1.AmountOfSand(), dirt1.AmountOfClay()); Console.WriteLine("Dirt 2 object details: Amount of sand: {0} Amount of clay: {1} ", dirt2.AmountOfSand(), dirt2.AmountOfClay()); Console.WriteLine("Dirt 3 object details: Amount of sand: {0} Amount of clay: {1} ", dirt3.AmountOfSand(), dirt3.AmountOfClay()); // Changing the values of the object Console.WriteLine(" First object after changing values"); dirt1.IncreaseAmountOfSand(); dirt1.DecreaseAmountOfSand(); dirt1.IncreaseAmountOfClay(); Console.WriteLine("Amount of sand: {0} Amount of clay: {1}", dirt1.AmountOfSand(), dirt1.AmountOfClay()); Console.WriteLine(" Decrementing Clay value"); dirt1.DecreaseAmountOfClay(); Console.WriteLine("Amount of sand: {0} Amount of clay: {1}", dirt1.AmountOfSand(), dirt1.AmountOfClay()); Console.WriteLine(" Second object after changing values"); dirt2.IncreaseAmountOfSand(); dirt2.IncreaseAmountOfClay(); Console.WriteLine("Values after incrementing Amount of sand: {0} Amount of clay: {1}", dirt2.AmountOfSand(), dirt2.AmountOfClay()); Console.WriteLine(" Third object after changing values"); dirt3.DecreaseAmountOfSand(); dirt3.DecreaseAmountOfClay(); Console.WriteLine("Amount of sand: {0} Amount of clay: {1}", dirt3.AmountOfSand(), dirt3.AmountOfClay()); } }

Dirt.cs

namespace a2b_3_C00010458; public class Dirt { private double amtOfSand; private double amtOfClay; public void IncreaseAmountOfSand() { amtOfSand += 1; } public void DecreaseAmountOfSand() { if (amtOfSand - 1 >= 0) { amtOfSand -= 1; } } public double AmountOfSand() { return amtOfSand; } public void IncreaseAmountOfClay() { amtOfClay += 1; } public void DecreaseAmountOfClay() { if (amtOfClay - 1 >= 0) { amtOfClay -= 1; } } public double AmountOfClay() { return amtOfClay; } public Dirt() { amtOfSand = 0; amtOfClay = 0; } public Dirt(double amtOfSand, double amtOfClay) { this.amtOfSand = amtOfSand; this.amtOfClay = amtOfClay; } }
Programming Assignment: 1. Create a C# console project in JetBrains Rider or Visual Studio Code and name it a2b_4_your-ulid. The code of the main (default) class in this project project is to be written in the C# 10 Only style (as demonstrated in class and in 01d_RiderBasics.pdf and 01e_VSCBasics.pdf"). When the project runs correctly, clean the project, zip the project folder and upload it to Moodle. 2. Improve project a2b_3_your-clid (as created in assignment a2b_3) as follows: (a) Copy all of your code in a2b_3_your-clid to the new project. Tips: Multiple projects can be open in multiple windows in Rider. To copy a file from one project to another in Rider, right click on the file and select Edit, Copy. In the target project, right click on the namespace in the solution explorer (this is the inner project name) and select Edit, Paste. If a namespace statement in copied file gets flagged, just change it to match the new project name. (b) Remove the constructors from the dirt sample class. (c) Remove all methods (other than the overriding of ToString - if present) in the dirt sample class. (d) Insert two properties into the dirt sample class, one for sand and one for clay. The get of each property returns the associated variable's value. The set of each property changes the associated variable's value by the amount assigned. For instance, if there are 3 grams of clay and the clay property is assigned 5, the result is that there are 8 grams of clay. The value of the associated variables can not be less than zero. Tip: The get of the properties can be written in traditional form with braces and a return, but can also be written in expression-bodied form. The Rider editor will typically assist with a 'fix'offering. (e) Add an expression-bodied method that returns the total grams in the dirt sample, i. e. the sum of clay and sand present. 3. In the code of default class, demonstrate that your dirt sample class can be used as a data type by creating at least three dirt sample class reference variables that reference one each of three unique dirt class objects and use them to demonstrate that each property and the expression bodied method work correctly and that the fields in each object are unique to that object. User input is optional

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Expert Oracle Database Architecture

Authors: Thomas Kyte, Darl Kuhn

3rd Edition

1430262990, 9781430262992

More Books

Students also viewed these Databases questions

Question

The secretary of the club is responsible for:

Answered: 1 week ago

Question

The following identity is correct: 85310=35416 True False

Answered: 1 week ago