Question

In: Computer Science

1.  Complete the second printSalutation() method to print the following given personName "Holly" and customSalutation "Welcome": Welcome,...

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);
}
}

Solutions

Expert Solution

// 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);
    }
}

Related Solutions

In C++ Instructions: Use a void function to print the following message (should be in welcome...
In C++ Instructions: Use a void function to print the following message (should be in welcome function) Welcome to the Event Scheduling program create 3 int arrays with 3 positions (one array for days one array for moths and one array for years) (should be in main) Create a file that contains the following (you can just create the file or write the file in the program) 1 / 26 / 2021 12 / 13 / 2020 2 / 1...
3. [Method 1] In the Main class, write a static void method to print the following...
3. [Method 1] In the Main class, write a static void method to print the following text by making use of a loop. Solutions without a loop will receive no credit. 1: All work and no play makes Jack a dull boy. 2: All work and no play makes Jack a dull boy. 3: All work and no play makes Jack a dull boy. 4: All work and no play makes Jack a dull boy. 4. [Method 2] In the...
Complete the given C++ program (prob1.cpp) to read an array of integers, print the array, and...
Complete the given C++ program (prob1.cpp) to read an array of integers, print the array, and then find the index of the largest element in the array. You are to write two functions, printArray() and getIndexLargest(), which are called from the main function. printArray() outputs integers to std::cout with a space in between numbers and a newline at the end. getIndexLargest () returns the index of the largest element in the array. Recall that indexes start at 0. If there...
Question 1: What does the following code print to the console when the main method is...
Question 1: What does the following code print to the console when the main method is run? public static void referenceMystery(int x, int[] a) { x = 3; a[0] = 4; System.out.println(x+" "+a[0]); } public static void main(String[] args) { int x = 1, y = 2; int[] a = new int[1]; int[] b = new int[1]; referenceMystery(y, b); } 1. x a[0] 2. 1 3. 2 0 4. 3 4 Question 2: What does the following code print out...
Use the method of reduction of order to find a second solution y2 of the given...
Use the method of reduction of order to find a second solution y2 of the given differential equation such that {y1, y2} is a fundamental set of solutions on the given interval. t2y′′ +2ty′ −2y=0, t > 0, y1(t)=t (a) Verify that the two solutions that you have obtained are linearly independent. (b) Let y(1) = y0, y′(1) = v0. Solve the initial value problem. What is the longest interval on which the initial value problem is certain to have...
1. Use the get() method to print the value of the "name" key and the value...
1. Use the get() method to print the value of the "name" key and the value of the "age" key of the stuInfo dictionary. Use the variable given below: stuInfo = {'name': 'John Smith', "gpa": 3.456, "age": 20} 2. Use the dict() function to make a copy of the NY dictionary to NewYorkState dictionary. 3. Change the "name" value from "John Smith" to "James Bond" of the stuInfo dictionary. Use the variable given below: stuInfo = {'name': 'John Smith', "gpa":...
(IN PYTHON 3) Complete the following two tasks: 1. Words like first, second, and third are...
(IN PYTHON 3) Complete the following two tasks: 1. Words like first, second, and third are referred to as ordinal numbers. In this exercise, you will write a function that takes an integer as its only parameter and returns a string containing the appropriate English ordinal number as its only result. Your function must handle the integers between 1 and 12 (inclusive). It should return an empty string if a value outside of this range is provided as a parameter....
PLEASE USE MEHODES (Print part of the string) Write a method with the following header that...
PLEASE USE MEHODES (Print part of the string) Write a method with the following header that returns a partial string: public static String getPartOfString(int n, String firstOrLast, String inWord) Write a test program that uses this method to display the first or last number of characters of a string provided by the user. The program should output an error if the number requested is larger than the string. SAMPLE RUN #1: java PartOfString Enter a string: abracadabra↵ Enter the number...
Using SPSS complete an analysis for the following question. Print out your results and take a...
Using SPSS complete an analysis for the following question. Print out your results and take a picture of the results with your interpretation on the printout. You can type the interpretation or handwrite the interpretation. The subject line should be SPSSQ4 last name first name. 1. A gerontologist investigating aspects of aging wanted to determine if leaner (not fat) rats might have longer life expectancies. She randomly assigned newborn rats to 1 of 3 treatment groups: unlimited food, 90% of...
Write a pseudocode for the following: given that a path is a hamiltonian path, print all...
Write a pseudocode for the following: given that a path is a hamiltonian path, print all its edges.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT