Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a program that allows the user to repeat all of the subparts of the program without restarting the program. You can accomplish this by

Create a program that allows the user to repeat all of the subparts of the program without restarting the program. You can accomplish this by wrapping your working code inside of a do-while loop. You must also validate the user input and ensure that the user does not enter an invalid response.

First subsection:

  • Your program will ask the user for a four digit integer. It will then find the largest digit value in that number and determine the smallest base that will represent that number. This can be done by bringing it in a String first and using charAt(), substring(), or bringing it in as an integer and using divide and modulus, and then use IF-THEN-ELSE statements to check the relative size of each digit. Using that base indicator return the decimal value of the inputted number. (Note: You may assume that the user will enter in the correct input.) Some things to consider about numbers and bases. The largest single digit that can be represented in a base is base 1. So the largest single digit that could be represented in base 2 is 1. This is true as base 2 only contains the digits 1 and 0. The largest single digit that can be represented in base 5 is 4. This is true as base 5 only contains the digits 0, 1, 2, 3, and 4. Our numbering system uses positional valuing when representing a number. So in base 10 the number 1234 has a value of 1 times a thousand plus 2 times a hundred plus 3 times ten plus 4 or one thousand two hundred thirty four. Another way of saying that is the value of a number is the individual value of each digit times that digits positional value summed across all of the numbers digits. So 1234 is 1 times (10 to the 3rd power) plus 2 time (10 to the 2nd power) plus 3 time (10 to the 1st power) plus 4 times (10 to the 0th power). This same system holds for all of the base systems. 1234 in base 5 would be 1 times (5 to the 3rd power) plus 2 times (5 to the 2nd power) plus 3 times (5 to the 1st power) times 4 times (5 to the 0th power) or 194 base 10. The Math.pow(base,power) method returns the value of base raised to the power or base times itself power times.
  • Allow the user to continue entering in new numbers until they enter a 0.

Second subsection:

  • Rewrite the temperature code to allow the user to enter in either a Fahrenheit or a Celsius entry. Also allow the user to enter either a floating point number or an integer. Use the formats XXXXX F, XXXXX f, XXXXX C, and XXXXX c. Where XXXXX is the number entered and the F/f and C/c indicate the input temperature scale. The program would then convert to the opposite scale. If the temperature is below absolute zero ask the user for a different input temperature and scale. When you write your program you may assume the user will input their data in the correct format. In this problem the user will type in their temperature and scale, on a single line separated by a space. Use the Scanner to retrieve first the floating point number then the single character string. If I were to enter 32.0 F the program would return "32.00 Fahrenheit is equal to 0.00 Celsius" (Note1: The output numbers must not exceed 2 decimal places) (Note1: Do not display values that are less than absolute zero) If I were to enter 32 C the program would return "32.00 Celsius is equal to 89.60 Fahrenheit" If I were to enter -300 c the program would not display a result but ask the user to enter a different temperature and scale.

Third subsection:

  • Write a section in your program that will identify a target String within another String. Prompt the user for a String. Then prompt the user for a target String. Your program should find each occurrence of that target string in the other String. If the target string is not contained in the other string indicate that to the user. For each occurrence of the target string contained in the other String, display the starting index of the target string, the ending index of the target string, the ASCII character preceding the target string, the ASCII character following the target string. You must find strings that differ only in case.
  • Place this code inside a do-while loop and allow the user to repeat it as many times as they would like.

Example: Please enter a four digit integer: 3745 The smallest base that can represent your number is base 8. Your number in base 10 is: 2021 Please enter a four digit integer: 1234 The smallest base that can represent your number is base 5. Your number in base 10 is: 194 Please enter a four digit integer: 0 That is all for now.

Please enter your temperature, Real number, followed by a space and the scale c or C for Celsius and f or F for Fahrenheit. -300 c That temperature value is invalid. It is below absolute zero. Please enter your temperature, Real number, followed by a space and the scale c or C for Celsius and f or F for Fahrenheit. 33.0 f 33.0 Fahrenheit is equal to 0.56 Celsius

Please enter a test string. Dog mimic concatenation is a small category Please enter a target string dog m The target string "dog " is found in the test string: at index 0, ending at index 4, with no character preceding, and the character 'i' following. Would you like to enter another test and target string pair? Please enter "y" for yes and "n" for no yes Please enter "y" for yes and "n" for no y Please enter a test string Concatenate the cat! The target string "cat" is found in the test string: at index 3 with 'n' preceding and 'e' following at index 16, with ' ' preceding and '!' following

Would you like to enter another test and target string pair? Please enter "y" for yes and "n" for no n Would you like to run the program again? Please enter "y" for yes and "n" for no y

Please enter a four digit integer: 1234 The smallest base that can represent your number is base 5. Your number in base 10 is: 194 Please enter a four digit integer: 0 That is all for now.

Please enter your temperature, Real number, followed by a space and the scale c or C for Celsius and f or F for Fahrenheit. 33.0 C 33.0 Celsius is equal to 91.4 Fahrenheit

Please enter a test string. Dog mimic concatenation is a small category Please enter a target string dog The target string "dog " is found in the test string: at index 0, ending at index 2, with no character preceding, and the character ' ' following. Would you like to enter another test and target string pair? Please enter "y" for yes and "n" for no n Would you like to run the program again? Please enter "y" for yes and "n" for no N Good-bye!

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

Databases DeMYSTiFieD

Authors: Andy Oppel

2nd Edition

0071747990, 978-0071747998

More Books

Students also viewed these Databases questions