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
1. Describe a linear search (explain how it works).
timurjin [86]
1. A linear search searches on a straight path, hence the term “linear”. So a linear search would search from a one index to another in a straight path. For example, a linear search of an array, if given given the first and last index of the array, would search it one index after the other. First it would check index 0, then index 1, then index 2, and so forth.

2. A linear search can be useful if you are trying to find more than one instance of an value in a data structure. Since you want to search the whole array for each instance of the object or value.

3. A binary search only works with sorted data structures. It takes a data structure, finds its mid point, and checks I see if the value it is looking for is greater, less than, or equal to the midpoint value. If it is equal to the midpoint value, it’s finished and the search function is over.
If it’s greater than the midpoint, it disregards the lower half of the data structure and focuses on the upper half. If it’s less than the mid point then it disregards the upper half and focuses on the lower half.
It then repeats what it did at the beginning of the search function to again narrow down the amount of searching that needs to be done. In other words, if it disregarded the lower half of the data structure in the first part of the search, it finds the midpoint of the upper half of the data structure, checks to see if the value it’s looking for is greater than, less than, or equal to the midpoint. If it’s equal to it the searching is done, if it’s greater it disregards the lower half of the upper data structure, and repeats the process.
It will continue to do this until either the value is found or the value is not found.

4. You would use binary search if you are searching for one specific value in a sorted data structure.

5. A binary search must have a sorted data structure for it work.

6. Binary search is more efficient because the cost to run a binary search is substantially less than running a linear search.







7 0
3 years ago
Describe how learning can be accessed in your class?​
SpyIntel [72]

There are four main learning styles used in classrooms today: Visual, auditory, reading/writing, and kinesthetic.

8 0
3 years ago
BIm computer class I need answers please
egoroff_w [7]

Answer:

I think the 3RD

Explanation:

The  reason why I think that is because the other once are not written correctly.

8 0
3 years ago
Read 2 more answers
When testing a game, why might you consider throttling the game’s “frames per second”?
Ivenika [448]

Answer:

because if you throttle it then

you can make sure it's okay

4 0
2 years ago
Mike needs to write the primary objectives of a project in a project plan. In which section should he write them?
Advocard [28]

Mike needs to write the primary objectives of a project in a project plan. He should write this under the SCOPE section of the project plan.

Explanation:

  • Project scope is the part of project planning that involves determining and documenting a list of specific project goals, deliverables, features, functions, tasks, deadlines, and ultimately costs.
  • It is what needs to be achieved and the work that must be done to deliver a project.
  • The Scope of Work (SOW) is the area in an agreement where the work to be performed is described.
  • The SOW should contain any milestones, reports, deliverables, and end products that are expected to be provided by the performing party. The SOW should also contain a time line for all deliverables.
  • The scope is simply all the work that needs to be done in order to achieve a projects objectives.
  • A project scope, or project scope statement, is a tool used to describe the major deliverables of a project including the key milestones, high level requirements, assumptions, and constraints.

7 0
3 years ago
Other questions:
  • Design and write an object-oriented program for managing inventory bins in a warehouse. To do this you will use two classes: Inv
    5·1 answer
  • Brute force attacks involve identifying a valid user account and then bombarding the server with an extensive:
    13·1 answer
  • Complete the paragraph describing characteristics of an audio mixer
    8·2 answers
  • What are features of a product?
    8·2 answers
  • Which of the following statements is false? a. InputStream and OutputStream are abstract classes for performing byte-based I/O.
    7·1 answer
  • John has subscribed to a cloud-based service to synchronize data between his smartphone, tablet, and PC. Before allowing the dat
    10·1 answer
  • What type of engineer is interested in designing, developing, and building different machines, devices, and tools? A.aerospace
    8·2 answers
  • The type of medium used to hide data in steganography is referred to as __________. This may be a photo, video, sound file, or V
    12·2 answers
  • You decide to test an audio clip that you have inserted into your presentation, but before you do that you make sure that the co
    6·1 answer
  • A network device that is used to connect multiple devices together without segmenting a network is a __________.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!