Lab 2
(week of Jan 19-23)
The purpose of this lab is to review control statements in Java and write
Java programs primarily using control statements
There are two parts of Lab 2.
Part 1: Debug Two Java Programs.
1. Program 1. Temperature.
java
2. Program 2. CompTalk.java
Remember to comment the code.
Part 2: Programming Questions.
1. Suppose a student was taking 5 different courses last
semester. Write a program that
(a) asks the student to input his/her name, student
ID, marks for these 5 courses,
(b) calculate the average,
(c) determine the letter grade of each course.
(d) record the number of courses whose final letter grade
is A+, A, A-, .... , F+, F, F-.
(e) Output the following information in a nice format:
student name, student ID, listing of marks, the average, letter grade for
each course, and the
number of courses in each
letter grade category.
2. A right triangle can have sides whose lengths
are all integers. The set of three integer values for the lengths of the sides
of a right triangle is called a Pythagorean triple. The lengths of the three
sides must satisfy the relationship that the sum of the squares of two of the
sides is equal to the square of the hypotenuse. Write an application to find all
Pythagorean triples for side1, side2 and the hypotenuse, all
no larger than 500. Use a triple-nested for loop
that tries all possibilities.
3. Write an application
that displays the following patterns separately, one below the other. Use for loops to generate the patterns. All asterisks (*) should be printed by a single statement of the form
System.out.print( '*'
) ( which causes the asterisks to print side by
side), or.a statement of the form System.out.println()
(which can be used to position to the next line), or a statement of the
form System.out.print( '
' ) (which can be used to display a space for
the last two patterns). There should be no other output statements in the
program.
* **********
** *********
*** ********
**** *******
***** ******
****** *****
******* ****
******** ***
********* **
********** *
Remember to comment your code.