Question
java For this project, you will create a program that asks the user to enter a positive integer value less than 20. If the user
java
For this project, you will create a program that asks the user to enter a positive integer value less than 20.
If the user enters a number greater than 20, the user should get an error.
If the user enters a number equal to or less than 20, display the double of each value beginning with 1 up to the selected number (multiply each number by 2), then provide the total of all doubles.
For example, if the user entered the number 5, the following should display:
Double up 1 = 2
Double up 2 = 4
Double up 3 = 6
Double up 4 = 8
Double up 5 = 10
Total = 30
You will be using mutator and accessor method. A mutator method is simply a fancy name for a method that modifies private data. An accessor method is a method which has the sole purpose of providing access to private data.
Minimum Requirements:
Create a class that has 3 methods.
A mutator method should take the number from the user and store it in a private variable. (5 points)
Another method should perform the calculations, display the double up results and store the total in a private variable. This method must use a loop. (5 points)
An accessor method should display the total. (5 points)
Create a main method that creates an object of your class and calls each of the methods of the class. (5 points)
For this project, you will create a recursive version of the method you created for the above project: Double Up
Requirements:
1. Do not use a loop.
2. Create a recursive method with an int return type that accepts a number that will represent the max number for the double up. This method must be called recursively to display the double up calculation for each value between 1 and that max number, and return the total. The output will be the same as the output for Project 2. For example, if the recursive method is called and sent the max value 5, the output should be as follows:
Double up 1 = 2
Double up 2 = 4
Double up 3 = 6
Double up 4 = 8
Double up 5 = 10
Total = 30
However, if the method is called with a value greater than 20, the method should display a message like "Invalid number" and return -1.
4. The main method should call the method and pass a max value for testing.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started