CSC113_Tutorial5

# CSC113_Tutorial5 - toString String op1 double op2 double...

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

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

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

View Full Document
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

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern