cover picture cover picture


Homework 7

CMP 167: Programming Methods I
Lehman College, City University of New York
Spring 2016


This Homework Is Due By 11:59 PM on Sunday April 17, 2016

In your textbook, this homework problem is in section 5.12 Homework 7-1.

Write a program to read a list of exam grades given as int's in the range of 0 to 100 into an array. You can assume that the maximum number of grades is 100. Use a negative number as a sentinel value to indicate the end of the input. (The negative value is used only to end the loop, do not use it in your calculations.)

Your program will compute the following:

  1. The average of all the grades.
  2. The number of grades entered.
  3. The number of grades that are greater than or equal to the average.
  4. The number of grades that are less than the average.

Your prompt to the user to enter a grade should be:

    Enter a grade: 
  

Your program must produce the following output:

    Number of grades            = Number of Grades Entered
    Number of grades >= average = Computed Number of Grades >= Average
    Number of grades <  average = Computed Number of Grades <  Average
  

For example, if the input is:

    98 76 45 56 82 75 99 87 35 44 67 32 11 5 0 17 94 56 73 74 75 -1
  

The output will be:

    Enter a grade: 
    Enter a grade: 
    Enter a grade: 
    Enter a grade: 
    Enter a grade: 
    Enter a grade: 
    Enter a grade: 
    Enter a grade: 
    Enter a grade: 
    Enter a grade: 
    Enter a grade: 
    Enter a grade: 
    Enter a grade: 
    Enter a grade: 
    Enter a grade: 
    Enter a grade: 
    Enter a grade: 
    Enter a grade: 
    Enter a grade: 
    Enter a grade: 
    Enter a grade: 
    Enter a grade: 
    Number of grades            = 21
    Number of grades >= average = 11
    Number of grades <  average = 10
  

Please note that your class should be named GradesArray.

In your textbook, this homework problem is in section 5.13 Homework 7-2.

Write a Java program that reads in ten integers and displays distinct numbers (i.e. if a number appears multiple times, it is displayed only once). Hint: Read a number and store it in an array if it is new. If the number is already in the array, discard it. After the input, the array contains the distinct numbers.

  

Your prompt to the user should be:

    Enter a number:
  

Your program must produce the following output:

    Distinct Numbers = List of distinct numbers seperated by comas
  

For example, if the input is:

    15 20 15 20 15 20 15 20 15 20
  

The output will be:

    Enter a number: 
    Enter a number: 
    Enter a number: 
    Enter a number: 
    Enter a number: 
    Enter a number: 
    Enter a number: 
    Enter a number: 
    Enter a number: 
    Enter a number: 
    Distinct Numbers = 15,20,
  

Please note that your class should be named DistinctNumbers.