Program L6a Solution

$35.00 $29.00

Problem#1 Get Chapter6_FillInTheCode.java and load it to IDEA. Code the answers in java in the provided file. Problem#2 Write a program that prompts the user for a value greater than 10.0 as an input and finds the square root of the number and the square root of the result, and continues to find the square…

5/5 – (2 votes)

You’ll get a: zip file solution

 

Categorys:
Tags:

Description

5/5 – (2 votes)

Problem#1

Get Chapter6_FillInTheCode.java and load it to IDEA. Code the answers in java in the provided file.

Problem#2

Write a program that prompts the user for a value greater than 10.0 as an input and finds the square root of the number and the square root of the result, and continues to find the square root of the result until we reach a result that is smaller than 1.01

The program must:

produce the output as shown in the sample run below including the line number

must use do-while loop for the input and a while loop for the square root calculations.

Follow this algorithm:

  1. with do-while loop keep prompting the user for input for as long as the given number is NOT greater than 10.0 (see example 6.13)

  2. calculate the first square root of the given number (prime read)

  1. with a while loop (see example 6.1):

    1. increment the square roots counter

    1. print the running count followed by the square root value

    1. calculate the next square root (for example squareRoot = Math.sqrt(squareRoot);)

  1. print the final results

The following is a sample run of the finished program:

> java SquareRoots

Enter a number greater than 10.0 > 9 Enter a number greater than 10.0 > 10.5

1. Calculated square root is –> 3.24037034920393

https://cilearn.csuci.edu/courses/5532/assignments/61969 1/2

12/14/2020 L6a

  1. Calculated square root is –> 1.8001028718392542

  1. Calculated square root is –> 1.3416791240230483

  1. Calculated square root is –> 1.1583087343290857

  1. Calculated square root is –> 1.0762475246564267

  1. Calculated square root is –> 1.0374235030383814

  1. Calculated square root is –> 1.0185398877993839

For the input 10.5 the number of square roots greater or equal than 1.01 is 7

Problem#3

Write a program that reads from the attached text file Logic.txt one word at a time. The program counts how many words start with the letters “is” (use startsWith method from String class to check for that), and prints each word with all the vowels replaced with ~ character (use replaceAll method from String class to replace all the vowels with the given replacement String). At the end, the program outputs the count of all the words that start with “is”. See the expected output below:

“C~ntr~r~w~s~,” c~nt~n~~d Tw~~dl~d~~, “~f ~t w~s s~, ~t m~ght b~; ~nd ~f ~t w~r~ s~, ~t w~~ld b~; b~t ~s ~t ~sn’t, ~t ~~nt’t. Th~t ~s l~g~c.”

2 words start with “is”.

Note: Example_6.2.java on page 290 shows you how to read from a file

Problem#4

Write a program that takes website names as keyboard input until the user types stop. The program should count how many website names are commercial websites names (i.e., end with .com)

Use appropriate method from the String class that detects if the given word ends with the given sequence of characters.

Use a while loop.

https://cilearn.csuci.edu/courses/5532/assignments/61969 2/2

Program L6a Solution
$35.00 $29.00