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
High quality pages in a task should all get the same Needs Met rating. For example, a high quality page for a common interpretat
marysya [2.9K]

Answer:

False

Explanation:

High quality page for a common interpretation always have different Needs Met rating than the high quality page for a minor interpretation of the query.

Although, both of this pages are of high quality we must differentiate the common from a minor interpretation of a query.

Needs Met should always know to place the high quality pages in a resolution hierarchy.

7 0
3 years ago
Question 11
STatiana [176]

What type of program would have a class named Student with objects called fullTime and partTime?

A. machine language program

B. object-oriented program

C. markup language program

D. procedural language program

Answer:

B. object-oriented program

Explanation:

An object-oriented program or OOP is a type of program that uses the concepts of objects and methods.

Although they are quite broad, they also make use of classes and types.

Java, for instance makes use of OOP as they use classes and objects under those classes and name them anyhow they want.

Therefore, the correct answer is B

8 0
3 years ago
Carlos is using the software development life cycle to create a new app. He has finished coding and is ready to see the output i
Nitella [24]

Answer:

Testing

Explanation:

From the question, we understand that Carlos just finished the coding of the app.

In software development life cycle, the coding phase is where Carlos is expected to make use of his choice of programming language to design the app;

This stage is an integral part of the implementation process and according to the question, the coding has been completed;

The next phase or stage after the implementation phase is testing.

Hence, Carlos is getting ready to test the app.

4 0
2 years ago
Read 2 more answers
What kind of operating system is MS-DOS?
ELEN [110]

MS-DOS is a command-line operating system.

Therefore, the best answer is Command-line.

8 0
3 years ago
Read 2 more answers
Why would students most likely need to collect data? Check all that apply
n200080 [17]
Well I would think all of them in some way. For the first one, students need to collect data (whether it’s mathematical, scientific, etc.) to answer a question. For the second one, they may need to know how much money is in there bank account or they may need to calculate a sale to order the item. For the third one, they may need statistical data to support a position. For the last one, a student could use technological data to be able to solve their problem sorting documents.
5 0
3 years ago
Read 2 more answers
Other questions:
  • Ninety-two percent of the new information was stored on magnetic media, mostly in _____.
    11·1 answer
  • What allows people to create their own radio shows over the internet?
    14·1 answer
  • Which organization safeguards americans from health, safety, and security hazards and threats?
    14·2 answers
  • python A year in the modern Gregorian Calendar consists of 365 days. In reality, the earth takes longer to rotate around the sun
    15·2 answers
  • Why does dew form on grass overnight
    7·1 answer
  • Kevin needs to get his data from a database into a text file to send to another group. He needs to _____.
    12·2 answers
  • Write a single statement that assigns avg_sales with the average of num_sales1, num_sales2, and num_sales3.
    15·1 answer
  • How do Computer Scientists use Binary Code?
    14·1 answer
  • Two girls were born to the same mother, on the same day, at the same time, in the same month and the same year and yet they're n
    7·1 answer
  • Determine the value of a and b at the end of the following code segment:
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!