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

  Write a program using linkedlist and listiterator

Write a program using LinkedList and ListIterator to obtain the following statements:1. Create a linked list named "number" with these elements: "one", "four" and "three".2. Create a List Iterator named "it1" related to "number".

  How do we read a numeric value using joptionpane method

How do we read a numeric value using JOptionPane method

  What the router does with a packet addressed

Suppose a router has built up the routing table shown in Table 4.14. The router can deliver packets directly over interfaces 0 and 1, or it can forward packets to routers R2, R3, or R4. Describe what the router does with a packet addressed to each..

  P needed to raise the column and the equilibrium

The contacting surface between A and D is smooth.

  Evaluating different approaches to deadlock

Another criterion is efficiency; in other words, which requires the least processor overhead. Rank order the approaches from 1 to 6, with 1 being the most efficient, assuming that deadlock is a very rare event. Comment on your ordering. Does your ..

  How big is block size used by the file system to read data

How big is the block size used by the file system to read data? Hint: use reads of varying sizes and plot the time it takes to do such reads. Also, be wary of prefetching effects that often kick in during sequential reads.

  Establish and improve standards of financial accounting

In 1973, the Financial Accounting Standards Board (FASB) was created and their mission is "to establish and improve standards of financial accounting and reporting for the guidance and education of the public, including issuers, auditors, and user..

  Design program that creates object productionworkers

Design an Employee class that has fields for the following pieces of information: Employee Name Employee Number Next, design a class named ProductionWorker that extends the Employee class

  Back to a previous learning experience

Think back to a previous learning experience (a class, a presentation, a training session, etc.) when the instructor or presenter asked for questions.

  The firstround of the des decryption

Compute the bits number 1, 16, 33, and 48 at the output of the firstround of the DES decryption, assuming that the ciphertext block iscomposed of all ones and the external key is composed of all ones

  Discuss security strategy for a multinational company

As a CIO for a multinational company, how do you address security issues in the company? In another words, what will be your information security strategy?

  Analyse the ethical dilemma

Analyse the ethical dilemma using the Australian Computer Society Code of Professional Conduct, The word limit is 800 words ± 10%. Note: Headings, citations, references and any appendices do not count towards your word limit, but quotations do.

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