Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Assignment Create a class named Module2, for performing various numeric operations as given below. You should submit your source code file (Module2.java). The Module2 class

image text in transcribed
image text in transcribed
Assignment Create a class named Module2, for performing various numeric operations as given below. You should submit your source code file (Module2.java). The Module2 class will import the class java.util.Scanner and should contain the following data fields and methods (note that all data and methods are for objects unless specified as being for the entire class) 1) Data fields: a. A String named value b. An int named decimalPlaces 2) Methods: a. A Module2 constructor method that accepts no parameters and initializes the data fields value to an empty String and decimalPlaces to zero b. A method named value RoundUp that accepts a parameter String s, converts s to a double using the method Double.parse Double(), and returns, as an int, that double rounded up to the next higher int value. Note that negative and positive values will need to be processed differently-typecasting to int will round negative values up but positive values down. c. A method named value Round Down that accepts a parameter String s, converts s to a double, and returns, as an int, that double rounded up to the next lower int value. Again, negative and positive values will need to be processed differently. d. A method named value DecimalPlaces that accepts two parameters a String s and an int places. The parameter s contains the text representation of a number and the method will return another String which represents that number with places as the number of decimal places. If the number contains more decimal places than places, the last decimal place should be rounded off. If places == 0, the number should not have a decimal point and should be rounded to the nearest integer. e. A method named getValue that accepts a parameter String prompt and does the following: creates a new Scanner object, prints prompt to the console, uses Scanner's nextLine method to read the user input, and returns the String obtained from Scanner's nextLine method f. A method named getInput with return type void and accepts no parameters and, in order: . Calls method e) with the argument "Please enter the value" and stores the result in value. If the user enters the String "exit", the program should end by calling the method System.exit(0). Calls method e) with the argument "Please enter the number of decimal places", converts the returned String to an int (use Integer.parseInt()), and stores the result in decimalPlaces Prints to the console, with appropriate text labels, the number represented by value to 1) decimal Places decimal places; 2) rounded up; and 3) rounded down Prints an empty line of text g. A main method that, in order: Creates a new Module2 object named m using the constructor from a) Starts an endless loop using while(true) and calls getInput() inside it, i.e.: while(true) {m.getInput();} Additional Constraints The program should be implemented as a single file holding the public class Module2. Comments should be provided at the start of the class file (i.e., above the class definition) giving the class author's name and the date the program was finished

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions