Answer in JAVA 1. Complete the method definition to output the hours given minutes. Output for…
The following solution is suggested to handle the subject “Answer in JAVA 1. Complete the method definition to output the hours given minutes. Output for…“. Let’s keep an eye on the content below!
Question “Answer in JAVA 1. Complete the method definition to output the hours given minutes. Output for…”
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:
5' 8"
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);
}
}
Answer
import java.util.Scanner; public class HourToMinConv { public static void outputMinutesAsHours(double origMinutes) System.out.print(origMinutes / 60); 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(""); } }
import java.util.Scanner; public class HeightPrinter public static void printFeetInchShort(int numFeet, int numInches) System.out.println(numFeet + "' " + numInches + "\""); 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)
import java.util.Scanner; public class ShampooMethod static void printShampooInstructions(int numCycles) { if (numCycles < 1) { System.out.println("Too few.."); } else if (numCycles > 4) { System.out.println("Too many.."); } else { for (int i = 1; i <= numCycles; ++i) { System.out.println(i + ": Lather and rinse."); } System.out.println("Done."); } } public static void main(String[] args) Scanner scnr = new Scanner(System.in); int userCycles; userCycles = scnr.nextInt(); printShampooInstructions(userCycles);
Conclusion
Above is the solution for “Answer in JAVA 1. Complete the method definition to output the hours given minutes. Output for…“. We hope that you find a good answer and gain the knowledge about this topic of engineering.