Assignment 1: Create ONE sample program problem that uses Features of Java Programming indicated below. Property Encapsulation (private / public variables) Inheritance (extends / superclass / subclass) Constructor Chaining Polymorphism Overriding Overloading Answer: /* This is the superclass */ public class Animal { private String name; private int age; private String gender; public Animal() { name = "Jose"; age = 20; gender = "male"; } public Animal(String name, int age, String gender) { this.name = name; this.age = age; this.gender = gender; } public void setName(String name) { this.name = name; } public String getName() { return name; } public void setAge(int age) { this.age = age;
} public int getAge() { return age; } public void setGender(String gender) { this.gender = gender; } public String getGender() { return gender; } public String toString() { return (name + " is a " + gender + " person and " + age + " years old."); } public String speak() { return ("Hello, everybody!!!"); } }
/* This is a subclass of Animal */ public class Cat extends Animal { private String breed; public Cat(String breed) { super(); this.breed = breed; } public String getBreed() { return breed; } public String speak() { return ("Meow, Meow, Meow!!!"); } }
/* This is also a subclass of Animal */ public class Dog extends Animal { private String breed; private String type; public Dog(String name, int age, String gender, String breed, String type) { super(name, age, gender); this.breed = breed; this.type = type; } public String toString() { String name = this.getName(); int age = this.getAge(); String gender = this.getGender(); return (name + " is a " + gender + " " + breed + " (which is a type of " + type + " dog) and " + age + " years old."); } public String speak() { return ("Arf, Arf, Arf!!!"); } }
/* This is the object program */ public class VariousAnimals { public static void main(String[] args) { Animal jose = new Animal(); System.out.println("\n" + jose); System.out.println(jose.getName() + ": " + jose.speak() + "\n"); Cat sprinkles = new Cat("Persian"); sprinkles.setName("Sprinkles"); sprinkles.setAge(5); sprinkles.setGender("female"); String name = sprinkles.getName(); int age = sprinkles.getAge(); String gender = sprinkles.getGender();
String breed = sprinkles.getBreed(); System.out.println(name + " is a " + gender + + breed + " cat and " + age + " years old."); System.out.println(name + ": " + sprinkles.speak() + "\n"); Dog brownie = new Dog("Brownie", 3, "female", "Chihuahua", "toy"); System.out.println(brownie); System.out.println(brownie.getName() + ": " + brownie.speak() + "\n"); } } Output: Jose is a male person and 20 years old. Jose: Hello, everybody!!! Sprinkles is a female Persian cat and 5 years old. Sprinkles: Meow, Meow, Meow!!! Brownie is a female Chihuahua (which is a type of toy dog) and 3 years old. Brownie: Arf, Arf, Arf!!!
Assignment 2: Differentiate Default Constructor from General Constructor Answer: A default constructor is a constructor that takes no argument. An object instantiated using this constructor will have the values of its variables equal to the values of the variables as defined (initialized) by its parent class. Example: Animal dog = new Animal(); A general constructor is one which takes arguments. An object instantiated using this constructor will set the values of its variables equal to the values in its parameter list. Example: Animal dog = new Animal(German Sheperd);
Assignment 3: Differentiate Accessor methods from Mutator methods Answer: An accessor is a method that accesses the contents of an object but does not modify that object. In the simplest case, an accessor just returns the value of one of the fields. In general, an accessor
performs some computation using the fields as long as that computation does not modify any of the fields. A mutator is a method that can modify an object. In the simplest case, a mutator just assigns a new value to one of the fields. In general, a mutator performs some computation and modifies any number of fields. Sometimes, accessors are called 'getter' methods and mutators are called 'setter' methods.
Advance Networking
Operating System
CPU Scheduling Non Pre-emptive FCFS SJF NPP Pre-emptive RR SRTF PP Deadlock set of blocked processes, each holding a resource and waiting to acquire a resource held by another process in a set. 4 condition to be satisfied Mutual Exclusion Hold and Wait No Pre-emption Circular Wait Resource Allocation Graph Handling Deadlock Prevention Avoidance Bankers Algorithm Memory Management Allocation can be contagious or non contagious Schemes- Compaction and multiple partition ( fixed or variable) Allocation Mechanics Best Fit First Fit Worst Fit Next Fit Variable Partition vs Fixed Partition Buddy System Paging Logical(u) vs physical address(v) Virtual Memory
Consider the following set of processes: Process P1 P2 P3 P4 P5 P6 1. Draw the Gantt Chart
FCFS P6(22) 3 P3(32) 25 P1(12) 57 P2(17) 69 P4(47) 86 P5(62) 133
Arrivat Time 6 10 5 17 22 3
Burst Time 12 17 32 47 62 22
Priority 5 2 3 4 1 6
0 SJF
195
0 SRTF
P6(22) 3
P1(12) 25
P2(17) 37
P3(32) 54
P4(47) 86
P5(62) 133
195
0 NPP
P6(2) 3
P6(1) 5
P1(4) 6
P1(7) 10
P1(1) 17
P2(4) 18
P2(13) 22
P6(19) 35
P3(32) 54
P4(47) 86
P5(62) 133
195
0 PP
P6(22) 3
P5(62) 25
P2(17) 87
P3(32) 104
P4(47) 136
P1(12) 183
195
P6(2) 0 3
P3(1) 5
P3(4) 6
P2(7) 10
P2(5) 17
P5(62) 22
P2(5) 84
P3(27) 89
P4(47) 116
P1(12) 163
RR
Q=13
P6(13) P3(13) 16 P1(12) 29 P2(13) 41 P6(9 ) 54 P4(13 ) 63 P5(13 ) 76 P3(13 ) 89 P2(4 ) 102 P4(13 ) 102 P5(13 ) 106 P3(6 ) 119 P4(1 3) 132 P5(1 3) 138
P4(8) 151
P5(13) 164
P5(13 ) 172
P5(10 ) 185 19 5
2. What algorithm results in the lowest Average Turn-around time? 3. What algorithm results in the lowest Average waiting time?
4. Calculate the Turn-Around Time and Waiting Time for each of the processes. (44 points)
TURN-AROUND TIME
TT1 TT2 TT3 TT4 TT5 TT6 TT AVE
63 31 12 189 169 35
76 44 25 94 79 92
22 22 51 22 192 60
2 86 54 35 104 89 102 10 76 44 25 94 79 92
4 133 133 133 183 163 164 17 116 116 116 166 146 147
6 25 25 54 25 195 63 3 22 22 51 22 192 60
WAITING TIME
WT1 WT2 WT3 WT4 WT5 WT6 WT AVE
51 19 0 177 157 23
59 27 8 77 62 75
20 49 49 99 79 95
69 69 69 119 99 100
0 0 29 0 170 38
Success is more of a function of consistent common sense than genius. Besides simplicity, other things I have found to be essential to success are communication, moderation and patience, adaptability, decisiveness, confidence, uncoventional thinking, social responsibility, and last but by no means least, luck. The importance of these attributes is in their interaction. Dr. An Wang Wang Laboratories