Starting from:

$29.99

Scanner objects, Strings, file processing

COMPUTER SCIENCE 12B 
PROGRAMMING IN JAVA
PROGRAMMING ASSIGNMENT 2
Program Description:
This assignment will test your understanding of the use of the Scanner objects, Strings, file
processing, Random objects, Arrays, and everything covered so far.
Modularity in your code is very important, YOU MUST USE STATIC METHODS.
Write five programs to solve the following problems. Write each program in a different file with
extension .java Named your programs/files Problem1.java, Problem2.java, etc.
Problem 1: (For this problem you are not allowed to use arrays)
Write a reverse Hangman game in which the user thinks of a word and the computer tries to guess
the letters in that word. Your program must output what the computer guessed on each turn, and
show the partially completed word. It also must use pseudorandom functions to make guesses. That
is, it should not simply try all the letters in order, nor should it use the user’s input to its advantage.
A sample run of your program might be as follows:
NOTE:
1. You are not allowed to use String methods that have not been discussed in class.
2. Because this program uses pseudorandom numbers, you won’t be able to recreate this exact
log.
>>Please enter a word for me to guess(letters only):
>>hello
>>My guess: n current status: _____
>>My guess: l current status: __ll_
>>My guess: x current status: __ll_
>>My guess: o current status: __llo

Problem 2: Write a program that reads a file containing data about the changing popularity of
various baby names over time and display the data about a particular name. Each line of the file
stores a name followed by integers representing the name’s popularity in each decade: 1900, 1910,
1920, and so on. The ranking ranges from 1 (most popular) to 1000 (least popular), or 0 for a name
that was less popular than the 1000th name. The following lines are a sample of the file format:
Sally 0 0 0 0 0 0 0 0 0 0 886
Sam 58 69 99 131 168 236 278 380 467 408 466
Your program should prompt the user for a name and search the file for that name:
This program allows you to search through the
data from the Social Security Administration
to see how popular a particular name has been
since 1900.
Name? Sam
If the name is found, the program should display data about the name on the screen:
Statistics on name "Sam"
1900: 58
1910: 69
1920: 99

NOTE: For this problem, use the provided file names.txt
Problem 3: Write a method called isUnique that accepts an array of integers as a parameter and
returns a boolean value indicating whether or not the values in the array are unique (true for
yes, false for no). The values in the list are considered unique if there is no pair of values that
are equal. For example, if passed an array containing {3, 8, 12, 2, 9, 17, 43, -8, 46}, your method
should return true, but if passed {4, 7, 3, 9, 12, -47, 3, 73}, your method should return false
because the value 3 appear twice.
You should also write the main method, which interacts with the user, calls the static method
isUnique, and prints the result.
Problem 4: Write a method called longestSortedSequence that accepts an array of integers
as a parameter and returns the length of the longest sorted (nondecreasing) sequence of integers in
the array. For example, in the array {3, 8, 10, 1, 9, 14, -3, 0, 14, 207, 56, 98, 12}, the longest sorted
sequence in the array has four values in it (-3, 0, 14, 207), so you method would return 4 if passed
this array. Your method should return 0 if passed an empty array.
You should also write the main method, which interacts with the user, calls the static method
longestSortedSequence, and prints the result.
Problem 5: Write a method called priceIsRight that mimics the guessing rules from the game
show The Price is Right. The method accepts as parameters an array of integers representing the
contestants’ bids and an integer representing a correct price. The method returns the element in the
bids array that is closets in value to the correct price without being larger than that price. For
example, is an array called bids stores the value {200, 300, 250, 1, 950, 40} the call of
priceIsRight(bids, 280) should return 250, since 250 is the bid closets to 280 without
going over 280. If all bids are larger than the correct price, your method should return -1.
You should also write the main method, which interacts with the user, calls the static method
priceIsRight, and prints the result.
Guidelines:
For this assignment you should limit yourself to the Java features covered in class so far (lecture
11). Although we will cover other topics while you are working on this assignment, do not use any
of those features.
Grading:
You will be graded on
o External Correctness: The output of your program should match exactly what is expected.
Programs that do not compile will not receive points for external correctness.
o Internal Correctness: Your source code should follow the stylistic guidelines shown in
class. Also, remember to include the comment header at the beginning of your program.
o Comments and Style
Submission:
Create a folder containing your Java source code (programs). Compress (zip) the folder and
upload it to Latte by the day it is due. For late policy check the syllabus.

More products