Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

Bonus 1

Computer programming is the process of designing and building an executable computer


program to accomplish a specific computing result or to perform a specific task. Programming
involves tasks such as: analysis, generating algorithms, profiling algorithms' accuracy and resource
consumption, and the implementation of algorithms in a chosen programming language (commonly
referred to as coding).[1][2] The source code of a program is written in one or more languages that are
intelligible to programmers, rather than machine code, which is directly executed by the central
processing unit. The purpose of programming is to find a sequence of instructions that will automate
the performance of a task (which can be as complex as an operating system) on a computer, often
for solving a given problem. Proficient programming thus often requires expertise in several different
subjects, including knowledge of the application domain, specialized algorithms, and formal logic.

The goal of this lab is to get used with basic Java notions introduced so far and selection control
structures. 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.  Write a program to 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.

You might also like