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
Hoochie [10]
2 years ago
6

Which of the following would be a valid method call for the following method? public static void showProduct (int num1, double n

um2) { int product; product = num1 * (int)num2; System.out.println("The product is " + product); }
Computers and Technology
1 answer:
Alenkinab [10]2 years ago
3 0

Answer:

showProduct(int,double)

for example: showProduct(10,10.5) is the correct answer even showProduct(10,10.0) is also correct but showProduct(10.0,10.5) or showProduct(10,10) or showProduct(10.0,10) are wrong calls.

Explanation:

The code is

  1.       <em>public static void showProduct (int num1, double num2){</em>
  2. <em>       int product;</em>
  3. <em>       product = num1*(int)num2;</em>
  4. <em>       System.out.println("The product is "+product);</em>
  5. <em>       }</em>

showProduct is function which asks for two arguments whenever it is called, first one is integer and second one is of type double which is nothing but decimal point numbers. Generally, in programming languages, 10 is treated as integer but 10.0 is treated as decimal point number, but in real life they are same.

If showProduct( 10,10.0) is called the output will be 'The product is 100'.

Strange fact is that, if you enter showProduct(10,10.5) the output will remain same as 'The product is 100'. This happens because in the 3rd line of code,which is <em>product=num1*(int)num2</em>, (int) is placed before num2 which makes num2 as of type integer, which means whatever the value of num2 two is given, numbers after decimal is erased and only the integer part is used there.

This is necessary in JAVA and many other programming languages as you <u>cannot</u><u> multiply two different datatypes</u> (here one is int and another is double). Either both of them should be of type int or both should be of type double.

You might be interested in
What is a best practice when approaching an automation effort?
Ksivusya [100]

Answer:

improving the current process before automating it

6 0
3 years ago
Which type of message format is designed to arouse curiosity, not showing the product or delivering quite enough information to
Anarel [89]

The type of message format that is designed to arouse curiosity by not showing the product or delivering quiet enough information to make sense is teaser. This is a way of providing information that is short and in which it does not identify the product or the whole message itself. 

7 0
2 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
2 years ago
Find the volume of the rectangular prism.<br>1<br>6 cm<br>32<br>cm​
Assoli18 [71]

Answer:

192 centimeters.

Explanation:

V= length x width x height

6 0
2 years ago
Jack has a fear of getting up in front of a group of people and giving a presentation. When he gave his last presentation, he ta
dezoksy [38]

Answer:

Jack has to be very calm and try his best to present himself in an outward way and think about the fact that by the end of the night no one will remember that he messed up, I feel like he'll be okay :)

7 0
2 years ago
Read 2 more answers
Other questions:
  • Elise has just edited two photos of her cat and three different photos of her dog. She needs to save all five of these photos in
    5·2 answers
  • Which social network site has 1.5 billion actives users per month?
    15·1 answer
  • George, a user, has contacted you to complain that his issue has not been resolved. He has already contacted your department twi
    9·1 answer
  • A user is attempting to format a 4 TB HDD using NTFS but only has the option to format the disk with a size of approximately 2 T
    15·1 answer
  • How many of you got the right answer from this app​
    8·1 answer
  • What are Manuscript signs​
    8·1 answer
  • Which of the following is not a responsibility of an operating system?
    9·2 answers
  • What are your strongest competencies? What will you do them? <br>❌NONSENSE ANSWER<br>​
    9·1 answer
  • When designers follow accepted standards and protocols, which of the four basic characteristics of network architecture is achie
    6·1 answer
  • If you have created users with administrator privileges on your windows 7 or linux systems, why bother creating other user accou
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!