Source Code: Lab02: Introduction To Java
Source Code: Lab02: Introduction To Java
BS(CS)- Semester 02
(Fall 2021)
Exercise 1 (Mosque.java)
}
}
OUTPUT:
CS Department, BUKC 2/5 Semester Fall 2021
CSL-210: Object-Oriented Programming Lab Lab02: Introduction to Java
Exercise 2 (Equations.java)
Wrtite a java program that calculates the following equation. Where x = 6, y = 20, z=13
2x2 + y2
3x + y -3z2
2x -2y + 5z2
Source code:
public class Main
{
public static void main(String[] args) {
int x=6,y=20,z=13;
System.out.println("2x^2+y^2=\n"+(2*x*x+y*y));
System.out.println("3x+y-3z^2=\n"+(3*x+y-3*z*z));
System.out.println("2x -2y + 5z^2=\n"+(2*x-2*y+5*z*z));
}
}
Output:
CS Department, BUKC 3/5 Semester Fall 2021
CSL-210: Object-Oriented Programming Lab Lab02: Introduction to Java
Exercise 3 (Arithmatic.java)
Type-in the following example, which receives the input of two integer numbers and compute the
sum, difference and product. Compile and run this program.
Source code:
public class Main
{
System.out.println("a-b="+(num1-num2));
System.out.println("a*b="+(num1*num2));
}}
OUTPUT:
Exercise 4 (Temperature.java)
Source Code:
public class Main
{
Exercise 5 (Cookies.java)
There are 12 cookies per box (sold at $1.14) and 24 boxes per carton. Left over boxes are sold for
57¢. Remaining cookies are given away free. Given the number of cookies produced, determine the
number of boxes, cartons, left over boxes and the total money made.
Exercise 6 (PullyFormulas.java)
Pulley formulas
a) calculate the speed of one pulley if there are 2 pulleys connected with a belt:
CS Department, BUKC 5/5 Semester Fall 2021
CSL-210: Object-Oriented Programming Lab Lab02: Introduction to Java
RPM2 = diameter1/diameter2 * RPM1
b) calculate the amount of weight that can be lifted with a multiple pulley system:
weight lifted = force exerted * number of up ropes