Write a program that contains three methods: Method max (int x, int y) returns the maximum...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Write a program that contains three methods: Method max (int x, int y) returns the maximum value of two integer values. Method min (int x, int y) returns the minimum value of two integer values. Method average (int x, int y) returns the average of two integer values. You should design the above methods to be in your program first before you proceed to write anything in the main method. Remember, write these methods assuming the variables in them already exist. A method is a function which you feed with input (determine what this input is using the parameters in the method); the method should then proceed in using these parameters in the way it was designed to use them. Therefore, whenever you designate a parameter, it is a variable that can be used in your methods. Write a main method that asks the user for three numbers. These three numbers should then be passed as actual parameters to the three methods you have which should return values back to the main method to be printed in a manner like shown below in the sample. Tip: When getting the average, please make sure you use a double or float for the variable. Pay attention as you may get a truncated answer as you are getting the average of integers. Remember casting! Remember, the class name should be Lab10A. The user input is indicated in bold. Sample output #1: Enter number 1: 4 Enter number 2: 9 Min is 4 Max is 9 Average is 6.5 Sample output #2: Enter number 1: 45 Enter number 2: 11 Min is 11 Max is 45 Average is 28 Overview: Up until now, the programs you have written have started at the "main" method and executed from top to bottom. Methods are also commonly called "functions" or "procedures". A method is a group of code that has a name and a single function. We can send information to the method to get it started (called parameters), and the method can return information when it is done with a return statement. This information must be the same data type as the return type. These are choices that you have to make when designing a method - and they can be confusing when you first see them. All methods you write in this class have a "template" that looks like: <return type> <method name> (<parameters> ) About each one: The return type is a data type (e.g. int, Boolean, char, string, int[], char[]...). It is the kind of data this method will return. If the method does not return data, the return type is void. If the method does return data, you must include a return statement in your method (this is usually done when the method finishes calculating a result). The method name is easy. Valid method names follow the same rules as naming variables. Parameters are listed between parentheses ( ) and are just a set of variables used to "catch incoming data". They are a listing of the data that must be passed to the method for it to do its job. For example, if you have a method called addTwoNumbers(), it needs two numbers to do its job, so those appear as two variables. If a method does not require any information to get started, the parentheses are empty. Tying all three things together, the example method would look like: int addTwoNumbers (int x, int y) { int result = x + y; } return result; For the Java and C# folks, you would have to put the keywords "public" and "static" before the return type. Note: the method above won't run until you call it (from main). That code would look like: int temp addTwoNumbers (6, 14); Write a program that contains three methods: Method max (int x, int y) returns the maximum value of two integer values. Method min (int x, int y) returns the minimum value of two integer values. Method average (int x, int y) returns the average of two integer values. You should design the above methods to be in your program first before you proceed to write anything in the main method. Remember, write these methods assuming the variables in them already exist. A method is a function which you feed with input (determine what this input is using the parameters in the method); the method should then proceed in using these parameters in the way it was designed to use them. Therefore, whenever you designate a parameter, it is a variable that can be used in your methods. Write a main method that asks the user for three numbers. These three numbers should then be passed as actual parameters to the three methods you have which should return values back to the main method to be printed in a manner like shown below in the sample. Tip: When getting the average, please make sure you use a double or float for the variable. Pay attention as you may get a truncated answer as you are getting the average of integers. Remember casting! Remember, the class name should be Lab10A. The user input is indicated in bold. Sample output #1: Enter number 1: 4 Enter number 2: 9 Min is 4 Max is 9 Average is 6.5 Sample output #2: Enter number 1: 45 Enter number 2: 11 Min is 11 Max is 45 Average is 28 Overview: Up until now, the programs you have written have started at the "main" method and executed from top to bottom. Methods are also commonly called "functions" or "procedures". A method is a group of code that has a name and a single function. We can send information to the method to get it started (called parameters), and the method can return information when it is done with a return statement. This information must be the same data type as the return type. These are choices that you have to make when designing a method - and they can be confusing when you first see them. All methods you write in this class have a "template" that looks like: <return type> <method name> (<parameters> ) About each one: The return type is a data type (e.g. int, Boolean, char, string, int[], char[]...). It is the kind of data this method will return. If the method does not return data, the return type is void. If the method does return data, you must include a return statement in your method (this is usually done when the method finishes calculating a result). The method name is easy. Valid method names follow the same rules as naming variables. Parameters are listed between parentheses ( ) and are just a set of variables used to "catch incoming data". They are a listing of the data that must be passed to the method for it to do its job. For example, if you have a method called addTwoNumbers(), it needs two numbers to do its job, so those appear as two variables. If a method does not require any information to get started, the parentheses are empty. Tying all three things together, the example method would look like: int addTwoNumbers (int x, int y) { int result = x + y; } return result; For the Java and C# folks, you would have to put the keywords "public" and "static" before the return type. Note: the method above won't run until you call it (from main). That code would look like: int temp addTwoNumbers (6, 14);
Expert Answer:
Answer rating: 100% (QA)
Heres the best way to solve it Expertverified 100 1 rating Share include using namespace std int M... View the full answer
Related Book For
Java An Introduction To Problem Solving And Programming
ISBN: 9780134462035
8th Edition
Authors: Walter Savitch
Posted Date:
Students also viewed these programming questions
-
Design a Java class that represents a cache with a fixed size. It should support operations like add, retrieve, and remove, and it should evict the least recently used item when it reaches capacity.
-
5) On the graphs below show the difference between a change in price and a change in demand. Fully label graphs for full marks! (2+2 marks) Change in price Change in demand X 6) A change in the price...
-
A production supervisor at a major chemical company wishes to determine whether a new catalyst, catalyst XA-100, increases the mean hourly yield of a chemical process beyond the current mean hourly...
-
Us-based Polyglot Industries will send its employee Jack Pundit to study Danish in an intensive training course in Copenhagen. Jack will need dkk 10,000 at t = 3 months when classes begin, and dkk...
-
Front-wheel-drive cars do not distribute the work involved in stopping the car equally among all wheels. The front wheel brakes dissipate about 60% of the energy transfer involved in braking, while...
-
Africa offers a fast growing and exciting mobile phone market, with more than 50% growth per year since 2002. More than 28% of African consumers own mobile phones; a larger market than North America....
-
Comprehensive variance analysis, responsibility issues (CMA, adapted) Styles, Inc. manufactures a full line of well-known sunglasses frames and lenses. Styles uses a standard costing system to set...
-
Using less human effort, less manufacturing space, less investment in tools, and less engineering time is the basic premise of Blank______. Multiple choice question. flexible manufacturing mass...
-
In December, Northern Kiteboarding magazine collected $80,000 for subscriptions for the next calendar year. The company collects cash in advance and then downloads the magazines to subscribers each...
-
What is critical thinking? Why do you believe that it is important that you develop critical thinking skills? Why do they matter - in work and in life? What might you do to improve your critical...
-
Anderson Equipment Company uses a spreadsheet to prepare its financial statements. Using the following amounts from its spreadsheet, what would it report as net income?
-
Frank is a captain in the U.S. Army who files single. In April 2010, he bought a house in Lawton, Oklahoma where he was stationed. He lived in the home until June 2013 when he was sent overseas on...
-
Ozark Cabin Resorts rents vacation cabins to tourists. Customers pay at the time they book their reservations. In 2020, Ozark Cabin Resorts had a beginning balance of $8,300 in its Unearned Service...
-
Brighton Company has $920 of supplies reported on its unadjusted trial balance as of August 30. At the end of August, Brighton Company had $450 worth of supplies remaining. What is the entry to...
-
Explain the fundamental differences between science and pseudo-science. also what is the ultimate goal of it? , what is the role of observable reality?, how's it willing to change options as new...
-
Given that F(s) = 2(s+ 1) Calculate L{u(t 3)f(t 3)}
-
Sundial Technologies produces and sells customized network systems in New Brunswick. The company offers a 60-day, all software and labor-and an extra 90-day, parts-only- warranty on all of its...
-
Modify the driver program from Practice Program 3 in Chapter 8 to use three exception classes called CylinderException, LoadException, and TowingException. The number of cylinders must be an integer...
-
Write a program that checks a text file for several formatting and punctuation matters. The program asks for the names of both an input file and an output file. It then copies all the text from the...
-
You have three identical prizes to give away and a pool of ten finalists. The finalists are assigned numbers from 1 to 10. Write a program to randomly select the numbers of three finalists to receive...
-
Dalia owns a small public relations firm and wants to contract with her insurance provider to offer her employees the option to purchase short-term disability insurance. The insurance will pay out...
-
Distinguish between portfolio (capital) investment and direct investment.
-
What are performance requirements?
Study smarter with the SolutionInn App