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
NAT ________. allows a firm to have more internal IP addresses provides some security both allows a firm to have more internal I
algol13

Answer:

NAT provides some security but allows a firm to have more internal IP addresses

Explanation:

NAT ( network address translation) this is a process where a  network system usually a firewall  assigns a public IP address to an internal computer used in a private network. it limits the number of public IP address a company operating a private network for its computer can have and this is very economical also limits the exposure of the company's private network of computers. the computers can access information within the private network using multiple IP addresses but it is safer to access external information using one public IP address

5 0
2 years ago
An online retailer has developed an algorithm to provide personalized recommendations to shoppers. Which form of IPR protects th
Helen [10]

Answer:

should be B.

Explanation:

If not then Im sorry

5 0
2 years ago
What is the first step in creating a maintenance ?
tankabanditka [31]
The first step would be knowing the manufacturer s recommended schedule for maintenance
7 0
3 years ago
Write 5 chart types​
Lemur [1.5K]

Answer:

pie chart

line chart

area chart

bar charts

histogram

scatter plot

6 0
2 years ago
What does a production proposal provide ?
aliina [53]

Answer:

information about the cast and crew

Explanation:

3 0
3 years ago
Read 2 more answers
Other questions:
  • Many of today’s digital devices operate on battery power supplied by what kind of ion batteries.
    15·1 answer
  • Renee's creating a plan for her business's information system. What should she do after she determines the goals for her busines
    10·1 answer
  • You have just starting working at Quantum Company. As a new programmer, you have been asked to review and correct various pseudo
    14·1 answer
  • What is the different between ethical and legal issues?​
    6·1 answer
  • In the Mouse Properties window, you can?
    8·1 answer
  • Write a program that allows the user to enter a time in seconds and then outputs how far an object would drop if it is in free f
    7·1 answer
  • During a network infrastructure upgrade, you have replaced two 10 Mbps hubs with switches and upgraded from Category 3 UTP cable
    6·1 answer
  • In Tynker, it is not possible to create a/an __________.
    6·2 answers
  • What are the characteristics of computer. Explain any one​
    15·2 answers
  • Read the ages of three people and find the average. Display the result.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!