CSE1115 Mid 183
CSE1115 Mid 183
1. a) Write a Java program that will go through the items of an array and find the min value using enhance for [2]
loop. Take the following values as the initial values of the array {2, 3, 9, 8, 13, 1, 5, 19, 15}
2. a) Consider the following MovieTheater class. Now, write a Movie class in such a way that MovieTheater [3]
class will give expected output as shown below.
Code Output
public class MovieTheater { Playing: Debi [2018]
public static void main(String[] args) { Playing: Venom [2018]
Movie m_Debi = new Movie("Debi", 2018, "1hr 30min"); Movie name: Debi, year: 2018, Duration: 1hr 30min
Movie m_Venom = new Movie ("Venom", 2018, "1hr");
m_Debi.play();
m_Venom.play();
Movie.movieInfo(m_Debi);
}
}
b) Find out if the following JAVA programs have any error. Fix the code and rewrite. You cannot delete [2]
any line of code. However, you are allowed to edit or add any code as per requirement.
public class Simple { public class Test {
static int a=5; public static void main(String[] args) {
int b=6; Simple s=new Simple();
private int #x=5; Simple.sum();
private int data=100; System.out.println(s.data);
static void sum(){ }
System.out.println(a+b); }
}
}
3. a) Write a class Grader which has three attributes: name, id and payPerAssignment. The constructor of [4]
Grader class initializes name, id and payPerAssignment with this reference keyword. There is one method
named void printEarnings() which prints the earning of grader by multiplying the number of graded
assignments with per-assignment-pay. To do so, you should include one private instance variables in Grader
class definition: count. Use getter and setter methods in the class to set and get the values of the field.
Page 1 of 3
b) What is the difference between static binding and dynamic binding? [1]
4 a) Fix the following code and rewrite the correct one. [4]
class B extends A{
class A{ private int bi;
private int ai;
public B(){}
public A(int ai){ this.ai = ai; } public B(int bi){
this(0, bi);
void set(){ }
this.ai = 0;
} void set(){
void set(int ai){ ai = 0;
this.ai = ai; bi = 0;
} }
} void set(intai, int bi){
this.ai = ai;
this.bi = ai;
}
}
5. Suppose you are hired by a company to make them a java program that calculates each employee’s monthly [5]
salary. You decided to write an abstract class named Employee which has name and age as member variables
and calculateMonthlySalary() as abstract member function. There are two other concrete classes named
DailySalariedEmployee and HourlySalariedEmployee. Both of these classes are subclass of Employee class.
DailySalariedEmployee has a member variable dailySalary and HourlySalariedEmployee has a member
variable hourlySalary.
Now, write each of the classes (Employee, DailySalariedEmployee, HourlySalariedEmployee). You should
write appropriate constructors that initialize the member variables. There are 22 working days and 176 working
hours in a month.
Page 2 of 3
6. a) Write the output of the given code. [3]
public class Application {
public static void main(String[] args) {
public class Wizard { Wizard w1=new Wizard("Hagrid");
String name; Wizard w2=new Wizard("Sirius");
Wizard(String n) Wizard w3=new Wizard("Harry");
{
name=n; w1=w2;
} w2=w3;
} w3=w1;
System.out.println(w1.name);
System.out.println(w2.name);
System.out.println(w3.name);
}
}
System.out.println(e2.a);
System.out.println(e2.b);
System.out.println("Sum: "+2+3);
System.out.println('a'+2);
}
}
Page 3 of 3