Question: Utility.Java must contain the following methods: A method named inputDouble that will accept a single String parameter representing the prompt to display to the user

Utility.Java must contain the following methods:

A method named inputDouble that will accept a single String parameter representing the prompt to display to the user and return a double number read from the keyboard. This method should:

1. display the prompt, followed by a colon and single space (no newline),

2. read a double value from the keyboard using the appropriate Scanner method (assume that a valid double value will be entered),

3. consume the newline character following the double (also using Scanner object), and

4. return the double value.

A method named inputLine that will accept a single String parameter representing the prompt to display to the user and return a String containing the whole line that the user types in. This method should:

1. display the prompt, followed by a colon and a single space (no newline),

2. read a line of input, and

3. return the line of input.

A method named formatTwoDecimals that will accept a double value of up to 15 digits and return a String containing that value rounded to exactly two decimal places.

For example, formatTwoDecimals(34.2589) would return 34.26.

A method named formatNoDecimals that will accept a double value of up to 15 digits and return a String containing that value rounded to an integer, with no decimal point.

For example, formatNoDecimals(34.6589) would return 35 .

My code so far thats not compiling:

import java.until.Scanner; import java.text.DecimalFormat;

private static Scanner sc = new Scanner(System.in);

public class Utility { public static double inputDouble(String prompt){ double input; scanner keyboard; keyboard = new Scanner(System.in); system.out.print(prompt + " : "); input = keyboard.nextDouble(); keyboard.nextLine(); return input; } public static double inputLine(String prompt){ double input; scanner keyboard; keyboard = new Scanner(System.in); system.out.print(prompt + " : "); input = keyboard.nextLine(); keyboard.nextLine(); } public static double formatTwoDecimals(string prompt){ double input; Scanner keyboard; keyboard = new Scanner(System.in); system.out.print(prompt + " : "); input = keyboard.nextDouble(); keyboard.nextLine(); if(double.toString(input).length()-1>15); { do{ input = keyboard.nextDouble(); keyboard.nextLine(); } while (Double.toString(input).length()-1>15); } return Math.round(input*100.0)/100.0; } public static int formatNoDecimals(String prompt){ double input; scanner keyboard; keyboard = new Scanner(system.in); system.out.prompt(+ " : ") input = keyboard.nextDouble(); keyboard.nextLine(); if(double.toString(input).length()-1>15);{ do{ system.out.prinntln("Please enter maximum 15 didgts.") }while (Double.toString(input).length() - 1 > 15); } return (int) Math.round(input); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!