Your instructor will assign one or more of the following problems. Submit all appropriate files for grading, including code files, screen captures, supplemental files (e.g., image files), and text files.

  1. Write a Java program that prompts the user to enter the number of students and each student's name and score, and finally displays the highest score and the second highest score with their names. You may assume that the user will always enter a number of students greater than or equal to 2. An example run follows:
    Please enter the number of students: 5
    Please enter name and score number 1: John 37
    Please enter name and score number 2: Sarah 39
    Please enter name and score number 3: David 23
    Please enter name and score number 4: Betsy 34
    Please enter name and score number 5: Elizabeth 35
    The highest score was 39 by Sarah.
    The second highest score was 37 by John.
    NOTE: If two or more scores tie for the highest score, you may print any two correct names that achieved the highest score.
  2. Write a Java program that computes and displays the squares of consecutive integers until the difference between a square and the preceding one is greater than a user specified value. An example run follows:
    Please enter the desired difference between squares: 10
    1 4 9 16 25 36 
    
    Note: No more than 10 squares should be printed on any line.
  3. Write a console driver program that asks the user how many test scores they have, and then reads that many test scores, averages them, and displays the average and a pass/fail grade appropriate for that average (passing is 60% or higher, failing is below 60%). The pass/fail determination should be done in a separate method from the driver.

  4. Proceed as in the previous exercise, but instead of displaying a pass/fail grade, the program should compute a "normal" letter grade (90-100 = A, 80-89 = B, 70-79 = C, 60-69 = D, <60 = F).

  5. Write a "password protection" method that you can use to guard your programs. When called, this method should ask the user for a password. It should allow the user N tries at entering the correct password, where N is a value received from its caller. If the user enters the correct password, the method returns control to its caller, where execution proceeds as normal. If the user fails to enter the correct password after N tries, then the method should use System.exit(1) to terminate the program. Write a driver (i.e. main method) to test it out.

  6. Write two methods:

    Your methods can assume that the value of n is positive and not too large. Include a main method that allows the user to specify the number of times she wants to run your computations and asks the user to specify which computation to execute on each round.

  7. Write a Java program that prompts the user to enter a positive integer (greater than zero), and then displays the integer in reverse order. An example run is shown below:
    Please enter a positive integer: 91827
    91827 reversed is 72819
    

    Name your program Reverse.java. Consider using the % operator to extract digits, and the / operator to remove the extracted digit. For instance, to extract 4 from 234, use 234 % 10, and then use 234 / 10 to remove the 4.

  8. Write a Java program that reads an unspecified number of integers, determines how many positive and negative values have been read, and computes the total and average of the input values. Your program ends with the input 0 and should not use the 0 in the count or average computations. Display the average as a floating-point number. Here is an example run:
    Enter as many int values as you'd like (the program exits if the input is 0):
     1 2 -1 3 0
    The number of positives is 3
    The number of negatives is 1
    The total is 4
    The average is 1.25
    
    Name your program SimpleStats.java. You may want to begin by computing the total of the numbers entered, and then add each additional statistic one at a time.

Checking In

Submit all appropriate files for grading, including code files, screen captures, supplemental files (e.g., image files), and text files. We will grade this exercise according to the following criteria:

If you work in teams for this homework assignment, be sure to submit all team members’ names in the code documentation.