Compre Review

download Compre Review

of 19

Transcript of Compre Review

  • 8/2/2019 Compre Review

    1/19

    Advance Programming

    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;

  • 8/2/2019 Compre Review

    2/19

    }

    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!!!");}

    }

  • 8/2/2019 Compre Review

    3/19

    /* 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();

  • 8/2/2019 Compre Review

    4/19

    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 thisconstructor 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 wilset 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. Inthe simplest case, an accessor just returns the value of one of the fields. In general, an accessor

  • 8/2/2019 Compre Review

    5/19

  • 8/2/2019 Compre Review

    6/19

  • 8/2/2019 Compre Review

    7/19

  • 8/2/2019 Compre Review

    8/19

  • 8/2/2019 Compre Review

    9/19

  • 8/2/2019 Compre Review

    10/19

  • 8/2/2019 Compre Review

    11/19

  • 8/2/2019 Compre Review

    12/19

  • 8/2/2019 Compre Review

    13/19

  • 8/2/2019 Compre Review

    14/19

  • 8/2/2019 Compre Review

    15/19

  • 8/2/2019 Compre Review

    16/19

    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 WaitResource 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

  • 8/2/2019 Compre Review

    17/19

    Consider the following set of processes:

    Process Arrivat Time Burst Time Priority

    P1 6 12 5

    P2 10 17 2

    P3 5 32 3

    P4 17 47 4

    P5 22 62 1P6 3 22 6

    1. Draw the Gantt Chart

    FCFS

    P6(22) P3(32) P1(12) P2(17) P4(47) P5(62)

    0 3 25 57 69 86 133 195

    SJF

    P6(22) P1(12) P2(17) P3(32) P4(47) P5(62)0 3 25 37 54 86 133 195

    SRTF

    P6(2) P6(1) P1(4) P1(7) P1(1) P2(4) P2(13) P6(19) P3(32) P4(47) P5(62)

    0 3 5 6 10 17 18 22 35 54 86 133 195

    NPP

    P6(22) P5(62) P2(17) P3(32) P4(47) P1(12)

    0 3 25 87 104 136 183 195

    PP

    P6(2) P3(1) P3(4) P2(7) P2(5) P5(62) P2(5) P3(27) P4(47) P1(12) P6(20)

    0 3 5 6 10 17 22 84 89 116 163 175 195

    RR Q=13

    P6(13) P3(13) P1(12) P2(13)P6(9

    )P4(13

    )P5(13

    )P3(13

    )P2(4

    )P4(13

    )P5(13

    )P3(6

    )P4(1

    3)P5(1

    3)

    0 3 16 29 41 54 63 76 89 102 102 106 119 132 138

    P4(8) P5(13)P5(13

    )P5(10

    )

    151 164 172 185195

  • 8/2/2019 Compre Review

    18/19

    2. What algorithm results in the lowest Average Turn-around time? Shortest Remaining Time First

    3. What algorithm results in the lowest Average waiting time? Shortest Remaining Time First

    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

    FCFS 63 76 52 116 173 22 83.67

    SJF 31 44 81 116 173 22 77.83

    SRTF 12 25 81 116 173 51 76.33

    NPP 189 94 131 166 65 22 111.2

    PP 169 79 111 146 62 192 126.5

    RR 35 92 127 147 173 60 105.7

    Lowest Average Turn-around Time76.33

    WAITING TIME

    WT1 WT2 WT3 WT4 WT5 WT6 WT AVE

    FCFS 51 59 20 69 111 0 51.67

    SJF 19 27 49 69 111 0 45.83

    SRTF 0 8 49 69 111 29 44.33

    NPP 177 77 99 119 3 0 79.17

    PP 157 62 79 99 0 170 94.5

    RR 23 75 95 100 111 38 73.67

    Lowest Average Waiting Time44.33

    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

    WangWang

    Laboratories

    1 2 3 4 5 6

    fcfs 69 86 57 133 195 25

    sjf 37 54 86 133 195 25

    srtf 18 35 86 133 195 54

    npp 195 104 136 183 87 25

    pp 175 89 116 163 84 195

    rr 41 102 132 164 195 63

    6 10 5 17 22 3

    FCFS 63 76 52 116 173 22

    SJF 31 44 81 116 173 22

    SRTF 12 25 81 116 173 51

    NPP 189 94 131 166 65 22

    PP 169 79 111 146 62 192

    RR 35 92 127 147 173 60

    tt= et-btwt=tt-

    bt

  • 8/2/2019 Compre Review

    19/19