Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439

Computer Science Courses

COMP2100

Related sites

COMP 2100/2500/6442: Lab 8 - Design Patterns, Bash

Pre-Lab Tasks [2 marks]

The first 10 minutes of the lab session time may be spent by your tutor to mark pre-lab tasks.

Bash basics

% ./greeting EricHello Eric% ./greeting AlistairGreetings Professor Rendell% ./greeting AnishG'Day Anish

You only need to have a few different greetings for different names and one default greeting. Please keep all your greetings positive and friendly.

String Counting with Java

This program must be completed in order to start the in-class activities.

(Hint - if the expression i == mainString.indexOf(subString, i) evaluates to true then the subString will be within the mainString starting at position i.)

Using the Facade Design Pattern

In Class Activity - Writing a Test Harness in Bash [2 marks]

The objective is to write a Bash script to test the StringCount program with different string combinations. This may be done individually or in a small group of 2 or 3 students.

#!/bin/bashwhile read x ydo  echo ${x} ${y}done

The key feature of this script is the read command which reads a line of input and assigns the first word to the variable x and the rest of the line to the variable y. The read command gives an exit code of 0 (= success = True) if was was able to read the words, or 1 (= failure = False) if it encounters the end of its input. That makes it perfect for use in a while loop, as seen in this example. When the input runs out, it returns 1, and the loop terminates.

Note: This does not mean rewrite the Java program as a bash script. It means write a bash script that runs the Java program on each line of its input and formats the results.

Have a look at the manual page for the test command (by typing man test). That should tell you everything you need to know now to complete this exercise. The test command evaluates a boolean expression (as well as being able to test for all sorts of other conditions). It basically lets you program in Bash in a way very like what you would do in Java.

The test command is so commonly used in shell scripts that it has a short-hand notation in which [ stuff ] means the same as test stuff (those spaces inside the square brackets are required). Use this notation to simplify your solution.

Updated:  15 May 2016 / Responsible Officer:   JavaScript must be enabled to display this email address. / Page Contact:   JavaScript must be enabled to display this email address. / Powered by: Snorkel 1.4

+61 2 6125 5111
The Australian National University, Canberra
CRICOS Provider : 00120C
ABN : 52 234 063 906