Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Given what is known about the parity of two numbers, a multiplier and a multiplicand, compute and report what is known about the parity

1. Given what is known about the parity of two numbers, a multiplier and a multiplicand, compute and report what is known about the parity of their product.

For example, if the parity of a multiplier is ODD and the parity of a multiplicand is ODD, your program would report the parity of the product is ODD. Similarly, if the parity of the multiplier is UNKNOWN and the parity of the multiplicand is EVEN, the program should report that the product has EVEN parity.

a. Write a solution to this problem in Java.

b. Add a comment to the beginning of the code in Parity.java. Include your name and a brief natural-language description of the problem your code solves.

c. Modify the code in Parity.java to prompt the user to enter two parity descriptions from standard input. Present these prompts:

"Enter parity of multiplier: "

"Enter parity of multiplicand: "

Be sure to match these prompts exactly (including the trailing spaces), or your tests may fail.

d. Write code to solve the stated problem.

e. Use exactly one if-else statement to implement your solution.

f. After computing the parity of the product, your program should output the parity using the format in the following example (be sure to use the same spacing and punctuation):

"The parity of the product of an EVEN number and an EVEN number is EVEN."

g. Structure your code in a modular way (you should have at least three methods in addition to the main method to solve this problem), and you should not mix computation with I/O.

h. Be sure to use appropriate variable names, locate the main method at the bottom of the file, and format your code using the Eclipse formatter.

k. Add exception-handling code.

Manually test your program on invalid inputs and note what type of exceptions are thrown.

Add exception-handling code (try and catch blocks) to print the following message if the user gives an invalid input and to return from main (for this program, just return; do not call System.exit):

"Parity must be one of EVEN, ODD, or UNKNOWN."

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data And Databases

Authors: Jeff Mapua

1st Edition

1978502257, 978-1978502253

More Books

Students also viewed these Databases questions

Question

If you were the reader, how would the message make you feel?

Answered: 1 week ago