Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part 1 Suppose you find a magic $1.00 coin. Its magic power is as follows: as each day passes, you get an additional dollar plus

image text in transcribed

image text in transcribed

image text in transcribed

Part 1 Suppose you find a magic $1.00 coin. Its magic power is as follows: as each day passes, you get an additional dollar plus half of what you already had it appears by the window somehow). Write a method called getRich Quick (no input is necessary for this method) that prints the first n days while your total is less than $1,000,000 dollars. In other words, how many days does it take for you to earn $1,000,000? Your program should calculate these numbers and print the following output: Day 1: $1 Day 2: $1 + ($1 + .50) = $2.50 Day 3: $2.50 + ($1 + 1.25) $4.75 Day N: $X + ($1 + Y) >= $1000000 Part 2 Write a method called eTaylor that takes as input (i.e. argument) a double x and returns the value of e*. This method should NOT use any Math library functions, so you will need to use Taylor Series for ea (loop until terms become close to 0, say 10e-16): e* = 1+&+ + -+... + Hint: Write a helper method for finding the nth power of a number x, divided by n! = n.(n-1).(n 2)....2.1 that is, your helper method should accept an x and output ** Your method eTaylor will return the value of En=0 2" Part 3 Hint: User will enter certain number of random words, you need to read the input as string and evaluate based on the following instructions Write a void method called palindrome Check that takes NO argument. The method should have functionality to check whether or not the word is a palindrome and print to the screen all of the palindromes, one per line. Also, the last line of the output should have the message: There are x palindromes out of y words provided by user" (where x is the number of palindrome words detected, and y is the total number of words entered by user). Hint: for this lab exercise you will need the following methods on String objects: length() gives the length of a string (that is, the number of characters it contains) and charAt(i) - gives the character at position i. For example: int sizeofString = "bob".length) // should be 3 char firstChar "bob".charAt(0) //should be 'b' Part 4 In main, write a menu that allows a user of your program to select and run the programs you wrote in the methods above. The user should be able to play with your methods a many times as they want and only exit the program if they want to exit. For example: Welcome to Lab5! Enter 1 to check how long it takes to get rich on a magic dollar coin. Enter 2 to calculate enx for any real x. Enter 3 to enter palindrome words. Enter 4 to re-print the menu. Enter to exit. What is your choice? 2 Enter an x: 1 el = 2.7182818284590452 What is your choice? 0 Thanks for participating! Goodbye. Note that the method from part 2 did not have you asking for keyboard input. Do NOT go back and modify your method from part, instead handle the request for keyboard input (to get the x or all the words) in main after the user has made his/her choice (i.e. item 2 or 3 in the menu). Part 5 Debugging Debugging your code is a valuable time-saving and problem-solving technique, and is easy to do in both Blue Jand Eclipse. Learn how to set a breakpoint (usually in the "gutter" of the code window, a column to the left) in your software and how to execute your code in "debug mode" so that your software pauses execution at each breakpoint. Using this technique, one can pause execution and inspect the values of variables. Debug any of the previous code you have written in this lab, and determine intermediate values of loop variables as they execute. Part 1 Suppose you find a magic $1.00 coin. Its magic power is as follows: as each day passes, you get an additional dollar plus half of what you already had it appears by the window somehow). Write a method called getRich Quick (no input is necessary for this method) that prints the first n days while your total is less than $1,000,000 dollars. In other words, how many days does it take for you to earn $1,000,000? Your program should calculate these numbers and print the following output: Day 1: $1 Day 2: $1 + ($1 + .50) = $2.50 Day 3: $2.50 + ($1 + 1.25) $4.75 Day N: $X + ($1 + Y) >= $1000000 Part 2 Write a method called eTaylor that takes as input (i.e. argument) a double x and returns the value of e*. This method should NOT use any Math library functions, so you will need to use Taylor Series for ea (loop until terms become close to 0, say 10e-16): e* = 1+&+ + -+... + Hint: Write a helper method for finding the nth power of a number x, divided by n! = n.(n-1).(n 2)....2.1 that is, your helper method should accept an x and output ** Your method eTaylor will return the value of En=0 2" Part 3 Hint: User will enter certain number of random words, you need to read the input as string and evaluate based on the following instructions Write a void method called palindrome Check that takes NO argument. The method should have functionality to check whether or not the word is a palindrome and print to the screen all of the palindromes, one per line. Also, the last line of the output should have the message: There are x palindromes out of y words provided by user" (where x is the number of palindrome words detected, and y is the total number of words entered by user). Hint: for this lab exercise you will need the following methods on String objects: length() gives the length of a string (that is, the number of characters it contains) and charAt(i) - gives the character at position i. For example: int sizeofString = "bob".length) // should be 3 char firstChar "bob".charAt(0) //should be 'b' Part 4 In main, write a menu that allows a user of your program to select and run the programs you wrote in the methods above. The user should be able to play with your methods a many times as they want and only exit the program if they want to exit. For example: Welcome to Lab5! Enter 1 to check how long it takes to get rich on a magic dollar coin. Enter 2 to calculate enx for any real x. Enter 3 to enter palindrome words. Enter 4 to re-print the menu. Enter to exit. What is your choice? 2 Enter an x: 1 el = 2.7182818284590452 What is your choice? 0 Thanks for participating! Goodbye. Note that the method from part 2 did not have you asking for keyboard input. Do NOT go back and modify your method from part, instead handle the request for keyboard input (to get the x or all the words) in main after the user has made his/her choice (i.e. item 2 or 3 in the menu). Part 5 Debugging Debugging your code is a valuable time-saving and problem-solving technique, and is easy to do in both Blue Jand Eclipse. Learn how to set a breakpoint (usually in the "gutter" of the code window, a column to the left) in your software and how to execute your code in "debug mode" so that your software pauses execution at each breakpoint. Using this technique, one can pause execution and inspect the values of variables. Debug any of the previous code you have written in this lab, and determine intermediate values of loop variables as they execute

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

Database And Expert Systems Applications Dexa 2021 Workshops Biokdd Iwcfs Mlkgraphs Al Cares Protime Alsys 2021 Virtual Event September 27 30 2021 Proceedings

Authors: Gabriele Kotsis ,A Min Tjoa ,Ismail Khalil ,Bernhard Moser ,Atif Mashkoor ,Johannes Sametinger ,Anna Fensel ,Jorge Martinez-Gil ,Lukas Fischer

1st Edition

3030871002, 978-3030871000

More Books

Students also viewed these Databases questions