Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

There are two parts to this assignment: The Math Equation Class o Defined by the class MathEquation. o Models a math equation The Main Program

There are two parts to this assignment: The Math Equation Class o Defined by the class MathEquation. o Models a math equation The Main Program o This is a main() method that tests and uses the MathEquation class. o Defined by the class Main. Both of these classes should be part of the same package.

Class: MathEquation Data Members: - leftVal: double - rightVal: double - opCope : char - resullt : double Static Members: - numberOfCalculations: int - sumOfResults: double Method Members: + MathEquation () + MathEquation (opCode : char) + MathEquation (opCode : char, leftVal: double, rightVal: double) + getLeftVal () : double + setLeftVal (double: leftVal) : void + getRightVal () : double + setRightVal (double: rightVal) : void + getOpCode () : char) + setOpCode(opCode: char) : void + getResult(): double + toString(): string + getAverageResult: (static method) returns sumOfResults divided by numberOfCalcualtions as a double Execute() See below for more on what execute() does Notes: The execute method is a void instance method that takes no parameters It uses the value in opcode (hint: consider using a switch case) to determine the operation to perform between leftVal and RightVal opcode supported values: Note: an instance of MathEquation specifying opcode needs to have been instantiated before calling execute opcode: a: set result to the addition of leftVal and rightVal opcode: s: set result to the subtraction (leftVal rightVal) opcode: m: set result to the multiplication of leftVal * rightVal opcode: d: set result to the multiplication of leftVal / rightVal only if rightVal is not zero. If rightVal is 0, set result to 0.0d opcode is none of the values above: print out a message indicating that opcode is invalid and set result to 0.0d. In all cases, number of calculations should be incremented and sumOfResults should be updated by adding the value of result to it

This program must be in the class called Main in your assignment 1 project. This program prompts the user to enter the left value, right value and the opCode Use the methods of your class to ensure that the user's input is valid. If any input is not valid, repeatedly prompt the user to enter data until that data is valid. Display the result of the operation; as well as the average result returned by the getAverageResult method. Each should be on a separate line Upon displaying the result of the operation, prompt the user again for to enter another set of left value, right value and an opCode After the user has entered all 3 input values: Display the MathEquation object as a String. (hint: use implement a toString method that prints out the 2 values and the operation as a user friendly string Display the result of the operation; as well as the average result returned by the getAverageResult method. Each should be on a separate line All user interaction and output should be displayed on the console/screen. Sample interaction and output below (you can use these values to test your program): Sample Interaction and Output Program Prompts are in GREEN BOLD, User Input is in BLUE ITALIC, Program Output is in MONOSPACE BOLD. Note that the colours are for demonstration purposes only: you are not required to have colours in your program's interaction/output. Example 1: Enter Left Value: 20 Enter Right Right: 2 Enter opCode: d MathEquation: LeftVal: 20.0, rightVal: 10.0, opcode:d Result : 2.0d Average Result: 2.0d Enter Left Value: 15.0 Enter Right Right: 5 Enter opCode: m MathEquation: LeftVal: 15.0, rightVal: 5.0, opcode:m Result : 75.0d Average Result: 38.5image text in transcribedimage text in transcribed

Method Members: + MathEquation () + MathEquation (opCode : char) + MathEquation (opCode : char, leftVal: double, rightVal: double) + getLeftVal (): double + setLeftVal (double: leftVal) : void + getRightVal (): double + setRightVal (double: rightVal) : void + getOpCode () : char) + setOpCode(opCode: char) : void + getResult(): double + toString(): string + getAverageResult: (static method) returns sumOfResults divided by numberOfCalcualtions as a double Execute() See below for more on what execute() does Notes: . The execute method is a void instance method that takes no parameters It uses the value in opcode (hint: consider using a switch case) to determine the operation to perform between leftVal and RightVal opcode supported values: Note: an instance of MathEquation specifying opcode needs to have been instantiated before calling execute opcode: 'a': set result to the addition of leftVal and rightVal opcode: 's': set result to the subtraction (leftVal rightVal) opcode: 'm': set result to the multiplication of leftVal * rightVal opcode: 'd': set result to the multiplication of leftVal / rightVal only if rightVal is not zero. If rightVal is 0, set result to 0.Od opcode is none of the values above: print out a message indicating that opcode is invalid and set result to 0.Od. In all cases, number of calculations should be incremented and . program): Sample Interaction and Output Program Prompts are in GREEN BOLD, User Input is in BLUE ITALIC, Program Output is in MONOSPACE BOLD. Note that the colours are for demonstration purposes only: you are not required to have colours in your program's interaction/output. Example 1: Enter Left Value: 20 Enter Right Right: 2 Enter opCode: 0 MathEquation: LeftVal: 20.0, rightVal: 10.0, opcode :d Result : 2.0d Average Result: 2.0d Enter Left Value: 15.0 Enter Right Right: 5 Enter opCode: m MathEquation: LeftVal: 15.0, rightVal: 5.0, opcode:m Result : 75.00 Average Result: 38.5

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions