Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Assignment Create a class named Module 3 containing the following data members and methods (note that all data members and methods are for objects unless
Assignment
Create a class named Module3 containing the following data members and methods (note that all data members and methods are for objects unless specified as being for the entire class)
1) Data members: a. A Scanner object named reader (your class will need to import the Scanner class) b. Two int variables named format and pointIndex c. A double variable named inputDouble d. A String object named outputString, initialized to "" (an empty String) 2) Methods: a. A main method that, in order: Creates a new Module3 object Prints the text starting application to the console Calls method b) with the argument "Please enter a floating point number" and assigns its returned double value to inputDouble Calls method c) with the argument "How many decimal places to display?" and assigns its returned int value to format Calls method d) with the argument format and the String "The formatted number is: " Prints the text ending application to the console b. A method named getInput that accepts a String parameter, prints the parameter String to the console, accepts a user-entered double via the console (use Scanner.nextDouble()), prints "Thank you" to the console, and returns the user-entered double value. c. A method named getFormat that accepts a String parameter, prints the parameter String to the console, accepts a user-entered int via the console (use Scanner.nextInt()), prints "Thank you" to the console, and returns the user-entered int value. For error-checking, if the user enters a negative value, the program should print the message "invalid input. halting." to the console, then exit the program by calling System.exit(1); d. A method named convert that: Accepts two parameters: a String parameterand an int named places Assigns outputString the text "" + inputDouble Assigns to pointIndex the index of the decimal point (use String.indexOf()) If places is greater than 0, places should be incremented by one (to account for the decimal points extra character) Extracts the substring from outputString starting from index zero to the specified number of decimal places (i.e., pointIndex + places) Displays via the console the parameter Stringconcatenated with the substring from the previous bullet point Additional Constraints
The program should be implemented as a single file holding the public class Module3. Comments should be provided at the start of the class file (i.e., above the class definition) giving the class authors name and the date the program was finished.
Assignment
Create a class named Module3 containing the following data members and methods (note that all data members and methods are for objects unless specified as being for the entire class)
1) Data members:
a. A Scanner object named reader (your class will need to import the Scanner class)
b. Two int variables named format and pointIndex
c. A double variable named inputDouble
d. A String object named outputString, initialized to "" (an empty String)
2) Methods:
a. A main method that, in order:
Creates a new Module3 object
Prints the text starting application to the console
Calls method b) with the argument "Please enter a floating point number" and assigns its returned double value to inputDouble
Calls method c) with the argument "How many decimal places to display?" and assigns its returned int value to format
Calls method d) with the argument format and the String "The formatted number is: "
Prints the text ending application to the console
b. A method named getInput that accepts a String parameter, prints the parameter String to the console, accepts a user-entered double via the console (use Scanner.nextDouble()), prints "Thank you" to the console, and returns the user-entered double value.
c. A method named getFormat that accepts a String parameter, prints the parameter String to the console, accepts a user-entered int via the console (use Scanner.nextInt()), prints "Thank you" to the console, and returns the user-entered int value. For error-checking, if the user enters a negative value, the program should print the message "invalid input. halting." to the console, then exit the program by calling System.exit(1);
d. A method named convert that:
Accepts two parameters: a String parameterand an int named places
Assigns outputString the text "" + inputDouble
Assigns to pointIndex the index of the decimal point (use String.indexOf())
If places is greater than 0, places should be incremented by one (to account for the decimal points extra character)
Extracts the substring from outputString starting from index zero to the specified number of decimal places (i.e., pointIndex + places)
Displays via the console the parameter Stringconcatenated with the substring from the previous bullet point
Additional Constraints
The program should be implemented as a single file holding the public class Module3. Comments should be provided at the start of the class file (i.e., above the class definition) giving the class authors name and the date the program was finished.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started