COSC 236

Lab 5

The goal of this lab is to get used with basic Java notions introduced so far and selection control structures (discussed in Lecture #5). Take a look at the examples and the sample programs in the lecture notes and try to apply the same concepts and style when writing your own programs. You will write 3 programs, given below.


1.  Use if statements to write a Java program that inputs a single letter and prints out the corresponding digit on the telephone. The letters and digits on a telephone are grouped this way:

2 = ABC    3 = DEF   4 = GHI    5 = JKL
6 = MNO   7 = PRS   8 = TUV    9 = WXY

No digit corresponds to either Q or Z. For these 2 letters your program should print a message indicating that they are not used on a telephone.

The program may operate like this (sample output):

Enter a single letter and you will get the corresponding digit on the telephone: R
The digit 7 corresponds to the letter R on the telephone

Another sample:

Enter a single letter and you will get the corresponding digit on the telephone: Z
There is no digit on the telephone that corresponds to Z

NOTE: Your program should accept only uppercase letters (error message for special characters or lowercase letters)


2.  Rewrite the program - this time use a switch statement.


3.  In the previous lab you wrote a Java program that computes a student's total score. Modify that program so that you can assign a letter grade according to the following scheme:

A: total score >= 90
B: 80 <= total score < 90
C: 70 <= total score < 80
D: 60 <= total score < 70
F: total score < 60

Output - the student's total score (float, 2 decimals) and letter grade
Testing - test your program with the following input data:

test1 = 95; test2 = 80; final = 90; assignments = 80

The expected output is:  score = 86.25 and letter grade = B.


Notes:
A. The lab will NOT be graded, do NOT hand anything in to the instructor.
B. The lab should be completed by the start of the next scheduled lab class.
Save the .java files on your disk and e-mail them (attachments) to Vishal Patel at vpatel12@students.towson.edu

Very important: Make sure that you have COSC 236.001, your name, and Lab#5 in the Subject box of your e-mail.
C. In case you have any problems, contact the TA or the instructor for assistance.