Separate the input function from the math function

Assignment Help Basic Computer Science
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.

Reference no: EM131260503

Questions Cloud

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..

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Create a web page for a company

Imagine that you have just started your own freelancing business. You have been hired to create a Web page for a company of your choice that announces the item of the week, month, or year. (e.g., Car of the Year, Pet of the Month, Sandwich of the Wee..

  Summarize the purpose of the sql language

Summarize the purpose of the SQL language

  Deal with the starvation problem

Can a system detect that some of its processes are starving? If you answer "yes," explain how it can. If you answer "no," explain how the system can deal with the starvation problem.

  Examine the performance of your implementation

Examine the performance of your implementation as a function of k.

  Recognize and explain six basic computer operations

Recognize the six basic computer operations. Describe each operation's role in computer program and indicate whether it is part of program's input component,

  Declare a variable

Assume the existence of a Window class with methods getWidth and getHeight, and a subclass TitledWindow, with a constructor accepts a string corresponding to the title of the window.

  Add text in dialog balloons or thought bubbles

In addition, the text should match the personality of the character with whom it is associated or the tone of the message itself.

  Use a block diagram for the decoder

Implement the circuit with a 3x8 decoder and OR gates. Use a block diagram for the decoder.

  Why is an e-mail use policy important

1). Why is the issue of trust an integral part of a security policy 2). Why is an e-mail use policy important?

  Use matlab to write a function function

Use Matlab to write a function function, call it fRotate, with a function, an interval, and an angle as its input arguments.

  What is the result of issuing 0x08 function code

In a SCADA system, what is the result of issuing 0x08 function code followed by a 0x01 subfunction code on a slave using Modbus?

  Describes how a honey pot was used

Describes how a honey pot was used

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd