Question

Write a method called Drawline that accepts as input an integer n and generates a line...

Write a method called Drawline that accepts as input an integer n and generates a line of output in lstOutput with n hyphens. That is, if n = 6 we have a line of ‘------‘ displayed in the list box.

Must be in C#

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Dear Student ,

As per requirement submitted above kindly find below solution.

Here new windows forms application in C# is created using visual studio 2019 with name "SimpleCSharpApp". This application contains a form with name "Form1.cs".Below is the details of this form.

Form1.cs[Design] :

Draw line . x Enter number: 0 Draw Line

**********************************

Form1.cs :

//namespace
using System;
using System.Windows.Forms;
//application namespace
namespace SimpleCSharpApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Drawline button click
private void btnDrawLine_Click(object sender, EventArgs e)
{
//taking number entered by user
int number = int.Parse(txtNumber.Text);
//call method
this.Drawline(number);
}
//method to drawline
public void Drawline(int n)
{
string line = "";//declaring variable to generate line
//using for loop
for (int i = 0; i < n; i++)
{
//concatenate hypens
line = line + "-";
}
//show line in the listbox
lstOutput.Items.Add(line);
}
}
}

==================================

Output :Run application using F5 and will get the screen as shown below

Screen 1:Form1.cs

Draw line . x Enter number: 0 Draw Line

Screen 2:Screen showing line in the list box when a numnber with value 6 is entered

Draw line - O X Enter number: Draw Line

NOTE :PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.

Add a comment
Know the answer?
Add Answer to:
Write a method called Drawline that accepts as input an integer n and generates a line...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Request an integer n from the console. Write a function that accepts n as input and...

    Request an integer n from the console. Write a function that accepts n as input and outputs the multiplication table of n from 1 to n to the console. Example Output (input in bold italics) Enter an integer: 9 1 * 9 = 9 2 * 9 = 18 3 * 9 = 27 4 * 9 = 36 5 * 9 = 45 6 * 9 = 54 7 * 9 = 63 8 * 9 = 72 9...

  • Write a method called inputStats that accepts a Scanner representing an input file and reports the...

    Write a method called inputStats that accepts a Scanner representing an input file and reports the number of lines, the longest line, the number of tokens on each line, and the length of the longest token on each line. If the file contains the following text: Beware the Jabberwock, my son, the jaws that bite, the claws that catch, Beware the JubJub bird and shun the frumious bandersnatch. For the input above, your method should produce the following output: Line...

  • Java problem In this problem, the first input is a positive integer called n that will...

    Java problem In this problem, the first input is a positive integer called n that will represent the number of lines to process. The lines to be processed have one or more integers separated by whitespaces. For each of these lines, you must output: The minimum value of the integers The maximum value of the integers The sum of the integers It is worth to mention that the number of integers of each line is not known a priori and...

  • Write a method called stutter that accepts an ArrayList of strings and an integer k as...

    Write a method called stutter that accepts an ArrayList of strings and an integer k as parameters and that replaces every string with k copies of that string. For example, if the list stores the values ["how", "are", "you?"] before the method is called and k is 4, it should store the values ["how", "how", "how", "how", "are", "are", "are", "are", "you?", "you?", "you?", "you?"] after the method finishes executing. If k is 0 or negative, the list should be...

  • java /* Q2 (10 pts): Write a method called method that accepts an integer parameter *...

    java /* Q2 (10 pts): Write a method called method that accepts an integer parameter * * * * and returns a sum of the first n terms of the sequence. * In other words, the method should generate the following sequence: 1 + 1/2 + 1/3 + 1/4 + ... 1/n * For example, method2(2) will return 1.5 since 1+1/2 = 1.5 * method2 (15) will return 3.3182289932289937 * You may assume that the parameter n is nonnegative. */...

  • In Java Write a method factorial that accepts an integer parameter n and that uses recursion...

    In Java Write a method factorial that accepts an integer parameter n and that uses recursion to compute and return the value of n factorial (also known as n!). Your method should throw an IllegalArgumentException if n is negative. Several calls and their return values are shown below. Call Output factorial(0); 1 factorial(1); 1 factorial(3); 6 factorial(5); 120 factorial(10); 3628800 factorial(-4); IllegalArgumentException

  • in java In a class called DomainParser, write a method getTopLevelDomain that accepts a URL in...

    in java In a class called DomainParser, write a method getTopLevelDomain that accepts a URL in String format then returns the top level domain. Files in the same directory: ComDemo.java Standard Input: google.com Required Output Enter a String\n Top level domain: com\n Standard Input google.co.in Required Output Enter a String\n Top level domain: in\n

  • java Write a program called Copy that accepts the names of an input file and an...

    java Write a program called Copy that accepts the names of an input file and an output file on the command line and copies the contents of the input file to the output file, for example, csc$ java Copy infile.txt outfile.txt

  • Write a program in Python that accepts as input an integer N and a real number...

    Write a program in Python that accepts as input an integer N and a real number c, and outputs the coefficient of the Nth degree term of the Taylor series for the function f(x) = ex centered at c. This process should recur until the user enters a quit code. Erroneous input should be excepted as necessary, and should result in a new prompt.

  • java Program Write a program called Copy that accepts the names of an input file and...

    java Program Write a program called Copy that accepts the names of an input file and an output file on the command line and copies the contents of the input file to the output file, for example, csc$ java Copy infile.txt outfile.txt

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT