Question

You are required to build a class ArithematicProblem that represent a binary
arithematic problem such as addition, subtraction, multiplication and division.
The ArithematicProblem class is a super class which is there to provide the most
generic version of the ArithematicProblem concept. This class has following
instance variables
1. Operator1 (double)
2. Operator2 (double)
3. Answer(double)
4. Error(boolean)
The value of Operator1 and Operator2 will be initialized through parameters in the
constructor while the value of answer is Double.POSITIVE_INFINITY and error is false
by default.
Provide getters for all but setters for only operand1 and operand2
Provide the toString method so that the string representation of each operation
the standard representation in mathematics i.e. if its an addition problem then it
should be printed as 2 + 3 = 5 and so on.
Provide a method double solve() in this class. This method performs the arithematic
operation on the operands, calculates answer, sets the value of answer and returns it. If an error occurs
in the calculation then the error is set to true and answer remains Double.POSITIVE_INFINITY. Since in
the super class ArithematicProblem, we do not know what to do (beccause it is not one of the standard
4 operations), you will simply return the answer (Double.POSITIVE_INFINITY)
Now provide the subclasses AdditionProblem, SubtractionProblem,
MultiplicationProblem and DivisionProblem. All of these class inherit from
ArithematicProblem. Provide appropriate constructors and the toString method.
Now override the solve method in each of these class to do the appropriate
operation. i.e. If it is AdditionProblem then you will add the operands in the solve
method, set the answer to the sum obtained and return this value.
In subtraction you will do subtration and multiplication the product. However, in division, you will
perform the division but if the divisor i.e. the second operand is 0 then the division goes into error. So
you will check for this situation and if the divisor is 0 then you will not solve, rather set the error to true
and return the answer unchanged. (I.e. POSITIVE_INFINITY, the default value).

Expert Answer

Want to see the step-by-step answer?

Check out a sample Q&A here.

Want to see this answer and more?

Experts are waiting 24/7 to provide step-by-step solutions in as fast as 30 minutes!*

*Response times may vary by subject and question complexity. Median response time is 34 minutes for paid subscribers and may be longer for promotional offers.
Tagged in
Engineering
Computer Engineering

Programing

Related Computer Engineering Q&A

Find answers to questions asked by students like you.

Q: Artemis Financial is looking to encrypt their archive files and they need advice from you, as the de...

A: CipherA cipher is an algorithm, operation, or method for encryption and decryption execution. A cyph...

Q: Consider a magnetic disk with 1000 cylinders rotating at a speed of 7200 revolutions per minute. The...

A: Given:- Total number of cylinders =1000 Number of Revolutions per minute = 7200 Sector size =1024 By...

Q: Explain the historical development of programming languages and compare Object Oriented Programming ...

A: Click to see the answer

Q: 1 Insert the following customer into the CUST_MYSQL table, allowing the AUTO_INCREMENT attribute set...

A: insert into CUSTOMER(CUST_LNAME, CUST_FNAME, CUST_BALANCE)values('Powers', 'Ruth', 500);

Q: What type of measure scale is being used? Nominal, Ordinal, Interval or Ratio. Karachi daily temper...

A: Explanation: Nominal Scale are used for labelling variables without any quantitative value, Example...

Q: Assume that the 4-digit numbers that are equal to the square of the sum of the numbers divided into ...

A: Code: in c   #include <stdio.h>   int getDigits(int n)//method for breaking the number into ha...

Q: There are n customer of bank who took loan of different amounts (Entered by User) and for different ...

A: Algorithm: 1. Input Number of customers (n), Rate of Interest 2. Declare 2 arrays of size n to stor...

Q: Help!

A: Click to see the answer

Q: Assignment 5.py: #Assignment 5 import Queueimport threadingimport timeimport random THREADS = 200 cl...

A: Part 1: Output From the output, it is clear it is in expected lines. However, if the same program i...

Q: Write a program to add the following five data bytes stored in memory locations starting from XX60H,...

A: Diagram:

Q: QUESTION 9 1. If a given memory address for a byte addressable machine is found in a cache that uses...

A: A CPU cache is a hardware cache used to lower the average costs of accessing data from the main memo...

Q: The language is C++ 3. Write a program to calculate the factorial value of the inputnumber.Use the i...

A: The C++ program is written which will be user defined input of the function. The program uses the fo...

Q: Activity Immediate Predecessor Optimistic Time Most Likely Time Pessimistic time Time Expe...

A: The schedule network diagram is:   1. The critical path is the path with highest durations. From th...

Q: write a c code for this code While travelling in a train, you observe some college students pulling ...

A: ALGORITHM: Declare             Integer n             Integer m Begin             Read n and m       ...

Q: Draw the block level diagram of the pipelined operand fetch (OF) stage of 5-   stage pipeline(IF,OF,...

A: Pipelining is a technique which allows several instructions to overlap in time; different parts of s...

Q: a. f1(n) is Ω(f6(n)) b. f5(n) is Q(f3(n)) c. f1(n) is O(f3(n)) d. f5(n) is O(f1(n)) e. f6(n) is Ω(f4...

A: Asymptotic notation : Mathematical way of representation of time complexity.  They are use to compar...

Q: The Internet has fast become a key instrument for the exercise of the right to freedom of speech. In...

A: Freedom of speech is a philosophy that encourages an individual's or a community's freedom to expres...

Q: // This program demonstrates a unique_ptr pointing to a dynamically allocated array of integers. #in...

A: This program has asked to write a program to demonstrate unique_ptr pointing to a dynamically alloca...

Q: Please solve very soon completely

A: File1:index.html <!DOCTYPE html> <html>   <body>   <h2>Calculate Salary Form...

Q: Draw the finite state automaton diagram for a 2-bit branch history predictor that changes prediction...

A:   The digital circuit which tries to guess the ways to way a branch, the two-level branch predictor ...

Q: Translate following program into compiled MIPS code. Assume that g, c, i are in $s0, $s1, $s2 regist...

A: MIPS(Microprocessor without Interlocked Pipeline Stages) assembly language of the MIPS processor.   ...

Q: PLEASE DO NOT COPY AND PASTE FROM CHEGG. IT IS INCORRECT.  Consider this code snippet.              ...

A: Let us have the following given code after naming them instruction wise:- I1: bnex r1, l1 I2: addi r...

Q: Need help please to decode this cryptogram

A: The Cryptogram we need to solve: LPUMO HBKJT CMCSI KQFWF JFXUT FZVKH UHPHI UJLIV YIOKL PCMBF  IFKRG ...

Q: Solve it

A: a. Given, E→‐E | (E) | VT T→‐E | ε V→id L L→(E) | ε In order to find the Predictive parsing table, f...

Q: When recursion is used to solve a problem, why must the recursive method call itself to solve a smal...

A: Actually, recursion is a function call it self.

Q: Write down a flowchart for the calculation of the following statistics: Midpoint = (min+max)/2, maxi...

A: Actually, flow chart is a type of diagram that represents a workflow or process.

Q: can you write in C language

A: Note: Below is the required C program. Program Approach: Defining necessary header files Declaring ...

Q: Use c++ program

A: #include <iostream>using namespace std; class cms{    public:        string name;    int exper...

Q: What is enterprise data modeling?

A: Actually, The enterprise data model is a independent of how the data is physically stored, processed...

Q: Using WHILE loop. Create a simple C++ program for purchasing which contains an invoice number, amoun...

A: Invoice number  should be in between 5000 and 10000 Sale Amount should be non negative  

Q: 1. Discuss the purpose of media and information to an individual and the society.

A: Now-a-days media became part of everyone's life and media may be printed media, television media and...

Q: C++  Create a standalone program that performs the tasks below. Start by solving task one and comple...

A: Program: #include <iostream> #include <fstream> #include <string> #include <sst...

Q: Create the above hierarchy as follows” Create Book class having above attributes provide getter, se...

A: public class Book{        //declare data members    private String authorName;    private double cos...

Q: Consider the following traditional file system, which shows a number of index cards stored in two se...

A: Actually, database is used to stores the data.

Q: Introduction:It is often necessary to reformat data in files. Sometimes it is done for readability, ...

A: Language : C++ Solution is in Step 2. 

Q: thumb_down program: #include<stdio.h> int main(){    int a[5][5],i,j;    printf("enter elem...

A: Introduction of Flow Chart: The flow chart represents the pictorial representation of any program. T...

Q: Given a non-dummy headed circular list, write down a method for inserting an elementinto the list.

A: In a circular linked list, the last node contains a pointer which points to the first node of the li...

Q: Using Switch statement, develop application that displays the following menu for the food items avai...

A: A switch statement is a multi-way decision making statement. In which, the input value is match with...

Q: What is the time space complexity of recursive??

A: Algorithm/Insights Fibonacci Sequence: In the given below code, the function 'fibonacci(int n)' comp...