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
Modify your previous exercise to determine if the user can ride a rollercoaster. To ride the rollercoaster, you must be at least
sweet-ann [11.9K]

Answer:

In Python:

age = int(input("How old are you? "))

height = float(input("How tall are you (inches)? "))

if age>=9 and height >= 42:

    print("You can ride the roller coaster")

else:

    print("You ca'nt ride the roller coaster")

Explanation:

The code segment of the "previous exercise" is not given; so, I rewrite the program from scratch using python.

And using the solution I provided, you'll have an idea of how to write the expected code If the "previous exercise" is not written in python,

This line prompts user for age

age = int(input("How old are you? "))

This line prompts user for height

height = float(input("How tall are you (inches)? "))

This checks if user is at least 9 years old and at least 42 inches tall

if age>=9 and height >= 42:

If true, the user gets to ride the roller coaster

    print("You can ride the roller coaster")

else:

If otherwise, the user will not ride the roller coaster

    print("You ca'nt ride the roller coaster")

4 0
3 years ago
Which method below is a physical security measure?
nekit [7.7K]

The only given option that is a physical security measure is; Passwords

<h3>Computer Security</h3>

Physical security is defined as the protection of personnel, hardware, software, networks or data from the adverse effect of human actions and events. These adverse actions or events could lead to severe loss and damage to an enterprise or any institution or even personnel.

Now, among the given options, firewall is a network security that simply monitors and filters the incoming and outgoing network traffic on a computer.

Anti-virus is uses to detect and remove corrupt files from a computer system. Whereas passwords are physical security measures because they involve human actions.

Read about Computer security at; brainly.com/question/26260220

5 0
2 years ago
In the United States, the government controls and owns a very large percentage of the media.
jeka94
True they can pretty much see anything you do and on top of that they can look through your cameras. thats why i keep tape on my camera on my laptop
6 0
3 years ago
Read 2 more answers
Best motherboard cpu and ram combo thats cheap but good for gaming under 200
Leviafan [203]

Kinda hard for under 200

7 0
3 years ago
Dr.Sanchez is creating a quiz for a history class. It will have true or false questions. What kind of variable will be needed to
KatRina [158]

Answer:

Option 3) Boolean is the correct answer

Explanation:

Let us see all the data types given in the options.

Alphabetic datatype stores alphabets and characters.

Float stores numbers with decimal points.

Boolean is a binary data type that can only have two values either one and zero or true and false.

Integer stores positive and negative numbers.

Looking at all the definitions we can conclude that Boolean will be the suitable variable to store the answers as the answer can only have one of the two values from true and false.

Hence,

Option 3) Boolean is the correct answer

4 0
3 years ago
Read 2 more answers
Other questions:
  • If a pedestrian begins to cross my path when i have the right of way
    5·1 answer
  • Pinterest, a visual bookmarking Website, logs more than 14 terabytes of new data each day, which means its storage needs are con
    10·1 answer
  • Select the correct answer
    11·1 answer
  • Write a program that asks for the names of three runners and the time, in minutes (no seconds, etc.), it took each of them to fi
    7·1 answer
  • If someone you don”t know asks where you go to school, what should you do?
    7·2 answers
  • Using a conversation voice is part of:
    9·1 answer
  • A type of storage which holds data on a permanent basis for later use<br><br><br><br> Help please
    8·1 answer
  • In PowerPoint, a type of chart that, rather than showing numerical data, illustrates a relationship or logical flow between diff
    13·1 answer
  • Which IDEs support multiple high-level programming languages? Select all that apply.
    13·1 answer
  • What happens to testosterone levels of those who lose chess tournaments?
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!