Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions 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));]
expand button
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
Check Mark
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.

Knowledge Booster
Background pattern image
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
    Recommended textbooks for you
    Text book image
    Database System Concepts
    Computer Science
    ISBN:9780078022159
    Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
    Publisher:McGraw-Hill Education
    Text book image
    Starting Out with Python (4th Edition)
    Computer Science
    ISBN:9780134444321
    Author:Tony Gaddis
    Publisher:PEARSON
    Text book image
    Digital Fundamentals (11th Edition)
    Computer Science
    ISBN:9780132737968
    Author:Thomas L. Floyd
    Publisher:PEARSON
    Text book image
    C How to Program (8th Edition)
    Computer Science
    ISBN:9780133976892
    Author:Paul J. Deitel, Harvey Deitel
    Publisher:PEARSON
    Text book image
    Database Systems: Design, Implementation, & Manag...
    Computer Science
    ISBN:9781337627900
    Author:Carlos Coronel, Steven Morris
    Publisher:Cengage Learning
    Text book image
    Programmable Logic Controllers
    Computer Science
    ISBN:9780073373843
    Author:Frank D. Petruzella
    Publisher:McGraw-Hill Education