Professional Documents
Culture Documents
Id:
Program: Day class Night class
QUESTION 1[30pt]: Write necessary classes and enum types for given following UML diagram. All the
classes are declared in the same package.
a) Create Animal, Zoo Classes and
AnimalType according to the given
UML class diagrams.
a. Create a class called EncapsulatedStudent, which applies data encapsulation (data hiding) to
Student class.
b. EncapsulatedStudent class should throw an exception (with an error message) if any illegal
arguments (midterm and finalExams) are set.
c. Inside the MainClass, create an instance (student1) from EncapsulatedStudent, set attributes for it,
handle any exception, and print the error message on the screen. Use getAverage() method to return the
average score, then print it on the screen. [averageScore= midTerm *0.4 + finalExam*0.6;]
Question.2
a. Student 'a data encapsulation (kapsülleme, gizleme) prensibini uygulayan EncapsulatedStudent adlı bir class oluşturun.
b. Illegal bir arguman ( midterm veya finalExams icin) girilirse, EncapsulatedStudent sınıfı bir exception (bir hata mesajıyla)
firlatmalidir.
c. MainClass’ta EncapsulatedStudent sinifindan bir student1 nesnesi (instance) oluşturun ve degiskenleri girin, herhangi bir exception
durumuyla başa çıkın (handle edin) ve hata mesajını ekrana yazdırın. Ortalama puanı döndürmek için getAverage() metodunu kullanın,
ardından ekrana yazdırın. [averageScore= midTerm *0.4 + finalExam*0.6;]
QUESTION.3 [20p]: Write outputs in the given table. All the classes are declared in the same package.
public class Worker { public class MainClass {
String name; public static void main(String[] args) {
public static String compName,
public static int number; Worker w1 = new Worker("Ahmet");
public int id; System.out.println(Worker.compName); //(1)
for(Level l : levels)
System.out.println(l + ":" +l.getDesc());
}
}
-C#: Hey, Can I Copy Your Homework?
-Java: “Yeah, change it up a bit, so it looks like you didn’t copy.
C#: Sure thing Good Luck!
Q1.
this.midTerm = midTerm;
}
this.finalExam = finalExam;
}
try{
Student s = new Student(-5, 99);
System.out.println(s.getAverage());
}
catch(Exception e){
System.out.println(e.getMessage());
}
}
}