CSC113_Tutorial5 - + toString(): String - op1: double -...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
King Saud University College of Computer and Information Systems, Department of Computer Science CSC 113: Java Programming-II, Spring2011 Tutorial #5 : Inheritance MathOp represent a mathematical operation. We have only two operations: Add (+) and Subtract (-). Below is a description for all the attributes and methods: opSymbol The symbol of the operation. For example "+" for Add, and "-" for Subtract. op1, op2 The two operands of the operation (LHS and RHS operands). result(): double It should return the result of applying the operation on the two operands. toString(): String It should return the string representation of the operation with the two operands. i.e. op1 + opSymbol + op2 . MathOp + MathOp(opName: String) + result(): double + toString(): String # opSymbol: String Add + Add(op1: double, op2: double) + result(): double
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: + toString(): String - op1: double - op2: double Subtract + Subtract(op1: double, op2: double) + result(): double + toString(): String - op1: double - op2: double King Saud University College of Computer and Information Systems, Department of Computer Science CSC 113: Java Programming-II, Spring2011 Tutorial #5 : Inheritance You have to do the following: 1. Implement the above classes 2. Write a main class, in it: a. Define an array of MathOp with the size 3. b. Add these three operations to it : 5 + 3 , 2 – 1 , 10.5 + 5 using Add and Subtract . c. Loop through the 3 operaƟons in the array and print the string representaƟon of the operation and the result of each operation using the methods toString() and result() . You should get an output similar to this: 5 + 3 = 8 2 – 1 = 1 10.5 + 5 = 15.5...
View Full Document

This note was uploaded on 08/18/2011 for the course COMPUTER S CSC 113 taught by Professor Dr.safwanqasem during the Spring '11 term at King Saud University.

Page1 / 2

CSC113_Tutorial5 - + toString(): String - op1: double -...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online