Question: Answer In JAVA 1. Complete The Method Definition To Output The Hours Given Minutes.
Output For Sample Program:
3.5
import java.util.Scanner;
public class HourToMinConv {
public static void outputMinutesAsHours(double origMinutes) {
/* Your solution goes here */
}
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
double minutes;
minutes = scnr.nextDouble();
outputMinutesAsHours(minutes); // Will be run with 210.0, 3600.0, and 0.0.
System.out.println("");
}
}
2. Define a method printFeetInchShort, with int parameters numFeet and numInches, that prints using ‘ and ” shorthand. End with a newline.
Ex: printFeetInchShort(5, 8) prints:
Hint: Use \” to print a double quote.
import java.util.Scanner;
public class HeightPrinter {
/* Your solution goes here */
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
int userFeet;
int userInches;
userFeet = scnr.nextInt();
userInches = scnr.nextInt();
printFeetInchShort(userFeet, userInches); // Will be run with (5, 8), then (4, 11)
}
}
3. Write a method printShampooInstructions(), with int parameter numCycles, and void return type. If numCycles is less than 1, print “Too few.”. If more than 4, print “Too many.”. Else, print “N: Lather and rinse.” numCycles times, where N is the cycle number, followed by “Done.”. End with a newline.
Example output with input 2:
1: Lather and rinse.
2: Lather and rinse.
Done.
Hint: Declare and use a loop variable.
import java.util.Scanner;
public class ShampooMethod {
/* Your solution goes here */
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
int userCycles;
userCycles = scnr.nextInt();
printShampooInstructions(userCycles);
}
}
There are no reviews yet.