1. Define stubs for the methods called by the below main(). Each stub should pri
ID: 3686529 • Letter: 1
Question
1. Define stubs for the methods called by the below main(). Each stub should print "FIXME: Finish methodName()" followed by a newline, and should return -1. Example output:
import java.util.Scanner;
public class MthdStubsStatistics {
/* Your solution goes here */
public static void main() {
int userNum1 = 0;
int userNum2 = 0;
int avgResult = 0;
userNum1 = getUserNum();
userNum2 = getUserNum();
avgResult = computeAvg(userNum1, userNum2);
System.out.println("Avg: " + avgResult);
return;
}
}
2. Using the celsiusToKelvin function as a guide, create a new function, changing the name to kelvinToCelsius, and modifying the function accordingly.
import java.util.Scanner;
public class TemperatureConversion {
public static double celsiusToKelvin(double valueCelsius) {
double valueKelvin = 0.0;
valueKelvin = valueCelsius + 273.15;
return valueKelvin;
}
/* Your solution goes here */
public static void main (String [] args) {
double valueC = 0.0;
double valueK = 0.0;
valueC = 10.0;
System.out.println(valueC + " C is " + celsiusToKelvin(valueC) + " K");
valueK = 283.15;
System.out.println(valueK + " is " + kelvinToCelsius(valueK) + " C");
return;
}
}
3. Complete the second printSalutation() method to print the following given personName "Holly" and customSalutation "Welcome":
import java.util.Scanner;
public class MultipleSalutations {
public static void printSalutation(String personName) {
System.out.println("Hello, " + personName);
return;
}
//Define void printSalutation(String personName, String customSalutation)...
/* Your solution goes here */
public static void main (String [] args) {
printSalutation("Holly", "Welcome");
printSalutation("Sanjiv");
return;
}
}
Explanation / Answer
1).
import java.util.Scanner;
public class MthdStubsStatistics {
/* Your solution goes here */
public static int getUserNum(){
System.out.println("FIXME: Finish getUserNum()");
return -1;
}
public static int computeAvg(int userNum1, int userNum2){
System.out.println("FIXME: Finish computeAvg()");
return -1;
}
public static void main(String args[]) {
int userNum1 = 0;
int userNum2 = 0;
int avgResult = 0;
userNum1 = getUserNum();
userNum2 = getUserNum();
avgResult = computeAvg(userNum1, userNum2);
System.out.println("Avg: " + avgResult);
return;
}
}
/*
Output:
FIXME: Finish getUserNum()
FIXME: Finish getUserNum()
FIXME: Finish computeAvg()
Avg: -1
*/
2).
import java.util.Scanner;
public class TemperatureConversion {
public static double celsiusToKelvin(double valueCelsius) {
double valueKelvin = 0.0;
valueKelvin = valueCelsius + 273.15;
return valueKelvin;
}
/* Your solution goes here */
public static double kelvinToCelsius(double valueKelvin) {
double valueCelsius = 0.0;
valueCelsius = valueKelvin - 273.15;
return valueCelsius;
}
public static void main (String [] args) {
double valueC = 0.0;
double valueK = 0.0;
valueC = 10.0;
System.out.println(valueC + "C is " + celsiusToKelvin(valueC) + " K");
valueK = 283.15;
System.out.println(valueK + "K is " + kelvinToCelsius(valueK) + " C");
return;
}
}
/*
Output:
10.0C is 283.15 K
283.15K is 10.0 C
*/
3).
import java.util.Scanner;
public class MultipleSalutations {
public static void printSalutation(String personName) {
System.out.println("Hello, " + personName);
return;
}
//Define void printSalutation(String personName, String customSalutation)...
/* Your solution goes here */
public static void printSalutation(String personName, String customSalutation) {
System.out.println(customSalutation+", " + personName);
return;
}
public static void main (String [] args) {
printSalutation("Holly", "Welcome");
printSalutation("Sanjiv");
return;
}
}
/*
Output:
Welcome, Holly
Hello, Sanjiv
*/
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.