
TASK 5. Methods Overloading. Review Methods, Implement the following code, test it with different input, make sure it runs without errors.
![3 import java.util.Scanner;
4
5 public class ReportSum4 {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
60
// Prompt the user to enter the number of integers
System.out.println("Enter the number of integers you wil1 provide: ");
int num =
9
10
sc. nextInt();
11
12
// Prompt the user to enter the first integer
System.out.println("Enter the value for 'a' and press Enter: ");
13
14
15
int a =
sc. nextInt();
// Prompt the user to enter the second integer
System.out.println("Enter the value for 'b' and press Enter: ");
int b = sc.nextInt();
16
17
18
19
if (num == 3) {
// Prompt the user to enter the third integer
System.out.println("Enter the value for 'c' and press Enter: ");
int c = sc.nextInt();
// Display the result
System.out.printf( "Provided Integers: %4d and %4d and %4d, the total is %5d\n", a, b, c, sum(a, b, c));
20
21
22
23
24
25
26
else {
// Display the result
System.out.printf( "Provided Integers: %4d and %4d, the total is %5d\n", a, b, sum(a, b));
}
}
public static int sum(int num1, int num2){
return num1 + num2;
}
public static int sum(int num1, int num2, int num3){
return num1 + num2 + num3;
29
30
31
320
33
34
35e
36
}
38 }
37
39
Our client just contacted us and said that they are planning from time to time provide us four integers instead
of two and three
Hint: What would be a universal/generic solution for dealing with such clients? Should we be proactive and
write methods with 5, 6, 7, etc. parameters in advance?](https://content.bartleby.com/qna-images/question/2ec814c7-90f3-4435-9bb8-fcbab3f733ac/9ec55c54-996c-42f7-9508-80decfe00e97/s2hl12_thumbnail.png)

Solution:
Java code:
Main.java
import java.util.Scanner;
public class Main{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Prompt the user to enter number of Integer
System.out.println("Enter the number of integers you will provide: ");
int num = sc.nextInt();
// Prompt the user to enter first Integer
System.out.println("Enter the value of \'a\' and press Enter: ");
int a = sc.nextInt();
// Prompt the user to enter second Integer
System.out.println("Enter the value of \'b\' and press Enter: ");
int b = sc.nextInt();
if(num >= 3){
// Prompt the user to enter third Integer
System.out.println("Enter the value of \'c\' and press Enter: ");
int c = sc.nextInt();
if(num == 3){
// Display result of three number sum
System.out.printf("Provided Integers: %4d and %4d and %4d, the total is %5d\n",a, b, c ,sum(a, b, c));
}
else if ( num== 4){
System.out.println("Enter the value of \'d\' and press Enter: ");
int d = sc.nextInt();
// Display result for four number sum
System.out.printf("Provided Integers: %4d and %4d and %4d and %4d, the total is %5d\n",a, b, c, d ,sum(a, b, c, d));
}
}
else{
// Display result of 2 number sum
System.out.printf("Provided Integers: %4d and %4d, the total is %5d\n",a, b,sum(a, b));
}
}
//this method return the sum of two number
public static int sum(int num1, int num2){
return num1+num2;
}
//this method returns the sum of three numbers
public static int sum(int num1, int num2, int num3){
return num1+num2+num3;
}
//this method returns the sum of four numbers
public static int sum(int num1, int num2, int num3, int num4){
return num1+num2+num3+num4;
}
}
Step by stepSolved in 5 steps with 5 images

- What error message do you see in the Code Pad if you type the following? NumberDisplay.getValue() Take a careful look at this error message and try to remember it because you will likely encounter something similar on numerous future occasions. Note that the reason for the error is that the class name, NumberDisplay, has been used incorrectly to try to call the getValue method, rather than the variable name nd.arrow_forwardFirst, a quick definition of the method should be given before moving on to the three components that make it up.arrow_forwardProblem: To write the JUnit test cases for our methods, you need to create two test methods: testLeapYear: This method should test if the isLeapYear method returns true for a given leap year. For example, you can choose the year 2020 and verify if the method returns true for it. If it does, the test will pass. If it doesn't, the test will fail. testNotLeapYear: This method should test if the isLeapYear method returns false for a given non-leap year. For example, you can choose the year 1900 and verify if the method returns false for it. If it does, the test will pass. If it doesn't, the test will fail. --------------------------------------------------------------------------------------------------------------------------------------------------------- import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.Test; public class LeapYearTest { // Test case to check if a year is a leap year @Test public void testLeapYear() { //create…arrow_forward
- task-5 Change Summation Integers problem to Finding the minimumproblem. Make sure you properly wrote/updated all text messages, method names,and math calculations.Hint: You can use java.lang.Math.min() method.Example: System.out.printf("The min of the integers %4d and %4d and %4dis %7d\n", a, b, c, MinTest(a, b, c));Submit the source code files (.java files) and the console output screenshotsarrow_forwardtask_6 Change Summation Integers problem to Finding the minimumproblem. Make sure you properly wrote/updated all text messages, method names,and math calculations.Hint: You can use java.lang.Math.min() method.Example: System.out.printf("The min of the integers %4d and %4d and %4dis %7d\n", a, b, c, MinTest(a, b, c));Submit the source code files (.java files) and the console output screenshotsarrow_forwardCreate a calculator program. Get 2 numbers from the user. Create a method that adds the 2 numbers. Create a method that subtracts 1 number from the other. Create a method that multiplies the 2 numbers. Create a method that divides one number by another. It is important to check that you are not dividing by 0 here. You should be calling these methods from the main method and printing out the answers from the main method. Create a method that uses the modulus to return the remainder and the language is Javaarrow_forward
- True or False: (a) In a debugger, we can choose whether to step into, step over, or step out of a particular method call. (b) Debuggers, tests, and println() statements are all legitimate ways to help us find errors in our code.arrow_forwardcan someone help me? The questions are: 1. Add an addExerciseAdd method that adds an exercise to a private variable exercises in Exercise You don't need to create a getter or setter for this private variable. 2. Modify the constructors in Exercise so that you can create two types of workouts (let one constructor use the other; each variable can only have a value in one constructor): a training schedule with exercises, but without a trainer. a training schedule with exercises and with a trainer. import java.util.ArrayList;class Exerciseplan {private String customer;private String trainer;Exerciseplan(String customer) {this.customer = customer;}Exerciseplan(String customer, String trainer) {this.customer = customer;this.trainer = trainer;}private void printExercise(String name, String muscleGroup, Integer numberOfSets, Integer repetition, Integer restTime) {System.out.println("Oefening voor " + muscleGroup + ":" +" herhaal " + numberOfSets + " keer " +"(rust tussendoor " + restTime +…arrow_forwardcreate a method for each of the following results using the array concept and any type of loopi. The total mark of the student in each module. ii. Finding the list of modules that the student has passed or failed in that semester. iii. Finding the highest mark of the student in all assessments. JAVAarrow_forward
- In java just add code between the comments public class A6 {/*** In this Java file, you will write three methods that will ensure that the calls in the main methods are* properly executed. You do NOT have to change anything in the main() method. You have to write the methods that* will complete the program.** Pay attention to the method name, the method return type, and the method parameters.*/public static void main(String[] args) {/*Your first method will ask user to enter two values and return the exponent where the firstnumber will be the base and the second will be the exponent. Remember to use a mathematical function.If the user enters value 1 as 2 and value 2 as 3, output of your method should be 8 (2 raised to power 3)*/double calculatedExponent = exponentCalculator();System.out.println(calculatedExponent); //this should print out the exponent value/* Your second method will have two parameters. The first is a String and the second is a number. The methodshould return the…arrow_forwardThis solution is unclear and does not answer my question. I am trying to add a main method to my code.arrow_forwardAnswer in python "Create a class Die with one attribute called sides, which has a default value of 6. Write a method called r oll_die () that prints a random number between 1 and the number of sides the die has. Make a 6 - sided die and Roll it 10 times.Make a 10 - sided die and a 20 sided die. Roll each die 10 times. "arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





