Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

*** JAVA PLEASE *** *** JAVA PLEASE *** Objectives Learn the basics of recursion. Background In this lab you'll write a calculator which calculates multiplication,

*** JAVA PLEASE ***

image text in transcribedimage text in transcribed

*** JAVA PLEASE ***

Objectives Learn the basics of recursion. Background In this lab you'll write a calculator which calculates multiplication, division and modular division using recursion. Tasks You'll need to write 3 methods, all of which must use recursion: 1) Write recursive_multiply. It should take in 2 integers and return an integer. Another way to say multiply 5*4, is 5+(5*3), or 5+5+(5*2), or 5+5+5+(5*1), or 5+5+5+5+(5*0). You know that any number multiplied by 0 is 0. 2) Write recursive_div. It should take in 2 integers and return an integer. Unlike regular division, div just returns the integer portion of division. It answers the question "how many times does the second number go into the first number. So, 7 div 3 = 2, because 3 goes in 2 times, the leftover is irrelevant to div. If you are asked to divide anything by 0, you should return -1, as that's an error. If you are asked to divide anything by itself, you should return 1. i.e. 7 div 7 = 1 If you are asked to divide a small number by a bigger one, the answer is 0. i.e. 2 div 7 = 0 For all other numbers, you'll keep subtracting the second number from the first number, until the first number is less than the second. You'll count how many times this happens, and return that count. Remember you must use recursion in all 3 of these methods. 3) Write recursive_mod. It should take in 2 integers and return an integer. Mod only cares about the remainder of division. If you are asked to divide anything by 0, it should return -1, as that's an error. If you are asked to divide any smaller number by a larger number, you should return the smaller number. i.e. 2 mod 3 = 2 For all other cases, you'll keep subtracting the second number from the first. For example: 7 mod 3: 7-3 = 4 4-3 = 1 Answer is 1. 4) Finally, write the main method, which prompts the user to either multiply, div, or mod. Then prompt the user for 2 numbers, call the appropriate method, receive a result, and print it out. Continue to ask the user (you may use a loop here) until they choose 0 to quit

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

Step: 3

blur-text-image

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

Excel As Your Database

Authors: Paul Cornell

1st Edition

1590597516, 978-1590597514

More Books

Students also viewed these Databases questions

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago