首页
编程语言
数据库
网络开发
Algorithm算法
移动开发
系统相关
金融统计
人工智能
其他
首页
>
> 详细
CSCI 1130A/B辅导、讲解Java设计、辅导Engineering、Java辅导 辅导R语言编程|辅导留学生 Statistic
CSCI 1130A/B Introduction to Computing Using Java 2018-2019 First Term
Department of Computer Science and Engineering
The Chinese University of Hong Kong
Assignment 4: Encoding ASCII Art
Due date: 7 November 2018 (Wed) Full mark: 100
Expected normal time spent on Tasks 1 and 2: 8-10 hours
Task 3: hours
Aims: 1. To encode and decode pictures of ASCII art using run-length encoding.
2. Practise reading/writing text files.
3. Practise the use of String and related methods.
BACKGROUND
ASCII Arts
ASCII stands for American Standard Code for Information Interchange. It is a character encoding standard
for electronic communication. The character set consists of 95 printable characters together with other special
non-printable characters, making up a total of 128 characters in the standard 7-bit ASCII code.
ASCII art is a graphic design technique that uses printable ASCII characters to create pictures. It is in
general regarded as text-based visual art. ASCII art was invented at around 1966. It is mainly because early
printers often lacked graphics ability. Therefore, characters were used in place of graphic marks. Below is the
picture of a building making up with ASCII characters.
.
. |~~ .
. ___|___ .
((((())))
. (((((())))) .
|-------------|
+ I_I_I_I_I_I_I_I_I +
(() |---------------| (()
|---| ||-| |-| |-| |-|| |---|
_________|-----|_|---------------|_|-----|_________
I_I_I_I_I_I_I_I|I_I_I_I_I_I_I_I_I_I|I_I_I_I_I_I_I_|
|-------|------|-------------------|------|-------|
||-| |-|| |-| ||-| |-| |-| |-| |-|| |-| ||-| |-||
((|-------|------|-------------------|------|-------|))
()| |_| | |_| |::::: ------- :::::| |_| | |_| |()
))| |_| | |_| | |_| |_.-"-._| |_| | |_| | |_| |((
()|-------|------| |_| | | | | | |_| |------|-------|()
@@@@@@@@@@@@@@@@@|-----|_|_|_|_|-----|@@@@@@@@@@@@@@@@@
@@@@/=============\@@@@
/ \
Source: www.asciiworld.com
Run-length Encoding
Run-length encoding (RLE) is one of the simplest form of lossless data compression. A sequence of data in
which the same data value occurs in many consecutive data elements are stored as a single pair of data value
and count instead of the original form. It is quite effective in compressing data that contains frequent
repetitions and repeated patterns, for example, the ACSII art described above. 2
PROBLEM DEFINITION
In this assignment, you are required to write some classes to encode ASCII art and decode the compressed
ASCII art file.
Task 1: Encoding a text file containing a picture of ASCII art (50%)
To encode the file, you need to open and read the text file line-by-line. Then you need to figure out whether
there are any occurrences of consecutive elements on each single line.
Example 1:
The original line
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ | - - - - - | _ | _ | _ | _ | - - - - - | @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
The encoded line
1 7 @ 1 | 5 – 1 | _ | _ | _ | _ | 5 – 1 | 1 7 @
Syntax of the encoded line
character(s)> … repeats until the end of line.
The encoded lines are written to a new text file for output. The positive integer denotes the number of times
that the succeeding character(s) is repeated in the original line. There is a space between the positive integer
and the character pattern. The line continues until the end of the input line is reached.
If the positive integer equals 1, the length of the succeeding ASCII character pattern can be larger than
or equal to 1. If the positive integer is greater than 1, the length of the succeeding pattern should be 1 in
this task.
As spaces are used as the delimiter in the encoded file, we here use negative integers to encode spaces in the
original file. Whenever you encounter spaces in the original line, you are required to write a negative integer
in the encoded file. For N spaces, the integer written is -N.
Example 2:
The original line
. ( ( ( ( ( ( ) ) ) ) )
The encoded line
- 1 0 1 . - 1 1 6 ( 5 )
Syntax of the encoded line
character(s)>
3
There are 10 spaces at the beginning of the original line. Then, a '.' appears. After that, we have 11 spaces. It
is then followed by 6 '('s and 5 ')'s.
The suggested algorithm:
1. Read a single line of text from the file containing a picture of ASCII art.
2. Process this line by first determining whether there is a space.
3. If there are some spaces, count the number of spaces and write a negative integer to the encoded
file.
4. If it is not a space, determine whether there is a repetition of a single character.
5. If repetition exists, write a positive integer to represent the number of the repeated character.
Also write the repeated character to the file.
6. If there is no repetition, write 1 and extract the character pattern up to a position where a space
is present OR repetition of a single character starts to occur.
7. Repeat Step 2 to process the remaining characters in the same line.
8. The encoding process ends when all lines in the original file are encoded in the output file.
For an original file that contains M lines of texts, there must also be M lines of texts in the corresponding
encoded file.
Task 2: Decoding the compressed ASCII art file (40%)
In this task, you are asked to reverse the above process. Given the run-length encoded file, you are required
to decode it to the original ASCII picture.
You should also open and read the encoded file line-by-line. For each line, you need to scan for integers and
strings in this single line so that you can write an appropriate number of the repeated characters to the
decoded ASCII picture file. Once a negative integer is read, you should convert it to the correct number of
spaces in the decoded file.
The suggested algorithm:
1. Read a line of characters from the encoded ASCII art file.
2. Scan this line for an integer.
3. If it is negative, write a corresponding number of spaces in the outputting line of the decoded
file.
4. If it is positive, scan for a string that follows in the input line. Write an appropriate number of
this character pattern in the decoded file.
5. Repeat Step 2 until the end of line is reached.
6. The decoding process ends when all lines in the encoded file are read.
Task 3: Increasing the efficiency of the encoded file (10%)
In task 1, we only consider the repetition of a single character in the original line. We can actually look for
repeated string patterns to increase the efficiency in terms of storage space. 4
Example 3:
The original line
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ | - - - - - | _ | _ | _ | _ | - - - - - | @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
The encoded line
1 7 @ 1 | 5 – 4 | _ 1 | 5 – 1 | 1 7 @
If we make use of the pattern “|_” in the original line, the encoded line becomes shorter than its counterpart
as shown in Example 1.
Example 4:
The original line
I _ I _ I _ I _ I _ I _ I _ I | I _ I _ I _ I _ I _ I _ I _ I _ I _ I | I _ I _ I _ I _ I _ I _ I _ |
The encoded line
- 2 7 I _ 1 I | 9 I _ 1 I | 7 I _ 1 |
Indeed, the repeated string pattern may be longer than 2 characters. The longer the pattern that you are able to
take into account, the smaller is the size of the encoded file.
Please note that a space in the original file breaks the pattern. It is because the
pattern
cannot contain any spaces in the encoded file. As we are writing our encoded file in text format and making it
to be able to decode using a simple algorithm, the resulting file may have a size larger than the original one.
Example 5:
The original line
| | @ | | @ | | @ | | @ | | @ | |
The encoded line
2 | 1 @ | - 1 1 | @ | - 1 1 | @ | - 1 1 | @ | - 1 1 | @ 2 |
In this task, your marks are given with reference to the size of your encoded file. The smaller the file size, the
higher is your mark. To make sure your encoding scheme is correct, you should verify the resulting file
by decoding it once with the method(s) written in Task 2.
For all the tasks above, you can assume that the dimension of the original ASCII art picture is smaller
than 500-by-500 characters., including newline characters. 5
PROCEDURE
1. Create a new project named Assignment4 in folder Assignment4. There are four source files named
Assignment4.java, RunLengthEncoder.java, RunLengthDecoder.java and RunLengthEncoderAdvanced.java
that contains the classes Assignment4, RunLengthEncoder (for task 1), RunLengthDecoder (for
task 2) and RunLengthEncoderAdvanced (for task 3). You shall define them in one package named
assignment4.
2. In the main method of class Assignment4, you are required to read a file name from the standard input
by users as follows:
The original ASCII art picture file: testcase1
If the input name is “testcase1” as shown above, the program should read the ASCII art file “testcase1.txt”.
Then, your program generates the following four files:
(1) “testcase1_e.txt”: the encoding results from Tasks 1;
(2) “testcase1_d.txt”: the results from decoding (1);
(3) “testcase1_ae.txt”: the encoding results from Tasks 3;
(4) “testcase1_ad.txt”: the results from decoding (3).
In the main method, you also need to make use of the other classes defined to perform encoding and
decoding.
3. If you have completed writing the classes, try build the project (press the function key [F11] on the
keyboard). If there are errors, don’t panic. Double-click on the first error message in the Output window.
Check the error, correct it and re-compile. Feel tired? Take a rest.
4. If you have many opened projects, close others or click menu [Run] [Set Main Project].
5. You may insert println() statements in your work to inspect variables and intermediate results.
6. When you finish and there is no more error, you are ready to try out the program by pressing the function
key [F6] on the keyboard. Then you can type the input number in the standard input. Enjoy your work.
SUBMISSION
1. Locate your NetBeans project folder, e.g. H:\Assignment4\.
2. ZIP the project folder Assignment4 and Submit the file Assignment4.zip via our Online Assignment
Collection Box on Blackboard https://blackboard.cuhk.edu.hk6
MARKING SCHEME AND NOTES
1. The submitted program should be free of any typing mistakes, compilation errors and warnings.
2. Comment/remark, indentation, style is under assessment in every programming assignments unless
specified otherwise. Variable naming, proper indentation for code blocks and adequate comments are
important. Insert your name, SID, section, date as well as a declaration statement on academic honesty in a
header comment block in the source file.
3. Test your work using different sets of inputs.
4. For Task 3, the smaller the size of the encoded file, the higher is the mark that you can get.
5. Remember to do your submission before 6:00 p.m. of the due date. No late submission would be accepted.
6. If you submit multiple times, ONLY the content and time-stamp of the latest one would be counted. You
may delete (i.e. take back) your attached file and re-submit. We ONLY take into account the last submission.
UNIVERSITY GUIDELINE FOR PLAGIARISM
Attention is drawn to University policy and regulations on honesty in academic work, and to the disciplinary
guidelines and procedures applicable to breaches of such policy and regulations. Details may be found at
http://www.cuhk.edu.hk/policy/academichonesty/. With each assignment, students are required to submit
a statement that they are aware of these policies, regulations, guidelines and procedures, in a header
comment block.
FACULTY OF ENGINEERING GUIDELINES TO ACADEMIC HONESTY
MUST read: https://www.erg.cuhk.edu.hk/erg/AcademicHonesty
(you may need to access via CUHK campus network/ CUHK1x/ CUHK VPN)
联系我们
QQ:99515681
邮箱:99515681@qq.com
工作时间:8:00-21:00
微信:codinghelp
热点文章
更多
辅导 comm2000 creating socia...
2026-01-08
讲解 isen1000 – introductio...
2026-01-08
讲解 cme213 radix sort讲解 c...
2026-01-08
辅导 csc370 database讲解 迭代
2026-01-08
讲解 ca2401 a list of colleg...
2026-01-08
讲解 nfe2140 midi scale play...
2026-01-08
讲解 ca2401 the universal li...
2026-01-08
辅导 engg7302 advanced compu...
2026-01-08
辅导 comp331/557 – class te...
2026-01-08
讲解 soft2412 comp9412 exam辅...
2026-01-08
讲解 scenario # 1 honesty讲解...
2026-01-08
讲解 002499 accounting infor...
2026-01-08
讲解 comp9313 2021t3 project...
2026-01-08
讲解 stat1201 analysis of sc...
2026-01-08
辅导 stat5611: statistical m...
2026-01-08
辅导 mth2010-mth2015 - multi...
2026-01-08
辅导 eeet2387 switched mode ...
2026-01-08
讲解 an online payment servi...
2026-01-08
讲解 textfilter辅导 r语言
2026-01-08
讲解 rutgers ece 434 linux o...
2026-01-08
热点标签
mktg2509
csci 2600
38170
lng302
csse3010
phas3226
77938
arch1162
engn4536/engn6536
acx5903
comp151101
phl245
cse12
comp9312
stat3016/6016
phas0038
comp2140
6qqmb312
xjco3011
rest0005
ematm0051
5qqmn219
lubs5062m
eee8155
cege0100
eap033
artd1109
mat246
etc3430
ecmm462
mis102
inft6800
ddes9903
comp6521
comp9517
comp3331/9331
comp4337
comp6008
comp9414
bu.231.790.81
man00150m
csb352h
math1041
eengm4100
isys1002
08
6057cem
mktg3504
mthm036
mtrx1701
mth3241
eeee3086
cmp-7038b
cmp-7000a
ints4010
econ2151
infs5710
fins5516
fin3309
fins5510
gsoe9340
math2007
math2036
soee5010
mark3088
infs3605
elec9714
comp2271
ma214
comp2211
infs3604
600426
sit254
acct3091
bbt405
msin0116
com107/com113
mark5826
sit120
comp9021
eco2101
eeen40700
cs253
ece3114
ecmm447
chns3000
math377
itd102
comp9444
comp(2041|9044)
econ0060
econ7230
mgt001371
ecs-323
cs6250
mgdi60012
mdia2012
comm221001
comm5000
ma1008
engl642
econ241
com333
math367
mis201
nbs-7041x
meek16104
econ2003
comm1190
mbas902
comp-1027
dpst1091
comp7315
eppd1033
m06
ee3025
msci231
bb113/bbs1063
fc709
comp3425
comp9417
econ42915
cb9101
math1102e
chme0017
fc307
mkt60104
5522usst
litr1-uc6201.200
ee1102
cosc2803
math39512
omp9727
int2067/int5051
bsb151
mgt253
fc021
babs2202
mis2002s
phya21
18-213
cege0012
mdia1002
math38032
mech5125
07
cisc102
mgx3110
cs240
11175
fin3020s
eco3420
ictten622
comp9727
cpt111
de114102d
mgm320h5s
bafi1019
math21112
efim20036
mn-3503
fins5568
110.807
bcpm000028
info6030
bma0092
bcpm0054
math20212
ce335
cs365
cenv6141
ftec5580
math2010
ec3450
comm1170
ecmt1010
csci-ua.0480-003
econ12-200
ib3960
ectb60h3f
cs247—assignment
tk3163
ics3u
ib3j80
comp20008
comp9334
eppd1063
acct2343
cct109
isys1055/3412
math350-real
math2014
eec180
stat141b
econ2101
msinm014/msing014/msing014b
fit2004
comp643
bu1002
cm2030
联系我们
- QQ: 99515681 微信:codinghelp
© 2024
www.7daixie.com
站长地图
程序辅导网!