CSL-210: Object-Oriented Programming Lab
BS(CS)- Semester 02
                                                                                         (Fall 2021)
                               Lab02: Introduction to Java
Exercise 1                                                                        (Mosque.java)
Write a program that prints a mosque, similar to the following:
Source Code:
public class Main
{
        public static void main(String[] args) {
                System.out.println("        ^        ^      ^");
                System.out.println(" /|\\           /|\\    /|\\ ");
                System.out.println(" ((&)) .((^)).             ((&))");
                System.out.println(" |.| ((((^))))           |.| ");
                System.out.println(" |.| (((((|)))))        |.| ");
                System.out.println(" |.| (((((((|))))))) |.| ");
                System.out.println(" |.| ((((((|)))))) |.| ");
                System.out.println(" |.| (((((|)))))        |.| ");
                System.out.println(" {===============================} " );
                System.out.println(" ================================= " );
                System.out.println(" |                     | ");
                System.out.println(" |                     | ");
                System.out.println(" |                     | ");
                System.out.println(" |              --      | ");
                System.out.println(" | _ {#}             _ | ");
                System.out.println(" | |###| {###} |###| | ");
                System.out.println(" | |###| {#######} |###| | ");
                System.out.println(" | ==== {#########} ==== | ");
                System.out.println(" |            {#########}        | ");
                System.out.println(" |            {#########}        | ");
                System.out.println(" ( @@@@@@@@@@@=========@@@@@@@@@)
");
                System.out.println(" (++++++++++/============/++++++++) ");
                System.out.println(" [%%%%%%%%%/============/%%%%%%%%%] ");
                System.out.println(" ''''''''''/============/'''''''''''' ");
       }
}
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
{
    public static void main(String[] args){
         int num1=5,num2=11;
         System.out.println("a=5,b=11");
         System.out.println("a+b="+(num1+num2));
         System.out.println("a-b="+(num1-num2));
         System.out.println("a*b="+(num1*num2));
    }}
OUTPUT:
Exercise 4                                                                 (Temperature.java)
Celsius to Fahrenhite temperature: F=(C × 9/5) + 32
CS Department, BUKC                                   4/5                             Semester Fall 2021
CSL-210: Object-Oriented Programming Lab                                      Lab02: Introduction to Java
       C = temperature in celsius.
       F = temperature in fahrenhite
Calculate the temperature for the following degrees
      289 °C
      400 °C
      -36 °C
      -180 °C
   Source Code:
   public class Main
   {
       public static void main(String[] args){
                 int c=289,c2=400,c3=-36,c4=-180;
                 System.out.println("Degree F for "+ c +" degree celcius ="+(c*9/5+32));
                 System.out.println("Degree F for"+c2+"degree celcius="+(c2*9/5+32));
                 System.out.println("Degree F for"+c3+"degree celcius="+(c3*9/5+32));
                 System.out.println("Degree F for"+c4+"degree celcius="+(c4*9/5+32));
             }
         }
   OUTPUT:
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