Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Complete the program, MethodLab.java, by adding the methods specified in parts 1

ID: 3589446 • Letter: C

Question

Complete the program, MethodLab.java, by adding the methods specified in parts 1, 2, & 3 below:

1. Write a void method called greetingwitch takes three String parameters and formats and prints

a title, first name, and last name in the following format and prints it out:

blank line

Dear <title> <first name> <last name>,

blank line

2. Write a method called maxthat takes two int parameters, num1 and num2, and returns the larger

of the two integers.

3. Write a method called sumTo that takes two int parameters, num1 and num2 and returns the sum

of all numbers from the smaller number to the larger number, inclusive. (i.e. given 2 and 4, returns

9. Because 2 + 3 + 4 = 9) (if given 4 and 2, returns 9 as well. Because 2 + 3 + 4 = 9)

USE THE GUIDE LINE BELOW

Explanation / Answer

package org.students;

import java.io.*;
import java.util.Scanner;


public class MethodLab {

public static void main(String[] args) {
// variable declarations for part 1
String title;
String firstName;
String lastName;
Scanner in = new Scanner(System.in);

// prompt for input for part 1
System.out.print("Enter a title:");
title = in .next();
System.out.print("Enter your first name:");
firstName = in .next();
System.out.print("Enter your last name:");
lastName = in .next();

// call the method for part 1
greeting(title, firstName, lastName);

// variable declarations for part 2
int number1;
int number2;

// user prompts for part 2
System.out.print("Enter first number:");
number1 = in .nextInt();
System.out.print("Enter second number:");
number2 = in .nextInt();

// call the method for part 2 inside the println statement
System.out.println("The largest number is " + max(number1, number2));

//Call the method for part 3 inside the println statement
System.out.println("The sum of " + number1 + " to " + number2 + " is " + sumTo(number1, number2));

in .close();
}

/******************** greeting method goes here*********************/
public static void greeting(String title, String firstName, String lastName) {
System.out.println(title + " " + firstName + " " + lastName);
}


/***********************end of method*************************/

/******************** max method goes here*********************/


public static int max(int number1, int number2) {
if (number1 > number2)
return number1;
else
return number2;
}


/***********************end of method*************************/

/******************** sumTo method goes here*********************/

public static int sumTo(int number1, int number2) {
int sum = 0;
for (int i = number1; i <= number2; i++) {
sum += i;
}
return sum;
}

/***********************end of method*************************/

}

___________________

Output:

Enter a title:Dear
Enter your first name:Kane
Enter your last name:Williams
Dear Kane Williams
Enter first number:22
Enter second number:33
The largest number is 33
The sum of 22 to 33 is 330


_____________Could you rate me well.Plz .Thank You

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote