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
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
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
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*********************/ /***********************end of method*************************/ /******************** max method goes here*********************/ /***********************end of method*************************/ /******************** sumTo method goes here*********************/ /***********************end of method*************************/ }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started