using System; using static System.Console; public class SortWords { public static void Main() { SortAndDisplaywords("one"); SortAndDisplaywords("one", "two"); SortAndDisplaywords("five", "ten", "one", "two", "three"); Sort AndDisplayWords ("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"); } public static void SortAndDisplaywords (params string[] words) { } Array.Sort (words); WriteLine(string.Join("", words)); }using System; using static System.Console; public class Sortwords { public static void Main() { SortAndDisplaywords("one"); SortAndDisplaywords("one", "two"); SortAndDisplaywords("five", "ten", "one", "two", "three"); SortAndDisplaywords("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"); public static void SortAndDisplaywords (params string[] words) { Array.Sort (words); WriteLine(string.Join("", words));

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

in C# i need to 

Write a program named SortWords that includes a method named SortAndDisplayWords that accepts any number of words, sorts them in alphabetical order, and displays the sorted words separated by spaces.

Write a Main() to test this function. The SortAndDisplayWords method will be tested with one, two, five, and ten words.

my errors are 

Unit Test  Incomplete

Method

 SortAndDisplayWords sorts and displays one words

Build Status
Build Failed
Build OutputCompilation failed: 5 error(s), 0 warnings
SortWords.cs(18,6): error CS1519: Unexpected symbol `using' in class, struct, or interface member declaration
SortWords.cs(18,14): error CS1519: Unexpected symbol `;' in class, struct, or interface member declaration
SortWords.cs(19,28): error CS1519: Unexpected symbol `;' in class, struct, or interface member declaration
SortWords.cs(20,14): error CS0542: `SortWords.SortWords': member names cannot be the same as their enclosing type
SortWords.cs(3,14): (Location of the symbol related to previous error) SortWords.cs(35,246): error CS1525: Unexpected symbol `end-of-file'
 
Test Contents
[TestFixture]
public class SortWordsOneWordTest
{
   [Test]
   public void SortWordsTest()
{
  using (StringWriter sw = new StringWriter())
{
    Console.SetOut(sw);
    SortWords.SortAndDisplayWords("money");
     string expected = "money";
     Assert.AreEqual(expected, sw.ToString().Trim());
    }
  }
}
 
Unit TestIncomplete

Method SortAndDisplayWords sorts and displays two words

Build Status
Build Failed
Build Output
Compilation failed: 5 error(s), 0 warnings
SortWords.cs(18,6): error CS1519: Unexpected symbol `using' in class, struct, or interface member declaration
SortWords.cs(18,14): error CS1519: Unexpected symbol `;' in class, struct, or interface member declaration
SortWords.cs(19,28): error CS1519: Unexpected symbol `;' in class, struct, or interface member declaration
SortWords.cs(20,14): error CS0542: `SortWords.SortWords': member names cannot be the same as their enclosing type
SortWords.cs(3,14): (Location of the symbol related to previous error) SortWords.cs(35,246): error CS1525: Unexpected symbol `end-of-file'
 
Test Contents
 
[TestFixture]
 
public class SortWordsTwoWordsTest
{
[Test]
public void SortWordsTest()
{
   using (StringWriter sw = new StringWriter())
{
   Console.SetOut(sw);
   SortWords.SortAndDisplayWords("job", "jelly");
   string expected = "jelly job";
   Assert.AreEqual(expected
   }
  }
}
 

Method SortAndDisplayWords sorts and displays ten words

Build Status
Build Failed
Build Output
Compilation failed: 5 error(s), 0 warnings
SortWords.cs(18,6): error CS1519: Unexpected symbol `using' in class, struct, or interface member declaration
SortWords.cs(18,14): error CS1519: Unexpected symbol `;' in class, struct, or interface member declaration
SortWords.cs(19,28): error CS1519: Unexpected symbol `;' in class, struct, or interface member declaration
SortWords.cs(20,14): error CS0542: `SortWords.SortWords': member names cannot be the same as their enclosing type
SortWords.cs(3,14): (Location of the symbol related to previous error) SortWords.cs(35,246):
 
Test Contents
[TestFixture]
public class SortWordsTenWordsTest
{
[Test]
public void SortWordsTest()
{
    using (StringWriter sw = new StringWriter())
    {
       Console.SetOut(sw);
        string[] words = {"magic", "mouse", "lemon", "lime", "monkey", "lucky", "kangaroo",                "lady", "market", "left"};
         
        SortWords.SortAndDisplayWords(words);
        string expected = "kangaroo lady left lemon lime lucky magic market monkey mouse";          Assert.AreEqual(expected, sw.ToString().Trim());
       }
    }
Unit TestIncomplete

Method SortAndDisplayWords sorts and displays five words

Build Status
Build Failed
Build Output
Compilation failed: 5 error(s), 0 warnings
SortWords.cs(18,6): error CS1519: Unexpected symbol `using' in class, struct, or interface member declaration
SortWords.cs(18,14): error CS1519: Unexpected symbol `;' in class, struct, or interface member declaration
SortWords.cs(19,28): error CS1519: Unexpected symbol `;' in class, struct, or interface member declaration
SortWords.cs(20,14): error CS0542: `SortWords.SortWords': member names cannot be the same as their enclosing type
SortWords.cs(3,14): (Location of the symbol related to previous error) SortWords.cs(35,246): error CS1525: Unexpected symbol `end-of-file'
 
Test Contents
[TestFixture]
public class SortWordsFiveWordsTest
{
    using (StringWriter sw = new StringWriter())
     {
        Console.SetOut(sw);
        SortWords.SortAndDisplayWords("goose", "elephant", "frog", "dog", "horse");
        string expected = "dog elephant frog goose horse";
        Assert.AreEqual(expected, sw.ToString().Trim());
      }
    }
 }
my code is in the picture 
using System;
using static System.Console;
public class SortWords
{
public static void Main()
{
SortAndDisplaywords ("one");
SortAndDisplaywords
("one", "two");
Sort AndDisplayWords("five",
"ten", "one", "two", "three");
SortAndDisplayWords ("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten");
}
}
public static void SortAndDisplaywords (params string[] words)
{
Array.Sort (words);
WriteLine(string.Join("", words));
}using System;
using static System.Console;
public class SortWords.
{
public static void Main()
{
SortAndDisplaywords ("one");
SortAndDisplaywords ("one", "two");
SortAndDisplaywords("five",
"ten", "one", "two", "three");
SortAndDisplayWords ("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten");
public static void SortAndDisplaywords (params string[] words)
{
Array.Sort (words);
WriteLine(string.Join("", words));
Transcribed Image Text:using System; using static System.Console; public class SortWords { public static void Main() { SortAndDisplaywords ("one"); SortAndDisplaywords ("one", "two"); Sort AndDisplayWords("five", "ten", "one", "two", "three"); SortAndDisplayWords ("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"); } } public static void SortAndDisplaywords (params string[] words) { Array.Sort (words); WriteLine(string.Join("", words)); }using System; using static System.Console; public class SortWords. { public static void Main() { SortAndDisplaywords ("one"); SortAndDisplaywords ("one", "two"); SortAndDisplaywords("five", "ten", "one", "two", "three"); SortAndDisplayWords ("one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"); public static void SortAndDisplaywords (params string[] words) { Array.Sort (words); WriteLine(string.Join("", words));
Expert Solution
Step 1

Algorithm:

1. Start the program by defining the SortWords class and the Main method.

2. Within the Main method, call the SortAndDisplayWords method four times with different sets of words as arguments.

3. In the SortAndDisplayWords method, sort the words using the Array.Sort method, which sorts the elements in an array in ascending order.

4. bUse the string.Join method to concatenate the sorted words into a single string, separated by spaces.

5. Write the concatenated string to the console using the WriteLine method.

6. End the SortAndDisplayWords method.

7. End the Main method.

8. End the SortWords class.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Random Class and its operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education