300144 Object Oriented Analysis 300888 Object Oriented Analysis (Advanced)
Tutorial 8 – User Interface & Prototyping (Week 11)
Student Name: ______________________________________ Student ID: ______________________________________ Tutorial Class: ______________________________________
Instructions to students –
• Attempt all questions
• This Tutorial will contribute to your final assessment mark
• The Tutor will check your solutions when you are finished
• BICT (Advanced) students need to complete optional questions.
Project Work:
1. Identify, specify and sketch at least FOUR user interfaces per package based on the packages identified in your project work 3 and the user cases documented in project work 4.
2. Identify and specify at least ONE printer interface (for example the printing interface for a receipt after a transaction).
3. Create ONE User Interface flow (UI-flow) diagram per package for the interfaces identified in above
4. Create a functional prototype (not necessarily an executable) for your system. This functional prototype should be able to ‘step through’ one use case from each of the package, by using the interface sketches.
Tutorial Exercises (Optional):
The following Java program was developed for prototyping a mini calculator. Run the program and provide your feedback as the user/project sponsor. (Save the code as MiniCalculator.java; compile the file: javac MiniCalculator.java; and then run the program: java MiniCalculator).
HINTs: May give feedback to the data type and operations handled by the program, the way the program to get numbers and operators, the way the calculation results are output, the termination of the program and the way the program handles wrong data types and other exceptions.
import java.util.Scanner;
class DataAndOperator {
int operand1;
int operand2;
int result;
String operator;
}
public class MiniCalculator {
public static void main(String[] args) {
// Scan for keyboard input.
Scanner input = new Scanner(System.in);
// operands and operator
DataAndOperator dataAndOperator = new DataAndOperator();
// Loop until the user enters zeros for both numbers.
do {
System.out.println(“(Enter zeros for both operands to exit)”);
GetOperands(input, dataAndOperator);
if ((dataAndOperator.operand1 != 0) || (dataAndOperator.operand2 != 0))
{
System.out.print(“Enter the operator(+, -, *, / or %): “);
dataAndOperator.operator = input.next();
// Print the result of the calculations.
if (DoMath(dataAndOperator)) {
System.out.println(dataAndOperator.operand1 + ” ”
+ dataAndOperator.operator.charAt(0) + ” ”
+ dataAndOperator.operand2 + ” = ” + dataAndOperator.result);
} else
System.out.println(“Calculation not performed!”);
}while ((dataAndOperator.operand1 != 0) || (dataAndOperator.operand2 != 0));
}
System.out.println(“Exiting…”);
}
private static void GetOperands(Scanner _input, DataAndOperator _dataAndOperator) {
while (true) { //until get the right data type input System.out.print(“Enter first number: “);
try {
_dataAndOperator.operand1 = _input.nextInt();
break; }
catch (Exception e) {
_input.nextLine();
System.out.println(“Wrong data typ. Please enter an integer.”);
} }
while (true) { //until get the right data type input System.out.print(“Enter second number: “);
try {
_dataAndOperator.operand2 = _input.nextInt();
break; }
catch (Exception e) {
_input.nextLine();
} }
}
System.out.println(“Wrong data typ. Please enter an integer.”);
// Switch statement to decide what operation to do based on the operand.
private static boolean DoMath (DataAndOperator _dataAndOperator) {
boolean success=true;
char _operator=_dataAndOperator.operator.charAt(0);
switch (_operator) {
case ‘+’:
_dataAndOperator.result= _dataAndOperator.operand1 +
_dataAndOperator.operand2;
break;
case ‘-‘:
_dataAndOperator.result= _dataAndOperator.operand1 –
_dataAndOperator.operand2;
break;
case ‘*’:
_dataAndOperator.result= _dataAndOperator.operand1 *
_dataAndOperator.operand2;
break;
case ‘/’:
try {
} }
}
break;
case ‘%’:
}
break;
default:
_dataAndOperator.result= _dataAndOperator.operand1 /
_dataAndOperator.operand2;
}
catch (Exception e) {
success=false;
System.out.println(“Cannot be divided by 0.”);
try {
_dataAndOperator.result= _dataAndOperator.operand1 %
_dataAndOperator.operand2;
}
catch (Exception e) {
success=false;
System.out.println(“Cannot be modulared by 0.”);
System.out.println(“Please select one operator from { +, -, *, /, % }.”);
success=false;
}
return success;