Snippet of code allows the user to input

Assignment Help Basic Computer Science
Reference no: EM131257600

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: EM131257600

Questions Cloud

Installing the new operating system : Your supervisor tasked you with installing the new operating system from Microsoft on all desktops and laptops in the company.
Determine the equilibrium price and quantity : Determine the implications for each of the computed elasticities for the business in terms of short-term and long-term pricing strategies. Provide a rationale in which you cite your results.
Determine the percent of failures : A manufacturer of disk drives for notebook computers wants an MTBF of at least 50,000 hours. -Determine the Percent of failures,  Number of failures per unit-hour  and  MTBF at this point in the testing.
What is the importance of market segmentation : What are the characteristics of markets and market segments? What is the importance of market segmentation? What are some of the criteria for successful marketing segmentation
Snippet of code allows the user to input : 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.
Save for retirement : Wendy decides to save for her retirement starting on her 25th birthday. She puts $1,000 a year in an investment that earns 10% a year compounded annually. She does this for 20 years (she is then 45, and has invested $20,000) and then stops adding mor..
Determine the various ways to integrate technology : Explain at least three (3) reasons why these particular tools are considered an emerging technology to the educational or training setting you have chosen. Using the current literature, support your rationale.
How leaders influence employees to achieve goals : Draft three interview questions that address how leaders influence employees to achieve organizational goals
Exponential back-off algorithm : Two CSMA/CD stations are trying to transmit a few long video files. After each frame is sent, they contend for the channel using binary exponential back-off algorithm.

Reviews

Write a Review

Basic Computer Science Questions & Answers

  How can buffer-overflow attacks be avoided

How can buffer-overflow attacks be avoided?

  A photo-sharing startup offers

A photo-sharing startup offers the following service. A client may upload any number N of photos and the server will compare each of the N pairs of photos with their proprietary image matching algorithms to see if there is any person that is in both ..

  Important to accomplishing corporate objectives

Having staff with the proper skill sets is immensely important to accomplishing corporate objectives. List and support three best practices in staffing future organizational needs.

  Number of cpu processing cycles

Taking into account the availability of today's powerful computers, why is programming efficiency important? Consider how the number of lines of programming instructions impact the number of CPU processing cycles?

  Problem and accompanying excel windows

Jones Furniture Company produces beds and desks for college students. The production process requires carpentry and varnishing. Each bed requires 6 hours of carpentry and 4 hour of varnishing.

  Question regarding the troubleshooting tables

Imagine that an associate of yours just designed a table with captions outside the table's borders. The font on the Website is black, and the text inside the table is red. He is frustrated because the captions he placed outside of the table are no..

  The design pattern capability is built into the ide

Review the Design Patterns you have learned this module (CRC Cards and Sun Blue Print Designs.) Use the Internet to find at least two other design patterns. What are the advantages and disadvantages of each? What happens when the design patter..

  Define a class called fraction

Define a class called Fraction

  Design the telecommunications network to support

You, as a telecommunications specialist, have been asked to design the telecommunications network to support this new multi-location practice.

  Search and seizure of computers

search and seizure of computers

  Eliminate the problem of unutilized empty slots

Write an algorithm that implements the shift right operation as used in linear queues to eliminate the problem of unutilized empty slots created after deletions.

  What influence do differences have on fundamental equation

As the number of runs of the executable programs grows ("goes to infinity"), prove that the difference in compilation time on the two platforms becomes irrelevant for the total time for the program.

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