Step 2: Create the method specified below.
static int GetValidWidth(string prompt)
Input parameters
prompt: message for user describing the input required
Returns
A non-zero width entered by the user
Step 3: Create the method specified below.
static int GetValidHeight(string prompt)
Input parameters
prompt: message for user describing the input required
Returns
A non-zero positive height entered by the user
Step 4: Create the method specified below.
static void DisplayBox(int width, int height, char fillChar)
Input parameters
width: width of each row of the box
height: number of rows in the box
fillChar: character to draw the box with
Outputs
Displays the specified box and fills it with repetitions of fillChar.
Step 5: From the main() method, prompt and retrieve the width of the box by calling the GetValidWidth(string) method, and the height by calling GetValidHeight(string) using appropriate prompts and then read in a fill character for the box (assume valid input), call the DisplayBox(int,int,char) method to display a filled box.
Step 6: Test your program using the following test plan.
Test Plan |
|||
Test case |
Test Data |
Expected result |
Checked |
Width Height Draw box with |
5 6 % |
%%%%% %%%%% %%%%% %%%%% %%%%% %%%%% |
|
Width Height Draw box with |
10 5 * |
********** ********** ********** ********** ********** |
Coding Requirements
The following coding standards must be followed when developing your program:
The language should be used is Csharpfor the code
Answer = We need to print Box with specific width, height and character specified by user. The program is in "C#" language and comments are shown by "//" operator.
Source Code:
using System.IO;
using System;
// Program class in C#
class Program
{
// Method of class to take width of box
static int GetValidWidth(string prompt){
Console.WriteLine(prompt);
string value=Console.ReadLine();
int width=Convert.ToInt32(value);
return width;
}
// Method to take height of box
static int GetValidHeight(string prompt){
Console.WriteLine(prompt);
string value=Console.ReadLine();
int height=Convert.ToInt32(value);
return height;
}
// Method to display Box on Display
static void DisplayBox(int width, int height, char fillChar){
for (int i = 1; i <= height; i++)
{
for (int j = 1; j <= width; j++)
{
Console.Write(fillChar);
}
Console.WriteLine();
}
}
// Main function
public static void Main()
{
// call method to take width
int width=GetValidWidth("Enter Width of Box: ");
Console.WriteLine(width);
// cal method to take height
int height=GetValidHeight("Enter Height of Box: ");
Console.WriteLine(height);
// take character input to display box
Console.WriteLine("Enter character to draw the box: ");
char fillChar=Console.ReadLine()[0];
Console.WriteLine(fillChar);
// call method to display box
DisplayBox(width,height,fillChar);
}
}
Output:
This is the screenshot of output of above program.
Step 2: Create the method specified below. static int GetValidWidth(string prompt) Input parameters prompt: message for...
How can i print a diamond implementing these methods public static void printNChars(int n, char c)). This method will print n times the character c in a row, public static void printDiamond(int size, char edgeChar, char fillChar). This method will call printNChars() method to print the shape. It will use the edgeChar to print the sides and the fillChar to fill the interior of the shape. The shape will have a height and a width of the given size. public...
I need to create a code for this prompt: In this project we will build a generic UserInput class for getting keyboard input from the user. Implementation: The class UserInput is a 'Methods only' class, and all the methods should be declared static. Look at the TestScanner.java program at the bottom of this page that inputs a string, int and double. It shows you how to use Scanner class to get input from the keyboard. Write FOUR simple methods, one...
public static int countCharacter(String str, char c) { // This recursive method takes a String and a char as parameters and // returns the number of times the char appears in the String. You may // use the function charAt(int i) described below to test if a single // character of the input String matches the input char. // For example, countCharacter(“bobbie”, ‘b’) would return back 3, while // countCharacter(“xyzzy”, ‘y’) would return back 2. // Must be a RECURSIVE...
Write a static method called encodeString that takes a string as input and prints to the console a word where each letter is advanced by one value. In addition, your method should return the encoded String. You may make use of the method provided below to help you. public static char encode(char x) { int current = x; current++; return (char)current; } This method takes a character and returns an "encoded" character. In other words, encode('a') will return 'b'. Your...
Hello Guys. I need help with this its in java In this project you will implement a Java program that will print several shapes and patterns according to uses input. This program will allow the use to select the type (say, rectangle, triangle, or diamond), the size and the fill character for a shape. All operations will be performed based on the user input which will respond to a dynamic menu that will be presented. Specifically, the menu will guide...
JAVA public static String generatePassword(String gp) { String password=""; boolean b= false; for (int i =0;i { char ch = gp.charAt(i); if (i == 0) { password += Character.toUpperCase(ch); } if (ch == 'S' || ch == 's') ...
In this same program I need to create a new method called “int findItem(String[] shoppingList, String item)” that takes an array of strings that is a shopping list and a string for an item name and searches through the “shoppingList” array for find if the “item” exists. If it does exist print a confirmation and return the item index. If the item does not exist in the array print a failure message and return -1. import java.util.Scanner; public class ShoppingList...
Using Java, please create the program for the following prompt. MUST CREATE BUTTONS IN A JFRAME, as specified by the prompt! DO NOT use user input of 1, 2, 3 etc. User input must come from clicking the buttons. Please be sure to test your program. Thank you! Write a program that displays three buttons with the names or images of three candidates for public of office. Imagine that a person votes by clicking the button that shows the candidate...
public static String getFlag(int size, char color1, char color2, char color3) - This method returns a string where a triangle appears on the left size of the diagram, followed by horizontal lines. For example, calling DrawingApp.getFlag(9, 'R', '.', 'Y'); will generate the string: R............................................ RRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRRRYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY RRRRRRRRR.................................... Write a Java program and the result has to match the pattern which showed above.
Methods: Net beans IDE Java two methods. Identifier: calculateScore(String word) Parameters: word – the word for which you should calculate the points in Scrabble Return Value: int – the number of points for the parameter word Other: This method should be static. This method should use the following system for scoring: 0 – blank 1 – e, a, i, o, n, r, t, l, s, u 2 – d, g 3 – b, c, m, p 4 – f, h,...