CIS 174 LAB
ASSIGNMENT #2
Assigned date: Tuesday 2/4
Due date:Tuesday 2/12
25 points
Lab 2.1: Compiling a program with syntax errors (5 points)
The following Java program will not compile because the lines have been
mixed up and some lines have syntax errors.
import java.swing.*;
public Class lab21
{ public static main(String [] args)
{
//This program displays three lines
//YOUR NAME
System.out.printlin( "Welcome to CECS 174. ";
Systems.out.println( "Programming and Problem Solving I.');
system.out.println(Using multimedia approach)
Systems.exit(0);
}
Copy or cut and paste the following program into a file named Lab21.java,
and then compile the program. The program has some syntax errors, pay attention
to the types of error you will get and the line number in which the error has
occurred. Fix them one-by-one or as many as you can in each try, compile it
until there is no more error in the program. Run the program and make sure it
produces an output.
When the lines are properly rearranged and the syntax errors are corrected,
the program should display the following output:
Program output
Welcome to CECS 174
Programming and Problem Solving I
Using a Multimedia Approach
Lab 2.2: Running a program with a run time error ( 2 points)
Compile and run the following Java statements:
int x = 10, y;
y = x /0;
System.out.println("y = " + y);
Lab 2.3: Using common escape sequences (2 points)
Write a complete Java program that will display the following output:
"Welcome to CECS 174"
Lab 2.4: (9 points)
Running or walking burns out about 100 calories per mile. Write a program to calculate how many miles you would have to run or walk to burn off the burritos, salads, and shakes that you consume. Use the table shown below for the calculation.
| Food | Calories |
| Bean burritos | 357 |
| Salad with dressing | 185 |
| Milk shake | 388 |
The program would likely run as follows:



You ingested 1829 calories. You will have to run 18.29 miles to expend that much energy.
Lab 2.5 (7 points)
Write a program that prompts the users to input the elapsed time for an event in seconds. The program then outputs elapsed time in hours, minutes and seconds.
Sample run

Hours:Minutes:Seconds 2:40:30
Grading requirements
Demonstrate lab problems to the instructor in the lab.
A hard copy of your lab assignment report.