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
baherus [9]
3 years ago
10

Create a function void process(char ch, int x, int y)- to accept an arithmetic operator (+,-./, in argum

Computers and Technology
1 answer:
saul85 [17]3 years ago
6 0

Answer:

The program is as follows:

import java.util.*;

public class Main{

   public static void process(char ch, int x, int y){

if(ch == '+'){

    System.out.print(x+y);  }

else if(ch == '-'){

    System.out.print(x-y);  }

else if(ch == '*'){

    System.out.print(x*y);  }

else if(ch == '/'){

    if(y!=0){

        double num = x;

        System.out.print(num/y);      }

    else{

        System.out.print("Cannot divide by 0");     } }

else{

    System.out.print("Invalid operator"); }

 }

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

 int x, y;

 char ch;

 System.out.print("Enter two integers: ");

 x = input.nextInt(); y = input.nextInt();

 System.out.print("Enter operator: ");

 ch = input.next().charAt(0);  

 process(ch,x, y);

}

}

Explanation:

The function begins here

   public static void process(char ch, int x, int y){

If the character is +, this prints the sum of both integers

<em> if(ch == '+'){</em>

<em>     System.out.print(x+y);  }</em>

If the character is -, this prints the difference of both integers

<em> else if(ch == '-'){</em>

<em>     System.out.print(x-y);  }</em>

If the character is *, this prints the product of both integers

<em> else if(ch == '*'){</em>

<em>     System.out.print(x*y);  }</em>

If the character is /, this prints the division of both integers.

<em> else if(ch == '/'){</em>

<em>     if(y!=0){</em>

<em>         double num = x;</em>

<em>         System.out.print(num/y);      }</em>

<em>     else{</em>

<em>This is executed if the denominator is 0</em>

<em>         System.out.print("Cannot divide by 0");     } }</em>

Invalid operator is printed for every other character

<em>else{</em>

<em>     System.out.print("Invalid operator"); }</em>

<em> </em> }

The main begins here

public static void main(String[] args) {

 Scanner input = new Scanner(System.in);

This declares both integers

 int x, y;

This declares the operator

 char ch;

Get input for both integers

<em>  System.out.print("Enter two integers: ");</em>

<em>  x = input.nextInt(); y = input.nextInt();</em>

Get input for the operator

<em>  System.out.print("Enter operator: ");</em>

<em>  ch = input.next().charAt(0);   </em>

Call the function

 process(ch,x, y);

}

}

You might be interested in
The part of the poppet valve that contacts the valve seat is called the?
Amiraneli [1.4K]
C. is the correct answer
6 0
3 years ago
Read 2 more answers
How many megapixels is in a macbook air 2017 camera
Anastasy [175]

Answer:

.7

Explanation:

3 0
3 years ago
Extend to also calculate and output the number of 1 gallon cans needed to paint the wal. Hint: Use a math function to round up t
Crank

Answer:

Here is the Python program:

import math #import math to use mathematical functions

height = float(input("Enter wall height (feet): ")) #prompts user to enter wall height and store it in float type variable height

width = float(input("Enter wall width (feet): ")) #prompts user to enter wall width and store it in float type variable width

area = height *width #computes wall area

print('Wall area: {} square feet'.format(round(area))) #displays wall area using round method that returns a floating-point number rounded

sqftPerGallon = 350 #sets sqftPerGallon to 350

paintNeeded = area/ sqftPerGallon #computes needed paint

print("Paint needed: {:.2f} gallons".format(paintNeeded)) #displays computed paint needed up to 2 decimal places

cansNeeded = int(math.ceil(paintNeeded)) #computes needed cans rounding the paintNeeded up to nearest integer using math.ceil

print("Cans needed: {} can(s)".format(cansNeeded)) #displays computed cans needed

colorCostDict = {'red': 35, 'blue': 25, 'green': 23} #creates a dictionary of colors with colors as key and cost as values

color = input("Choose a color to paint the wall: ") #prompts user to enter a color

if color in colorCostDict: #if the chosen color is present in the dictionary

    colorCost = colorCostDict.get(color) #then get the color cost from dictionary and stores it into colorCost using get method that returns the value(cost) of the item with the specified key(color)

    cost = cansNeeded * colorCost #computes the cost of purchasing paint of specified color per cansNeeded

  print("Cost of purchasing {} paint: ${}".format(color,colorCostDict[color])) #displays the real cost of the chosen color paint

print("Cost of purchasing {} paint per {} gallon can(s): ${}".format(color,cansNeeded, cost)) #displays the cost of chosen color paint per cans needed.

Explanation:

The program first prompts the user to enter height and width. Lets say user enter 20 as height and 50 as width so the program becomes:

Wall area computed as:

area = height *width

area = 20 * 50

area = 1000

Hence the output of this part is:

Wall area: 1000 square feet                                                                                                                     Next program computes paint needed as:

paintNeeded = area/ sqftPerGallon

Since sqftPerGallon = 350 and area= 1000

paintNeeded = 1000 / 350

paintNeeded = 2.86

Hence the output of this part is:

Paint needed: 2.86 gallons

Next program computes cans needed as:      

cansNeeded = int(math.ceil(paintNeeded))

This rounds the computed value of paintNeeded i.e. 2.86 up to nearest integer using math.ceil so,

cansNeeded = 3                                                                  

Hence the output of this part is:

Cans needed: 3 can(s)                                                                                                                            Next program prompts user to choose a color to paint the wall

Lets say user chooses 'blue'

So the program get the cost corresponding to blue color and multiplies this cost to cans needed to compute the cost of purchasing blue paint per gallon cans. So

cost = cansNeeded * colorCost

cost = 3 * 25

cost = 75

So the output of this part is:

Cost of purchasing blue paint per 3 gallon can(s): $75                                                                                        The screenshot of the program along with its output is attached.

5 0
3 years ago
(03 MC)Why is it important to set goals and share them with others?
Ad libitum [116K]

Answer:

answer is b

Explanation:

hope it was helpful

3 0
2 years ago
One way to protect against a security threat to a computer system is to __________. Avoid external links with inconsistent URLs
Makovka662 [10]

One way to protect against a security threat to a computer system is to Avoid external links with inconsistent URLs.

<h3>What is malware?</h3>

Malware is any programme that is purposely designed to disrupt a computer, server, client, or computer network, leak private information, obtain unauthorised access to information or systems, deny users access to information, or otherwise interfere with the user's computer security and privacy.

One way to protect against a security threat to a computer system is to Avoid external links with inconsistent URLs. The reason for this is that such links may contain malware or spyware.

Learn more about Malware:

brainly.com/question/14276107

#SPJ1

7 0
2 years ago
Other questions:
  • It is used to replace numeric number of a website​
    7·1 answer
  • Technician A says that the engine block is the solid frame from which all automotive and truck engines are constructed and is ma
    10·2 answers
  • A powerful computer that acts as a hub for other computers is a called a ______.
    6·2 answers
  • If you want to open an application that does not have a tile pinned to the Start menu, _____ to find it in the list of installed
    7·1 answer
  • FILL IN BLANK FOR THE POINTS!!!!!!
    8·1 answer
  • Create a class named Lease with fields that hold an apartment tenant’s name, apartment number, monthly rent amount, and term of
    13·1 answer
  • What is a characteristic of maintaining logs in a system? A. Logging prevents security violations, but only deals with passive m
    10·1 answer
  • An IT security threat is anything that might cause serious harm to a computer system, including someone stealing a laptop that c
    8·2 answers
  • Under the Home tab, controls for aligning text and objects can be found in the
    5·2 answers
  • Can anyone figure this out???? I need help ASAP!
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!