📄 question.txt
字号:
ex8c Drawing Part 1: Drawing Lines
==================================
Introduction
============
This is the second large exercise of the course, which in total is
worth a large percentage of the course. However, this exercise has
been split into three parts of increasing difficulty, full marks can
only be obtained by completing all 3 parts and also submitting the
associated report.
Problem specification
=====================
You are to create a program that can draw lines of a given length using ASCII
characters.
The specification of the lines to be drawn is given below in the description
of the drawLine method.
You are first to display a menu offering the user the following choices:
Main Menu
=========
H) Create Horizontal Line
V) Create Vertical Line
Q) Quit
Enter choice:
If the user selects q, then you are to quit. If the user selects either h or v
then you are to prompt them for the length of the line to be printed:
Enter the length:
if the length entered is less than zero, your program should print the
following error message and then prompt and read another length value in the
same way. For example...
Enter the length: -1
The value of length must be positive!
Enter the length: -5
The value of length must be positive!
Enter the length: 4
when a positive integer is entered you are then to print the line.
If the user enters a value into the menu which is not an option you are to
print the following error message:
That option is not available
and return to the main menu.
In writing the program, you must define and use the following methods
in your solution:
promptAndReadValue( String value )
This repeatedly prompts with "Enter the " followed by the string argument
supplied followed by ": " until a valid positive integer is typed, which it
then returns. Every time a non-valid input is typed it also prints "The value of "
followed by the string argument supplied followed by " must be positive!
drawLine( boolean isHorizontal, int length )
This prints a line of the specified integer length using '+' as the end characters
and '|' or '-' as the middle characters depending on whether the line is horizontal
or vertical respectively. Horizontal lines should be drawn when the isHorizontal
boolean argument is true, otherwise assume the line is vertical.
Examples:
drawLine( true, 5 ) draws the string
+---+
drawLine( true, 2 ) draws the string
++
drawLine( true, 1 ) draws the string
+
drawLine( true, 0 ) draws the string
drawLine( false, 3 ) draws the string
+
|
+
underlinedPrint( String value )
This prints the string argument supplied on one line then underlines this on
the following line with the correct number of '=' characters.
Notes
=====
Constants should be declared as "final" and "static".
Hints
=====
The menu prompt should accept both lower and uppercase characters.
There should be no blank lines in the output, unless a line of length
zero is being printed.
Error conditions
================
If a value which is not 'H', 'h', 'V', 'v', 'Q', or 'q' is entered into
the main menu, you should print the message:
That option is not available
and return to the main menu.
If the value for the length is less than 0, your program should print the
following error message and then prompt and read another length value in the
same way. For example...
Enter the length: -1
The value of length must be positive!
Enter the length: -5
The value of length must be positive!
Enter the length: 4
Typical input/output
====================
For this exercise your program's output should match that shown below, line
for line, character for character!
Main Menu
=========
H) Create Horizontal Line
V) Create Vertical Line
Q) Quit
Enter choice: h
Enter the length: 4
+--+
Main Menu
=========
H) Create Horizontal Line
V) Create Vertical Line
Q) Quit
Enter choice: h
Enter the length: 0
Main Menu
=========
H) Create Horizontal Line
V) Create Vertical Line
Q) Quit
Enter choice: V
Enter the length: 3
+
|
+
Main Menu
=========
H) Create Horizontal Line
V) Create Vertical Line
Q) Quit
Enter choice: a
That option is not available
Main Menu
=========
H) Create Horizontal Line
V) Create Vertical Line
Q) Quit
Enter choice: q
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -