MIDTERM
CS201, Spring 2004
Please print out a hard copy of all your java programs and turn it in
at
the end of the exam. Do not forget to put your name on the hard copy. Before turn in your programs, try to
compile and run them and make sure they work correctly. If your program
does not even compile, you receive an automatic 10pt deduction for that
problem, no matter how "close" the program seems to be correct.
For the following problems, you may choose to use either System.out.println() or JOptionPane.showMessageDialog() for output.
1. (25pt) Write a program SimpleGrade.java
which asks a user to enter
an integer number between 0 and 10. If the number is less than or
equals to 5, the program outputs the letter F. If the number is greater
than 6, the output of the program is based on the following table:
Number
|
Output
|
6
|
D
|
7
|
C
|
8
|
B
|
9
|
A
|
10
|
A
|
To receive full credit for this problem, you must use a switch statement.
2. (35pt) Write a program TwoNumbers.java
which asks a user to enter two integer numbers, m and n. The program then computes and
prints out the following:
- All even numbers between m
and n, inclusive.
- The sum of all odd numbers between m and n, inclusive.
- All numbers between m
and n which are divisible by
5, inclusive.
For example, if the user enter 5 and 12, the output of your program
should be:
6 8 10 12
32
5 10
You may assume that m is
always less than n.
3. (25pt) The cost of an international call from New York to New Delhi
is calculated as follows: Connection fee, $1.99; $2.00 for the first
three minutes; and $0.45 for each additional minute. Time less than one
minute is always rounded up
to one minute. Write a program PhoneCharge.java which asks
a user to enter the number of minutes a call lasted, and output the
charge for that call. Note that the number of minutes could be a real number such as 4.1 or 5.2.
4. (15pt) Write a program Shift.java
which asks a user to enter an integer number n. The program then outputs the
following pattern:
1 2 3 4 5 ... n-2 n-1 n
2 3 4 5 6 ... n-1 n 1
3 4 5 6 7 ... n 1 2
... ..
n 1 2 3 4 ... n-3 n-2 n-1
For example, if the user enters 6, the output should be:
1 2 3 4 5 6
2 3 4 5 6 1
3 4 5 6 1 2
4 5 6 1 2 3
5 6 1 2 3 4
6 1 2 3 4 5