Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a ceil method that takes a single double as an argument and returns an int

ID: 3936620 • Letter: W

Question

Write a ceil method that takes a single double as an argument and returns an int. The int should be the next highest whole integer (eg 3.14 would return 4). Use math, not built-in Java methods (est. 20 mins) Write a method that takes a string as an argument. If your string is more than 10 letters or less than 1 letter return "Bad number". Otherwise, return the telephone number equivalent of the input Your return can be of type String. Eg. A, B, or C are 2, D, E, F are 3 etc, "GOCOSC1046" would return "4626721046" (even better would be "462-672-1046" but not required) Write a brief main method that collects input and shows off your methods.

Explanation / Answer

import java.math.*; public class TestRound11 { public static double round(double d, int decimalPlace){ BigDecimal bd = new BigDecimal(Double.toString(d)); bd = bd.setScale(decimalPlace,BigDecimal.ROUND_HALF_UP); return bd.doubleValue(); } } private static String getInput(Scanner in) { // Ask the user to enter string here do { System.out.println("Enter a string here: "); String input = in.nextLine(); // Create an if/else statement to find out if the user // entered input if (input.trim().length() > 0) { return input.trim(); } else { System.out.println("Error -- " + "You must enter a string!"); } } while (true); } private static int getWordCount(String input) { String[] result = input.split(" "); return result.length; } public static void main(String args[]){ double d = 3.1537; BigDecimal bd = new BigDecimal(d); bd = bd.setScale(2,BigDecimal.ROUND_HALF_UP); // output is 3.15 System.out.println(d + " : " + round(d, 2)); // output is 3.154 System.out.println(d + " : " + round(d, 3)); //Print out the number of words within the users string here int counter = getWordCount(getInput(new Scanner(System.in))); System.out.println("The number of words in the string are: " + counter); }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote