1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Licemer1 [7]
3 years ago
8

Write a program that defines an interface having the following methods: addition, subtraction, multiplication, and division. Cre

ate a class that implements this interface and provides appropriate functionality to carry out the required operations. Hard code two operands in a test class having a main method that calls the implementing class.
Computers and Technology
1 answer:
Tatiana [17]3 years ago
7 0

Hello, you haven't provided the programing language in which you need the code, I'll explain how to do it using Python, and you can follow the same logic to make a program in the programing language that you need.

Answer:

1. # -*- coding: utf-8 -*-

2. #Python  

3. class Calculator:

4.     def add(self):

5.         print(a + b)

6.     def sub(self):

7.         print(a - b)

8.     def mul(self):

9.         print(a * b)

10.     def div(self):

11.         print(a / b)

12.  

13. obj = Calculator()

14. choice = 1

15. while choice != 0:

16.     a = int(input("\nEnter first number: "))

17.     b = int(input("Enter first number: "))

18.      

19.     print("\n0. EXIT")

20.     print("1. DIVISION")

21.     print("2. ADDITION")

22.     print("3. SUBTRACTION")

23.     print("4. MULTIPLICATION")

24.      

25.     choice = int(input("\nEnter your choice: "))

26.     if choice == 1:

27.         obj.div()

28.     elif choice == 2:

29.         obj.add()

30.     elif choice == 3:

31.         obj.sub()

32.     elif choice == 4:

33.         obj.mul()

34.     else:

35.         break

Explanation:

  • From lines 1 to 12 we define the object with four methods, addition, subtraction, multiplication, and division. Each method contains the operation between two variables inside a print function
  • On line 13 we instantiate our class
  • On line 14 we declare the variable choice that is going to store the operation that the user wants to perform
  • On line 15 we declare a while loop, this is going to keep running the program until the user wants to exit
  • From line 16 to 18 we ask the user to enter two numbers
  • From line 19 to 24 we print the possible operation, assigning a number for each operation, this indicates to the user what number to press for what operation
  • On line 25 we ask the user for the operation
  • From lines 26 to 35 we check the user input an accordingly we call the corresponding method to performs the operation
You might be interested in
4.(L.5.1.A) Select the sentence that includes an interjection,
spin [16.1K]

Answer:

Hurray, we won the tournament!

Explanation:

hurray is an interjection just like yikes, uh-oh, and others

5 0
3 years ago
HELP ME IF YOU KNOW HOW TO CODE ON PYTHON <br> ITS FOR A TEST DUE IN A FEW MINUTES
photoshop1234 [79]

Answer:

Interactive mode is the method to type and run python code in command line. In interactive mode, the python code is written and run line by line in a sequential manner.To enter into interactive mode, open Command Prompt and type ‘python’ and press Enter. Write one line of code and press enter to execute it and enter the second line.

Explanation:

3 0
3 years ago
PLEASE HELP WILL GIVE BRAINLIEST!!!’
Brrunno [24]

Answer: What is a Path, and how do you know that it is filled and selected?

A Path is a series of curves that you can join together. As you click a point in a curve, it changes color and becomes black.

8 0
3 years ago
The __________ clash of clans and candy crush saga are video games that exploit the real world–digital world convergence by buil
solmaris [256]
The  game play of the clash of clans and candy crush saga are video games that exploit the real world–digital world convergence by building huge personal-rewards psychology for players.<span>The Candy Crush game app exploits some well known weaknesses in the human brain to keep us playing</span>
5 0
3 years ago
Clicking the _____ opens the insert function dialog box shown in the accompanying figure.
stiks02 [169]
Clicking the insert function box on the formula bar <span>opens the insert function dialog box shown in the accompanying figure.</span>
8 0
3 years ago
Other questions:
  • What document is created to identify the areas of testing of a website?
    8·1 answer
  • Which topology enables only one person, at one time, to send data to others on the network?
    6·1 answer
  • ______________ helps you see how your document will appear on the paper. ​
    10·1 answer
  • A security policy is a?
    11·2 answers
  • Value of 3.0+4.0×6.0​
    14·1 answer
  • THIS IS FOR MY FINAL PLEASE HELP
    6·1 answer
  • What is a non-example for job application???
    11·1 answer
  • Why were Redditors interested in "Mister Splashy Pants"?
    6·2 answers
  • T<br> N<br> O<br> ?<br> You can insert only the row<br> only to<br> True or false
    7·2 answers
  • What refers to a set of instructions executed in order?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!