cover picture cover picture


Homework 5

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 3, 2016

In your textbook, this homework problem is in section 4.12 Homework 5-1.

Write a Java program that uses an int variable num which starts at 1.

Your program will have a loop that will continue as long as num is less than or equal to 30. The loop will do the following

  1. If num is odd, you should output: num is an odd number
  2. If num is even, you should output: num is an even number
  3. If num is divisible by 3, you should output: num is divisible by 3
  4. If num is divisible by 5, you should output: num is divisible by 5
  5. If num is divisible by 7, you should output: num is divisible by 7
  6. If num is divisible by 9, you should output: num is divisible by 9
  7. Increment num

Please note that your class should be named FirstLoop.

In your textbook, this homework problem is in section 4.13 Homework 5-2.

Write a program to read a list of exam grades given as int's in the range of 0 to 100. Your program will display the total number of grades and the number of grades in each letter-grade category as follows:

A
93 <= grade <= 100
A-
90 <= grade < 93
B+
87 <= grade < 90
B
83 <= grade < 87
B-
80 <= grade < 83
C+
77 <= grade < 80
C
73 <= grade < 77
C-
70 <= grade < 73
D
60 <= grade < 70
F
0 <= grade < 60

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.)

Each time you prompt the user to enter a grade you will print:

    Enter a grade:
  

For example, if the input is:

    98 95 87 86 83 92 85 78 74 72 81 71 69 63 50 43 -1
  

The output would be:

    Total number of grades = 16
    Number of A's  = 2
    Number of A-'s = 1
    Number of B+'s = 1
    Number of B's  = 3
    Number of B-'s = 1
    Number of C+'s = 1
    Number of C's  = 1
    Number of C-'s = 2
    Number of D's  = 2
    Number of F's  = 2
  

Please note that your class should be named Grades.