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.

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

Microsoft SQL Server 2012 Unleashed

Authors: Ray Rankins, Paul Bertucci

1st Edition

0133408507, 9780133408508

More Books

Students also viewed these Databases questions