Reference no: EM131260503
This snippet of code allows the user to input two integers and then divides them. Unfortunately, it is error prone (ie allows a divide by zero error) and does not give the user much feedback when the two numbers are not evenly divisible.
Scanner userIn = new Scanner(System.in);
int numerator, denominator;
int result;
numerator = userIn.nextInt();
denominator = userIn.nextInt();
result = numerator / denominator;
First, separate the input function from the math function, placing the input function into a class with a main method, and the math function into a the class MyMath.
Next, declare two exception classes, a ZeroDenominatorException which should be a subclass of RuntimeException and a NotEvenlyDivisibleException which should be a subclass of Exception.
Next, within the MyMath class method that divides the two numbers, throw a ZeroDeonminatorException if the denominator is zero and throw a NotEvenlyDivisibleException if the two numbers are not evenly divisible (ie there is any remainder).
Finally, in the main method, add the error handling code necessary to provide feedback to the user when the division cannot be done, or when the division will end in a remainder that would not be shown.
Subnet address of host
: A host on the network has an IPv4 address of 172.26.84.236 with a subnet mask of 255.255.255.240. What is the subnet address of this host and how many hosts could this network have?
|
Pros and cons of hiring multi craft maintenance personnel
: What might be done to help take Frito-Lay to the next level of outstanding maintenance? Consider factors such as sophisticated software.
|
Determine the magnitude of the force p
: A 4-mm-diameter steel wire, 3.2 m long, carries an axial tensile load P. Find the maximum safe value of P if the allowable normal stress is 280 MPa and the elongation of the wire is limited to 4 mm. Use E = 200 GPa.
|
Identify and discuss 2 treatment modalities for mr. potts
: Identify and discuss 2 treatment modalities for Mr. Potts that you believe would be appropriate and useful for his recovery. State why you believe the 2 treatment modalities that you have chosen would be effective for Mr. Potts.
|
Separate the input function from the math function
: First, separate the input function from the math function, placing the input function into a class with a main method, and the math function into a the class MyMath.
|
Prepare statement of revenues and expenditures
: Capital Projects Transactions. In 2017, Riverside began work on an outdoor amphitheater and concession stand at the city's park. It is to be financed by a $3,500,000 bond issue and supplemented by a $500,000 General Fund transfer. Prepare a balance s..
|
What is the expected number of breakdowns per year
: What is the expected number of breakdowns per year with station employees performing maintenance? - What is the cost of the current maintenance policy?
|
How art is experienced through senses and artist connection
: As you read Alice Walker's "Everyday Use," be aware of how the quilt in the story is discussed as both an artistic creation with aesthetic properties that enhance a sensory response, as well as a creation that has a significant practical use.
|
Reports zero taxable income
: Bonnie, who is single, reports a zero taxable income in 2016. Bonnie itemized her deductions and takes the personal exemption. She reports positive AMT timing adjustments of $200,000. and the other AMT positive adjustments of $100,000 for the year. W..
|