CS110T Lab03 PDF
CS110T Lab03 PDF
Lab Objectives:
In this lab, the student will practice:
ü Defining variables of different data types
ü Reading data values from the user.
ü Compiling and executing Java applications.
ü Writing and evaluating mathematical expressions
Lab Exercise 1: Program Output
Problem Description: What is the output of the following code?
Output:
2
Lab Exercise 2: Java statements
Problem Description: Write Java statements that accomplish the following:
b. Initialize x to 10 and y to B.
3
Lab Exercise 3: Debugging
Problem Description: The following program has syntax errors. Correct them, then type and
compile the program to check if all errors have been found. (Hint: 7 errors must be found)
one = 18;
two ="apple";
first = 25.5;
second = first * three;
System.out.printf("%d \t %f \t %s\n",first,second,(second/3));
}
}
The solution :
4
Lab Exercise 4: Coding
Problem Description: A milk carton can hold 3.78 liters of milk. Each morning, dairy farm
ships cartons of milk to local grocery store. The cost of producing one liter of milk is $ 0.38
and the profit of each carton of milk is $ 0.27.
A simple Output
How many liters of milk you need this morning?
6
you need 2.0 cartons for the 6.0 liter of milk
The total cost is 2.87
The total profit is 0.54
code:
5
Assignment Problems:
Problem Description 1: Consider the following program segment:
public class Prog1
{
public static void main (String [] arg)
{
// variable declaration
// executable statements
}
}
Problem Description2: Write a program that asks the user to type the price without tax of one kilogram of
tomatoes, the number of kilograms you want to buy. The program must calculate the total price including
taxes.
Note: taxes are 5% of product price.
Simple Output:
Please enter the price without tax of one kilogram of tomatoes: 10
Please enter the number of kilograms: 5
Total price: 52.5 S.R.