CSCI.UA0101: Homework 1

Section 001 (Honors): 50 points Section 002: 40 points + 10 bonus Updates: None Instructions: Answer the questions stated in the following exercises by submitting plain-text or Java source code (.txt and .java extensions respectively) as stated in the exercises through NYU Classes. No word (.doc/.docx/etc.) or rich-text (.rtf) files please (in your text editor do "Save file as plain-text"). Java programs should be just the Java source code (not your .class files or Eclipse workspaces) unless otherwise stated. In all files submitted include a documentation header using comments which include: /** * [Description of the program] * @author: [Your Name] */ Points will be deducted for bad coding style (up to 25% of your grade), so: - use good variable/function names (self-documenting code) - avoid hardcoding values - provide comments for complex code blocks For more details regarding good coding style guidelines see the grading criteria.

Exercise 1 - LiveLab Exercise02_21 (10 points)

Complete programming Exercise02_21 from the text. You can check your code correctness on LiveLab before submitting your code on NYU Classes. Remember that LiveLab only checks for technical accuracy. In addition to correctness, coding style is always in consideration when grading. Save and submit your program (just the source code) as Exercise02_21.java.

Exercise 2 - LiveLab Exercise03_08 (10 points)

Complete programming Exercise03_08 from the text. You can check your code correctness on LiveLab before submitting your code on NYU Classes. Save and submit your program (just the source code) as Exercise03_08.java.

Exercise 3 - LiveLab Exercise03_35 (10 points)

Complete programming Exercise03_35 from the text. You can check your code correctness on LiveLab before submitting your code on NYU Classes. Save and submit your program (just the source code) as Exercise03_35.java.

Exercise 4 - Best Guess (10 points)

Write a program that generates a secret random number between 0 and 100. Then allows two separate players to guess what the number is. After the guesses have been made, the program should output two lines of output. The first line should indicate what the secret number was. The second should state which player won or if the game was a tie. Sample Input/Output: I am thinking of a number from 0 to 100. Player1, make a guess: 13 Player2, make a guess: 37 The winner is: Player2 The number was: 51 Eat it player1! Save and submit your program (just the source code) as BestGuess.java.

Exercise 5 - High Low (10 points - Required for Honors students, Bonus for standard students)

Write a program similar to Exercise 4 that generates a secret random number between 0 and 100. The program should then allow the user to try and guess that number. With each guess, the program should tell the user if thatsecret number is less than, equal to, or greater than their guess. If the user guesses the number, the program should tell the user how many guesses it took and then terminate. If after the user has made 5 guesses incorrectly, the program should state that they exhausted their allotted number of guesses, let the user know what the number was, and exit. Example Input/Output: I am thinking of a number from 0 to 100. Make a guess: 50 The number is higher. Make a guess: 75 The number is lower. Make a guess: 60 The number is lower. Make a guess: 55 The number is lower. Make a guess: 53 You guessed 5 times incorrectly. The number was 52. Save and submit your program (just the source code) as HighLow.java.