Ask Question, Ask an Expert

+61-413 786 465

info@mywordsolution.com

Ask Computer Engineering Expert

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.

Computer Engineering, Engineering

  • Category:- Computer Engineering
  • Reference No.:- M92015287
  • Price:- $20

Priced at Now at $20, Verified Solution

Have any Question?


Related Questions in Computer Engineering

Chebyshevs theorem is used to approximate the proportion of

Chebyshev's theorem is used to approximate the proportion of observations for any data set, regardless of the shape of the distribution. Assume that a distribution has a mean of 255 and standard deviation of 20. Approxim ...

Question the discussion board db is part of the core of

Question: The Discussion Board (DB) is part of the core of online learning. Classroom discussion in an online environment requires the active participation of students and the instructor to create robust interaction and ...

What is the name of the text file on a windows computer

What is the name of the text file on a Windows computer that may store DNS to IP address mappings?

Write the java source code necessary to build a solution

Write the Java source code necessary to build a solution for the problem below:You have just taken a new "Teach for America" job in a very rural, impoverished neighborhood. The school system does not provide you with any ...

Question you are required to sort a file containing

Question : You are required to sort a file containing integers between 0 and 999999. You cannot afford to use one million pigeon-holes, so you decide instead to use one thousand pigeon-holes numbered from 0 to 999. You b ...

Software engineering software architecture questioncan

(Software engineering (Software Architecture) question) Can someone explain how a system's decomposition into components is driven by the system's features/requirements. Also, how can this decomposition be used to determ ...

It has been a bad day for the stock market and you have

It has been a bad day for the stock market and you have heard that only 30% of all stocks gained value. Suppose you have a portfolio of 10 securities and assume a binomial distribution for the number of your stocks that ...

Access your browsers security settings and configure the

Access your browser's security settings and configure the browser to refuse all cookies or to prompt you before allowing a cookie. Restart the browser; then visit several different Web sites. Be sure to visit popular sit ...

Question suppose you want to back up a huge file to a cd-r

Question : Suppose you want to back up a huge file to a CD-R. You can do this by splitting the file into smaller pieces and backup up those pieces separately. Write a utility program named FileSplitter that splits a larg ...

Question suppose that a car is moving through a suburban

Question : Suppose that a car is moving through a suburban environment that has a wireless channel with a coherence time of 10 ms and a coherence bandwidth of 600 kHz. The bit rate of the signal being used is 50 kbps. Ch ...

  • 4,153,160 Questions Asked
  • 13,132 Experts
  • 2,558,936 Questions Answered

Ask Experts for help!!

Looking for Assignment Help?

Start excelling in your Courses, Get help with Assignment

Write us your full requirement for evaluation and you will receive response within 20 minutes turnaround time.

Ask Now Help with Problems, Get a Best Answer

Why might a bank avoid the use of interest rate swaps even

Why might a bank avoid the use of interest rate swaps, even when the institution is exposed to significant interest rate

Describe the difference between zero coupon bonds and

Describe the difference between zero coupon bonds and coupon bonds. Under what conditions will a coupon bond sell at a p

Compute the present value of an annuity of 880 per year

Compute the present value of an annuity of $ 880 per year for 16 years, given a discount rate of 6 percent per annum. As

Compute the present value of an 1150 payment made in ten

Compute the present value of an $1,150 payment made in ten years when the discount rate is 12 percent. (Do not round int

Compute the present value of an annuity of 699 per year

Compute the present value of an annuity of $ 699 per year for 19 years, given a discount rate of 6 percent per annum. As