All JAVA code
6.2.2:
Define a method printFeetInchShort, with int parameters numFeet and numInches, that prints using ' and " shorthand. Ex: printFeetInchShort(5, 8) prints:
5' 8"
Hint: Use \" to print a double quote
Sample program:
import java.util.Scanner;
public class HeightPrinter {
/* Your solution goes here */
public static void main (String [] args) {
printFeetInchShort(5, 8);
System.out.println("");
return;
}
}
6.4.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:
FIXME: Finish getUserNum() FIXME: Finish getUserNum() FIXME: Finish computeAvg() Avg: -1
Sample program:
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;
}
}
6.2.2:
Program:
Sample Output:
Code to be copied by the user:
/*import the utilities package*/
import java.util.*;
/*HeightPrinter class to display the height in shorthand notation*/
public class HeightPrinter
{
/*static method that accept two integer variables numFeet and numInches
and display height in short hand notation */
public static void printFeetInchShort(int numFeet, int numInches)
{
System.out.println(numFeet + "'" + numInches + "\"");
}
/* main method */
public static void main (String[] args)
{
//variable declaration
int numFeet, numInches;
//Scanner class
Scanner sc=new Scanner(System.in);
/*Prompt the user to enter number of feet and number of inches*/
System.out.println("Enter the number of feet: ");
numFeet = sc.nextInt();
System.out.println("Enter the number of Inches: ");
numInches = sc.nextInt();
//Display the output
System.out.print("In shorthand notation the height is: ");
printFeetInchShort(numFeet,numInches);
//clsing the scanner class
sc.close();
System.out.println("");
}
}
6.4.1:
Program:
Sample Output:
Code to be copied by the user:
/*class MthdStubsStatistics that define the stubs*/
public class MthdStubsStatistics
{
/*Stub: computeAvg() that returns the message "FIXME: Finish computeAvg()"*/
public static int computeAvg(int userNum1, int userNum2)
{
System.out.println("FIXME: Finish computeAvg()");
return -1;
}
/*Stub: getUserNum() that returns the message "FIXME: Finish getUserNum()"*/
public static int getUserNum()
{
System.out.println("FIXME: Finish getUserNum()");
return -1;
}
/*method that perform compuatations */
public static void main()
{
/*variable declarations*/
int userNum1 = 0;
int userNum2 = 0;
int avgResult = 0;
/*calling stubs*/
userNum1 = getUserNum();
userNum2 = getUserNum();
avgResult = computeAvg(userNum1, userNum2);
/*Display Average*/
System.out.println("Avg: " + avgResult);
return;
}
//main method
public static void main(String[] args)
{
main();
}
}
All JAVA code 6.2.2: Define a method printFeetInchShort, with int parameters numFeet and numInches, that prints...
THE LANGUAGE IS JAVA!! 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: FIXME: Finish getUserNum() FIXME: Finish getUserNum() FIXME: Finish computeAvg() Avg: -1 import java.util.Scanner; 3 public class MthdStubsStatistics { 1* Your solution goes here */ public static void main(String [] args) { int userNum1; int userNum2; int avgResult; userNum1 = getUserNum(); userNum2 = getUserNum(); avgResult = computeAvg(userNumi, userNum2); System.out.println("Avg: " +...
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: FIXME: Finish getUserNum() FIXME: Finish getUserNum() FIXME: Finish computeAverage() Avg: -1 import java.util.Scanner; public class MethodStubs{ /* Your solution goes here */ public static void main(String [] args) { int userNum1; int userNum2; int avgResult; MethodStubs stubTester = new MethodStubs(); userNum1 = stubTester.getUserNum(); userNum2 = stubTester.getUserNum(); avgResult = stubTester.computeAverage(userNum1, userNum2); System.out.println("Avg: " +...
In C please Write a function so that the main() code below can be replaced by the simpler code that calls function MphAndMinutesToMiles(). Original maino: int main(void) { double milesPerHour, double minutes Traveled; double hours Traveled; double miles Traveled; scanf("%f", &milesPerHour); scanf("%lf", &minutes Traveled); hours Traveled = minutes Traveled / 60.0; miles Traveled = hours Traveled * milesPerHour; printf("Miles: %1f\n", miles Traveled); return 0; 1 #include <stdio.h> 3/* Your solution goes here */ 1 test passed 4 All tests passed...
Define a method printFeetinchShort, with int parameters numFeet and numinches, that prints using 'and' shorthand. End with a newline. Ex printFeetinch Short(5,8) prints: 5' 8" Hint Use l'to print a double quote. 1 import java.util.Scanner; public class Height Printer public static void printFeet InchShort(user feet." public static void main(String[] args) Scanner ser new Scanner(System.in); int userfeet: int user Inches; 13 userFeet - ser.nextInt(); user Inches - Sen.nextInt(); printFeet Inch Short(user Feet, user Inches); // Will be run with 5, 8),...
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....
Identify a logical error in the following code and fix it. public class test1 { public static void main(String[] args){ int total; float avg; int a, b, c; a=10; b=5; c=2; total=a+b+c; avg=total/3; System.out.println("Average: "+avg); } } Answer: Write the output of the program below. import java.util.Scanner; public class test2 { public static void main(String[] arg){ int psid; String name; Scanner input=new Scanner(System.in); System.out.println("Enter your PSID"); psid=input.nextInt(); System.out.println("Enter your...
CHALLENGE ACTIVITY 3.4.2: Detect number range. Write an expression that prints "Eligible" if userAge is between 18 and 25 inclusive. Ex: 17 prints "Ineligible", 18 prints "Eligible". 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 import java.util.Scanner; public class AgeChecker { public static void main (String [] args) { int userAge = 0; userAge = 17; if( /* Your solution goes here */ ){ System.out.println("Eligible"); } else{ System.out.println("Ineligible"); } return; }...
Write a while loop that prints all positive numbers that are divisible by 10 and less than a given number n. For example, if n is 100, print 10 20 30 40 50 60 70 80 90. import java.util.Scanner; public class PositiveLess { public static void main(String[] args) { Scanner in = new Scanner(System.in); System.out.print("n: "); int n = in.nextInt(); ... while (...) { ...
(Java Zybooks) Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print a space after each seat, including after the last. Use separate print statements to print the row and column. Ex: numRows = 2 and numColumns = 3 prints: 1A 1B 1C 2A 2B 2C import java.util.Scanner; public class NestedLoops { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int...
JAVA HELP: Directions Write a program that will create an array of random numbers and output the values. Then output the values in the array backwards. Here is my code, I am having a problem with the second method. import java.util.Scanner; import java.util.Random; public class ArrayBackwards { public static void main(String[] args) { genrate(); print(); } public static void generate() { Scanner scanner = new Scanner(System.in); System.out.println("Seed:"); int seed = scanner.nextInt(); System.out.println("Length"); int length = scanner.nextInt(); Random random...