Question

In: Computer Science

Create an application named ShirtDemo that declares several Shirt objects and includes a display method to...

Create an application named ShirtDemo that declares several Shirt objects and includes a display method to which you can pass different numbers of Shirt objects in successive method calls.

The Shirt class contains auto-implemented properties for a Material, Color, and Size (all of type string).

Here is my code:

//Program.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ShirtApplication

{

    class Program

    {

        static void Main(string[] args)

        {


            //Create an instance of Shirt

            Shirt shirt = new Shirt("cotton", "white", "L");

            //print heading

            Console.WriteLine("{0,-12}{1,10}{2,10}", "Material", "Color","Size");

            //call display method

            display(shirt);

            //Create an instance of Shirt

            shirt = new Shirt("cotton", "blue", "XL");

            //call display method

            display(shirt);

            //Create an instance of Shirt

            shirt = new Shirt("polyester", "pink", "M");

            //call display method

            display(shirt);

            Console.WriteLine();

            Console.WriteLine("{0,-12}{1,10}{2,10}", "Material", "Color", "Size");

            //Create an instance of Shirt

            shirt = new Shirt("cotton", "white", "L");

            //call display method

            display(shirt);

            //Create an instance of Shirt

            shirt = new Shirt("cotton", "blue", "XL");

            //call display method

            display(shirt);

            //Create an instance of Shirt

            shirt = new Shirt("polyester", "pink", "M");

            //call display method

            display(shirt);

            //Create an instance of Shirt

            shirt = new Shirt("silk", "yellow", "S");

            //call display method

            display(shirt);

            Console.WriteLine();

            Console.WriteLine("{0,-12}{1,10}{2,10}", "Material", "Color", "Size");

            //Create an instance of Shirt

            shirt = new Shirt("cotton", "white", "L");

            //call display method

            display(shirt);

            //Create an instance of Shirt

            shirt = new Shirt("cotton", "blue", "XL");

            //call display method

            display(shirt);

            shirt = new Shirt("polyester", "pink", "M");

            //call display method

            display(shirt);

            //Create an instance of Shirt

            shirt = new Shirt("silk", "yellow", "S");

            display(shirt);

            shirt = new Shirt("silk", "white", "XXL");

            //call display method

            display(shirt);

            Console.ReadKey();

        }


        //The metod display that takes Shirt object and prints the properties of shirt object

        //to console

        public static void display(Shirt shirt)

        {

            Console.WriteLine("{0,12}{1,10}{2,10}", shirt.Material, shirt.Color, shirt.Size);

        }

    }

}

here is the error message:

Unable to instantiate shirt objects with the correct properties.

Checks

Unit TestIncomplete

Shirt class is defined and can be instantiated

Build Status

Build Failed

Build Output

Compilation failed: 1 error(s), 0 warnings

ShirtDemo.cs(77,36): error CS0246: The type or namespace name `Shirt' could not be found. Are you missing an assembly reference?

Test Contents

[TestFixture]
public class ShirtClassTest
{
  [Test]
  public void Shirt()
  {
    Shirt shirt1 = new Shirt();
    shirt1.Material = "cotton";
    shirt1.Color = "Green";
    shirt1.Size = "Large";

    Shirt shirt2 = new Shirt();
    shirt2.Material = "polyester";
    shirt2.Color = "red";
    shirt2.Size = "small";

    Assert.AreEqual("cotton", shirt1.Material);
    Assert.AreEqual("Green", shirt1.Color);
    Assert.AreEqual("Large", shirt1.Size);
    Assert.AreEqual("polyester", shirt2.Material);
    Assert.AreEqual("red", shirt2.Color);
    Assert.AreEqual("small", shirt2.Size);
  }
}

Unit TestIncomplete

Get and set the Material property of the Shirt object, test 1

Build Status

Build Failed

Build Output

Compilation failed: 1 error(s), 0 warnings

ShirtDemo.cs(77,36): error CS0246: The type or namespace name `Shirt' could not be found. Are you missing an assembly reference?

Test Contents

[TestFixture]
public class ShirtClassTest
{
  [Test]
  public void Shirt()
  {
    Shirt shirt1 = new Shirt();
    shirt1.Material = "cotton";

    Shirt shirt2 = new Shirt();
    shirt2.Material = "polyester";

    Assert.AreEqual("cotton", shirt1.Material, "Unable to set or get the `Material` property of the class `Shirt`");
    Assert.AreEqual("polyester", shirt2.Material, "Unable to set or get the `Material` property of the class `Shirt`");

  }
}

Unit TestIncomplete

Get and set the Color property of the Shirt class, test 2

Build Status

Build Failed

Build Output

Compilation failed: 1 error(s), 0 warnings

ShirtDemo.cs(77,36): error CS0246: The type or namespace name `Shirt' could not be found. Are you missing an assembly reference?

Test Contents

[TestFixture]
public class ShirtClassTest
{
  [Test]
  public void Shirt()
  {
    Shirt shirt1 = new Shirt();
    shirt1.Color = "Green";

    Shirt shirt2 = new Shirt();
    shirt2.Color = "red";

    Assert.AreEqual("Green", shirt1.Color, "Unable to set or get the `Color` property of the class `Shirt`");
    Assert.AreEqual("red", shirt2.Color, "Unable to set or get the `Color` property of the class `Shirt`");

  }
}

Unit TestIncomplete

Get and set the Size property of the Shirt class, test 3

Build Status

Build Failed

Build Output

Compilation failed: 1 error(s), 0 warnings

ShirtDemo.cs(77,36): error CS0246: The type or namespace name `Shirt' could not be found. Are you missing an assembly reference?

Test Contents

[TestFixture]
public class ShirtClassTest
{
  [Test]
  public void Shirt()
  {
    Shirt shirt1 = new Shirt();
    shirt1.Size = "Large";

    Shirt shirt2 = new Shirt();
    shirt2.Size = "small";


    Assert.AreEqual("Large", shirt1.Size, "Unable to set or get the `Size` property of the class `Shirt`");
    Assert.AreEqual("small", shirt2.Size, "Unable to set or get the `Size` property of the class `Shirt`");
  }
}

0.00 out of 10.00

Display method defined

2

0 out of 2 checks passed. Review the results below for more details.

Checks

Unit TestIncomplete

Display method displays all shirt properties, test 1

Build Status

Build Failed

Build Output

Compilation failed: 2 error(s), 0 warnings

NtTest2202f400.cs(6,14): error CS0246: The type or namespace name `ShirtDemo' could not be found. Are you missing an assembly reference?
ShirtDemo.cs(77,36): error CS0246: The type or namespace name `Shirt' could not be found. Are you missing an assembly reference?

Test Contents

[TestFixture]
public class ShirtClassDisplayTest
{
  [Test]
  public void ShirtTest1()
  {
    using (StringWriter sw = new StringWriter())
    {
      Console.SetOut(sw);

      Shirt shirt1, shirt2, shirt3;
      shirt1 = new Shirt();
      shirt2 = new Shirt();
      shirt3 = new Shirt();

      shirt1.Material = "cotton";
      shirt1.Color = "white";
      shirt1.Size = "L";
      shirt2.Material = "cotton";
      shirt2.Color = "blue";
      shirt2.Size = "XL";
      shirt3.Material = "polyester";
      shirt3.Color = "pink";
      shirt3.Size = "M";

      Display(shirt1, shirt2, shirt3);

      StringAssert.Contains("cotton", sw.ToString());
      StringAssert.Contains("white", sw.ToString());
      StringAssert.Contains("L", sw.ToString());
      StringAssert.Contains("blue", sw.ToString());
      StringAssert.Contains("XL", sw.ToString());
      StringAssert.Contains("polyester", sw.ToString());
      StringAssert.Contains("pink", sw.ToString());
      StringAssert.Contains("M", sw.ToString());

      Assert.IsFalse(sw.ToString().Contains("silk"), "Output should not contain `silk`");
      Assert.IsFalse(sw.ToString().Contains("yellow"), "Output should not contain `yellow`");
    }
  }
}

Unit TestIncomplete

Display method displays all shirt properties, test 2

Build Status

Build Failed

Build Output

Compilation failed: 2 error(s), 0 warnings

NtTestfc79b0ec.cs(6,14): error CS0246: The type or namespace name `ShirtDemo' could not be found. Are you missing an assembly reference?
ShirtDemo.cs(77,36): error CS0246: The type or namespace name `Shirt' could not be found. Are you missing an assembly reference?

Test Contents

[TestFixture]
public class ShirtClassDisplayTest
{
  [Test]
  public void ShirtTest2()
  {
    using (StringWriter sw = new StringWriter())
    {
      Console.SetOut(sw);

      Shirt shirt1, shirt2, shirt3, shirt4;
      shirt1 = new Shirt();
      shirt2 = new Shirt();
      shirt3 = new Shirt();
      shirt4 = new Shirt();

      shirt1.Material = "cotton";
      shirt1.Color = "white";
      shirt1.Size = "L";
      shirt2.Material = "cotton";
      shirt2.Color = "blue";
      shirt2.Size = "XL";
      shirt3.Material = "polyester";
      shirt3.Color = "pink";
      shirt3.Size = "M";
      shirt4.Material = "silk";
      shirt4.Color = "yellow";
      shirt4.Size = "S";

      Display(shirt1, shirt2, shirt3, shirt4);

      StringAssert.Contains("cotton", sw.ToString());
      StringAssert.Contains("white", sw.ToString());
      StringAssert.Contains("L", sw.ToString());
      StringAssert.Contains("blue", sw.ToString());
      StringAssert.Contains("XL", sw.ToString());
      StringAssert.Contains("polyester", sw.ToString());
      StringAssert.Contains("pink", sw.ToString());
      StringAssert.Contains("M", sw.ToString());
      StringAssert.Contains("silk", sw.ToString());
      StringAssert.Contains("yellow", sw.ToString());
      StringAssert.Contains("S", sw.ToString());
    }
  }
}

Solutions

Expert Solution

Code:-

/// Program.cs ///

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ShirtApplication
{
    class Program
    {
        static void Main(string[] args)
        {
            Shirt shirt = new Shirt("cotton", "white", "L");
            Console.WriteLine("{0,-12}{1,10}{2,10}", "Material", "Color","Size");
            display(shirt);
            shirt = new Shirt("cotton", "blue", "XL");
            display(shirt);
            shirt = new Shirt("polyester", "pink", "M");
            display(shirt);
            Console.WriteLine();
            Console.WriteLine("{0,-12}{1,10}{2,10}", "Material", "Color", "Size");
            shirt = new Shirt("cotton", "white", "L");
            display(shirt);
            shirt = new Shirt("cotton", "blue", "XL");
            display(shirt);
            shirt = new Shirt("polyester", "pink", "M");
            display(shirt);
            shirt = new Shirt("silk", "yellow", "S");
            display(shirt);
            Console.WriteLine();
            Console.WriteLine("{0,-12}{1,10}{2,10}", "Material", "Color", "Size");
            shirt = new Shirt("cotton", "white", "L");
            display(shirt);
            shirt = new Shirt("cotton", "blue", "XL");
            display(shirt);
            shirt = new Shirt("polyester", "pink", "M");
            display(shirt);
            shirt = new Shirt("silk", "yellow", "S");
            display(shirt);
            shirt = new Shirt("silk", "white", "XXL");
            display(shirt);
            Console.ReadKey();
        }
        public static void display(Shirt shirt)
        {

            Console.WriteLine("{0,12}{1,10}{2,10}", shirt.Material, shirt.Color, shirt.Size);
        }
    }
}

/// Shirt.cs ///

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ShirtApplication
{
    class Shirt
    {
        public string Material { get; set; }
        public string Color { get; set; }
        public string Size { get; set; }
        public Shirt()
        {
            Material = "";
            Color = "";
            Size = "";
        }
        public Shirt(string material, string color, string size)
        {
            this.Material = material;
            this.Color = color;
            this.Size = size;
        }
    }
}

Code Screenshots:-

Program.cs

Shirt.cs

Output:-

Please UPVOTE thank you...!!!


Related Solutions

Create a class named TestLease whose main() method declares four Lease objects. Call a getData() method...
Create a class named TestLease whose main() method declares four Lease objects. Call a getData() method three times. Within the method, prompt a user for values for each field for a Lease, and return a Lease object to the main() method where it is assigned to one of main()’s Lease objects. Do not prompt the user for values for the fourth Lease object, but let it continue to hold the default values. Then, in main(), pass one of the Lease...
Create a C# program named SalesLetter whose Main() method uses several WriteLine() calls to display a...
Create a C# program named SalesLetter whose Main() method uses several WriteLine() calls to display a sales letter to prospective clients for a business of your choice. Display your contact information at least three times in the letter. The contact information should contain at least three lines with data such as land line phone number and/or cellphone number, email address, and web address.. Each time you want to display the contact information, call a method namedDisplayContactInfo().
Design a Java program named LambdaTester2 which includes a main method that declares a lambda expression...
Design a Java program named LambdaTester2 which includes a main method that declares a lambda expression reference which implements the following interface: interface Multiplier {     int multiply(int num1, int num2); } The program must declare an array of Pair objects (see class specification below), followed by the declaration of an ArrayList which is instantiated using the declared array (the ArrayList stores Pair objects). Then write a loop which iterates through each element of the ArrayList, calls the lambda expression reference...
Create an C# application named ConvertMilesToKilometers whose Main() method prompts a user for a number of...
Create an C# application named ConvertMilesToKilometers whose Main() method prompts a user for a number of miles, passes the value to a method that converts the value to kilometers, and then returns the value to the Main() method where it is displayed.
Create a windows application that contains two TextBox objects and two Button objects. One of the...
Create a windows application that contains two TextBox objects and two Button objects. One of the TextBox objects and one of the buttons are initially invisible. The first textbox should be used to input a password. The textbox should be masked to some character of your choice so that the characters entered by the user are not seen on the screen. When the user clicks the first button, the second TextBox object and button object should be displayed with a...
Instructions Create an application to accept data for an array of five CertOfDeposit objects, and then...
Instructions Create an application to accept data for an array of five CertOfDeposit objects, and then display the data. import java.time.*; public class CertOfDeposit { private String certNum; private String lastName; private double balance; private LocalDate issueDate; private LocalDate maturityDate; public CertOfDeposit(String num, String name, double bal, LocalDate issue) { } public void setCertNum(String n) { } public void setName(String name) { } public void setBalance(double bal) { } public void issueDate(LocalDate date) { } public String getCertNum() { }...
Create a mockup of your web application that will display a list of favorites. Remember, this...
Create a mockup of your web application that will display a list of favorites. Remember, this can be a list of any favorite items, such as books, movies, restaurants, music, and so on. Your web application should contain at least 3 pages (HTML documents). Your mockup should contain mockups of each HTML document. You should follow a similar format as the sample mockup provided here. Your 5-6-page document should include the following: A description of the site's organizational structure. A...
Create an interface named Shippable with a method named getVolume and another named getWeight. Neither has...
Create an interface named Shippable with a method named getVolume and another named getWeight. Neither has parameters and both return a number
Objectives: 1. Create classes to model objects Instructions: 1. Create a new folder named Lab6 and...
Objectives: 1. Create classes to model objects Instructions: 1. Create a new folder named Lab6 and save all your files for this lab into this new folder. 2. You can use any IDE (such as SciTE, NetBeans or Eclipse) or any online site (such as repl.it or onlinegdb.com) to develop your Java programs 3. All your programs must have good internal documentation. For information on internal documentation, refer to the lab guide. Problems [30 marks] Problem 1: The Account class...
Objectives: 1. Create classes to model objects Instructions: 1. Create a new folder named Lab6 and...
Objectives: 1. Create classes to model objects Instructions: 1. Create a new folder named Lab6 and save all your files for this lab into this new folder. 2. You can use any IDE (such as SciTE, NetBeans or Eclipse) or any online site (such as repl.it or onlinegdb.com) to develop your Java programs 3. All your programs must have good internal documentation. For information on internal documentation, refer to the lab guide. Problem : The Fraction class (Filename: TestFraction.java) Design...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT