In: Computer Science
1. Complete the second printSalutation() method to print the following given personName "Holly" and customSalutation "Welcome":
Welcome, Holly
End with a newline.
What I am given:
import java.util.Scanner;
public class MultipleSalutations {
public static void printSalutation(String personName) {
System.out.println("Hello, " + personName);
}
//Define void printSalutation(String personName, String customSalutation)...
/* Your solution goes here */
public static void main (String [] args) {
printSalutation("Holly", "Welcome");
printSalutation("Sanjiv");
}
}
2. Write a second convertToInches() with two double parameters, numFeet and numInches, that returns the total number of inches. Ex: convertToInches(4.0, 6.0) returns 54.0 (from 4.0 * 12 + 6.0).
What I am given:
import java.util.Scanner;
public class FunctionOverloadToInches {
public static double convertToInches(double numFeet) {
return numFeet * 12.0;
}
/* Your solution goes here */
public static void main (String [] args) {
double totInches;
totInches = convertToInches(4.0, 6.0);
System.out.println("4.0, 6.0 yields " + totInches);
totInches = convertToInches(5.8);
System.out.println("5.8 yields " + totInches);
}
}
// 1)
public class MultipleSalutations { public static void printSalutation(String personName) { System.out.println("Hello, " + personName); } public static void printSalutation(String personName, String customSalutation) { System.out.println(customSalutation + ", " + personName); } public static void main(String[] args) { printSalutation("Holly", "Welcome"); printSalutation("Sanjiv"); } }
// 2)
import java.util.Scanner; public class FunctionOverloadToInches { public static double convertToInches(double numFeet) { return numFeet * 12.0; } public static double convertToInches(double numFeet, double numInches) { return numFeet * 12.0 + numInches; } public static void main(String[] args) { double totInches; totInches = convertToInches(4.0, 6.0); System.out.println("4.0, 6.0 yields " + totInches); totInches = convertToInches(5.8); System.out.println("5.8 yields " + totInches); } }