107k views
2 votes
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).

User Rebeling
by
3.3k points

2 Answers

0 votes

Final answer:

An example of how to create an application in C# that declares and uses Shirt objects with auto-implemented properties, and includes a display method.

Step-by-step explanation:

The question is asking to create an application named ShirtDemo that declares and uses several Shirt objects. The Shirt class should have auto-implemented properties for Material, Color, and Size, all of which are of type string. The application should also include a display method that can accept different numbers of Shirt objects. Here is an example of how you can implement the Shirt class and the ShirtDemo application in C#:

public class Shirt
{
public string Material { get; set; }
public string Color { get; set; }
public string Size { get; set; }
}

public class ShirtDemo
{
public void Display(params Shirt[] shirts)
{
foreach (var shirt in shirts)
{
Console.WriteLine($"Material: {shirt.Material}, Color: {shirt.Color}, Size: {shirt.Size}");
}
}
}

public class Program
{
public static void Main()
{
Shirt shirt1 = new Shirt { Material = "Cotton", Color = "Blue", Size = "M" };
Shirt shirt2 = new Shirt { Material = "Polyester", Color = "Red", Size = "L" };
Shirt shirt3 = new Shirt { Material = "Silk", Color = "Black", Size = "S" };

ShirtDemo shirtDemo = new ShirtDemo();
shirtDemo.Display(shirt1, shirt2);
shirtDemo.Display(shirt3);
}
}

User Joakim Karlsson
by
3.7k points
1 vote

Final answer:

The ShirtDemo application is a program that demonstrates the use of a Shirt class to declare and display multiple instances of Shirt objects.

Step-by-step explanation:

The student's question pertains to writing a Java application, specifically, the creation of a program called ShirtDemo. This program should include a Shirt class with auto-implemented properties such as Material, Color, and Size, all of string type. Additionally, a display method is needed to output the properties of the Shirt objects. Here is an example of how one might define the Shirt class and the display method:

public class Shirt {
public String Material { get; set; }
public String Color { get; set; }
public String Size { get; set; }
}

public class ShirtDemo {
public static void display(Shirt... shirts) {
for(Shirt shirt : shirts) {
System.out.println("Shirt Material: " + shirt.Material);
System.out.println("Shirt Color: " + shirt.Color);
System.out.println("Shirt Size: " + shirt.Size);
}
}

public static void main(String[] args) {
// Declare Shirt objects
// Call display method with different number of Shirt objects
}
}

The display method can accept a variable number of Shirt objects, thanks to the use of varargs in Java. After declaring Shirt objects in the main method, the display method can be called multiple times with different numbers of shirts.

User Mike Mazur
by
3.7k points