Design and development of significantly sized software using top-down design and bottom-up implementation. Dynamically allocated data, object-oriented programming, architecture of memory, basics of language translation, and basics of algorithm analysis. Development of simple graphical user interfaces. Prerequisite: CS 110 (grade of C or better).

Lab 3 - Introduction to Array Operations - (50 points)



Due date: 2/26/2015 at 11:59pm

Objectives



  • Learn how to use of Arrays in Java
  • Familiarize yourself with the Math class in Java
Create a directory called lab3.

Part 1 - Introduction to Arrays (30 points)



For this lab, you will create a class called ArrayOperations. This class will start by initializing an integer array of size 1000 with random integers between 0 and 100. You will then show the user a menu that will contain the following array operations (with a choice to exit):

  1. Find and print the maximum number in the array
  2. Find and print the minimum number in the array
  3. Calculate and print the sum of all the numbers in the array
  4. Calculate and print the average of all the numbers in the array
  5. Reverse the array
  6. Count the occurences for each number in the array. For example, how many times do you find a number (say 63) in the array. Hint: You will need another array of 100 integers that will store how many times you have seen every number between 0-100.
For each of the above operations, your class must contain separate functions that are invoked from the main(). Please do not write all your code in the main function.

Part 2 - Random number guessing game (15 points)



For this part of the lab, you will create a game where the computer randomly picks a number between 0 and 20. The user is asked to specify a guess.

  • If the guess less than the computer-picked number, then the user is informed that their guess is lower
  • If the guess greater than the computer-picked number, then the user is informed that their guess is higher
  • If the guess equal to the computer-picked number, then the user is informed that they have correctly guessed the number. You should also let the user know how many guesses were required to accurately guess the number.
  • The user can have five guesses at most, after which the computer-picked number is displayed to the user. If the user guesses the number correctly at any point, then you must stop asking the user to make more guesses.
  • At this point, your program must ask the user if s/he would like to play again (y/n).
  • If the user presses a 'y', then the program must generate a new random number and ask the user to start guessing again.
  • If the user presses a 'n', then the program should exit.
Here are some implementation details, we would like you to follow for the lab

  • For this program, create a new Java class called GuessingGame.
  • Use the Scanner class to take input from the user
  • Consider using the do-while construct for the "do you want to play again" part of the lab
  • You only need to implement the program to work with integers

Commenting and formatting your code (5 points)



We will be deducting points for lack of comments and overall quality of your code. Make sure your README file is well written and contains enough information regarding any colleagues you worked with or resources you used for the assignment.

Submitting the assignment



  • Create a directory called (lab3), copy all the java files and the README into the directory and submit your assignment.
  • You can resubmit the assignment as many times as you want. It will upload a new copy of the files to the SVN repository. We will only grade the one that is closest to 11:59pm on the due date.