i have a computer science 201  assignment to be done by tonight homework + extra credit

profileabutid
cmpt_201_homework_3.htm

CMPT 201 Westminster College Homework 3 Due Thursday, September 11 at 11 pm

Before You Begin - Time Estimate

Before you begin this assignment, read through this description and estimate how long it will take you to complete this assignment (designing, programming, commenting, testing, and debugging). Write this estimate down in your README. Then keep track of the time you spend on this assignment. While completing this estimate and measuring your time will be part of your grade, you will not be graded on how long the assignment took or how close your estimate was.

Estimating the time it takes to develop software is very difficult, even for experienced programmers. Comparing your estimates to your real development time should help you improve your estimates.

Questions:

Submit your answers to these questions as a text file named "Questions.txt". You should not need to write more than a few sentences for each answer.

  1. Give a brief explanation of what the following are typically used for in Java. If there is more than one use, give the most common usage.
    • curly braces {}
    • parenthesis ()
    • semicolon ;
  2. Copy and paste the following code into Dr. Java. Then add curly braces to the code to produce the output shown. Use proper indentation techniques (Control-a and tab). Do not make any changes to this code except indenting and inserting braces: {}. When your code produces the below output, copy and paste the if-statements into Questions.txt.
    if (y == 8)
    if (x == 5)
    System.out.println ("@@@@@");
    else
    System.out.println ("#####");
    System.out.println ("$$$$$");
    System.out.println ("&&&&&");
      
      A. Assuming x=5 and y=8, the following output is produced:
      @@@@@
      $$$$$
      &&&&&  

      B. Assuming x=5 and y=8, the following output is produced:

      @@@@@  

      C. Assuming x=5 and y=8, the following output is produced:

      @@@@@
      &&&&&  

      D. Assuming x=5 and y=7, and all three of the last output statements after the else are part of a compound statement:

      #####
      $$$$$
      &&&&&  
    • Write the corresponding boolean expressions checking for the following. You should use syntactically correct java code. The variable name is written in special red text:
        A. age is between 18 to 21 inclusive (including 18 and 21) B. year is divisible by 4 C. speed is not greater than 75 D. grade is between 80 and 90 (not including 80 and 90) E. either temperature is greater than 95 or humidity is greater than 90
      • Explain in your own words, what is an empty String. It is explained in sections 2.2 and 2.3 of your textbook.
  • Explain in your own words, what is the difference between the next and nextLine methods in the Scanner class (Section 2.3).

Program:

Write a program Rephrase.java that will read a line of text as input and then output the line with the first word moved to the end of the line. You should also capitalize the first letter of the new first word (which was the second word).

For example, a sample dialog might be:

Enter a line of text. No punctuation please. Java is the language I have rephrased that line to read: Is the language Java

Another sample dialog:

Enter a line of text (or enter to quit). No punctuation please. Hello world I have rephrased that line to read: World Hello

You may assume that there is no space before the first word and that the end of the first word is indicated by a blank (not by a comma or other punctuation).

Don't forget to write this program in steps, the way we wrote the Conversation program in steps during lab. You may want to write down your steps before beginning.

Include your Rephrase.java file in the zip file uploaded to Canvas.

Also submit a README file, which should be a text file describing which java files you handed in for which programs, what the goals of the program were, whether you achieved them, and what outside resources you used (if any).

Extra Credit

For extra credit, modify your Rephrase program so it repeats until the user enters an empty line. So in other words, the following would be the dialog from running your program ONCE:

Enter a line of text (or enter to quit). No punctuation please. Java is the language I have rephrased that line to read: Is the language Java

Another sample dialog:

Enter a line of text (or enter to quit). No punctuation please. Hello world I have rephrased that line to read: World Hello Enter a line of text (or enter to quit). No punctuation please. Goodbye!

You should begin by making a backup of the working no-loop version of your program. Then add a loop:

  1. Add an if-statement so the program runs 0 or 1 time. This will involve:
    • Determining the condition. Most people find it easier to think about the STOPPING condition, and then reversing that for the boolean expression for the if statement.
    • Determining what code goes inside the if-statement's {}.
  2. Before moving to the next step, test your changes by running your code at least twice: once where you do not execute the if-statement, and once where you do.
  3. Convert the if to while, and double check that it still works correctly if you run the code without entering the while loop. (The code will fail when you try to run through the while loop, probably with an infinite loop.)
  4. Examine the code that appears before the while loop. Some of this code initialized values that were needed inside the while-loop. Repeat those initialization lines at end of while loop, so they are run before the next iteration in the while loop.
  5. Test your code, running through the while loop 0, 1, and 2 times.
Remember to mention if you did the extra credit in your README.