What are three of your favorite Web 2.0 technologies or Web sites? Explain what is so great about each of them and how they might be improved.
(Dont copy previous answers)
In: Computer Science
A) What happens when a software Interrupt occurs? Write steps briefly?
B) Differentiate between maskable and non-maskable interrupts?
C) How are the multiplexed bus of 8086 demultiplexed?
D) Find the address range when a 2K x 8 memory is interfaced with 8086/8088?
In: Computer Science
The centered average of a list of numbers is the arithmetic mean of all the numbers in the list, except for the smallest and largest values. If the list has multiple copies of the smallest or largest values, only one copy is ignored when calculating the mean. For example, given the list [1, 1, 5, 3 5, 10, 8, 7], one 1 and 10 are ignored, and the centered average is the mean of the remaining values; that is, 5.2. Use the function design recipe to develop a function named centered_average. The function takes a list of integers. (Assume that the list has at least three integers). The function returns the centered average of the list. Hint: In this exercise you are permitted and encouraged to use Python's min and max functions.
**** YOU CANNOT USE THE FOLLOWING:
list slicing (e.g., lst[i : j] or (lst[i : j] = t) the del statement (e.g., del lst[0]) Python's built-in reversed and sorted functions. any of the Python methods that provide list operations; e.g., append, clear , copy , count, extend, index, insert, pop, remove, reverse and sort list comprehensions
In: Computer Science
You must program the game called MaDi which is described below.
There is a board of NxN (the size N is defined by the user and must
be a number greater than or equal to 2), where in each box there is
an instruction. The first (the [0] [0]) and the last box (the [N-1]
[N-1]) have no instruction. Possible instructions are:
1. Don't move
2. Advance 4 places
3. Jump to the next row
4. Go back 2 places
5. It exploded! End of the game.
In order to facilitate the visualization of the matrix for the
player, the instruction number will be displayed on the board and
below it the list of instructions with their numbering.
Instructions:
1. Don't move
2. Advance 4 places
3. Jump to the next row
4. Go back 2 places
5. Bomb! Exploded.
The instruction that goes in each square of the board will be
assigned randomly each time the game starts.
The player starts with his chip in the first position (row: 0,
column: 0) and (bottom-right corner). On each turn the player rolls
a die that will tell him how many spaces to advance. You advance
across the board from left to right and from top to bottom as
follows:
On each turn the player rolls a dice that tells him how many
positions on the board to advance. After advancing, he must execute
what is indicated in the instruction of the box where he fell. For
each turn, only execute one instruction on the board. The player
has a maximum number of rolls of the dice, which will be asked to
the player when starting the game.
The game is lost if the dice are thrown without having reached the
goal or if the product of rolling the dice advances to a square
with a bomb. The game is won if you reach the goal (it does not
have to be by exact count) before the roll of the dice runs
out.
In: Computer Science
Write a function that plots the following trajectory equations using python turtle graphics.
x = v*sin(A)*t
y = v*cos(A)*t -.5*(9.8)*t**2
Loop through t starting at 0 and increment by .1 until y<=0. (hint, while loop) Experiment with values of velocity V (1 to 20) and angle A (0 to 90) that gives you a good plot that does not go off the screen. Position the start of the plot at the left bottom of the screen
In: Computer Science
1- Write a class called MedicalStaff that is a Person (the class that you wrote in last lab). A MedicalStaff has specialty (i.e. Orthopedic, cardiology, etc.).
2- Then write two classes:
Doctor class has office visit fee.
Nurse class has title (i.e. RN, NP, etc.)
Both classes inherit from MedicalStaff.
Be sure these are all complete classes, including toString method.
3- Write a tester to test these classes and
their methods, by creating an array or ArrayList of
Person and adding different kinds of objects
(MedicalStaff, Doctor, Nurse) to it.
Now that you know polymorphism, you don't need to create specific
references for each object.
4- Print the list of Person items by calling toString method in a for-each loop.
The Person class was,
public class Person { // Decalring super class//
private String name; // attributes
private int birthYear;
public Person(String n, int y) {
this.name = n;
this.birthYear = y;
}
public Person() {
name = "";
birthYear = 0;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getbirthYear() {
return birthYear;
}
public void setbirthYear(int birthYear) {
this.birthYear = birthYear;
}
public String toString() {
return "Person [name=" + name + ", birthYear=" + birthYear +
"]";
}
}
In: Computer Science
Question #1
The commented codes in the Driver class are either causing a syntax error or run time error. Make sure to identify the error yourself without running it.
predict the output once you fix all the errors.
Make sure you are able to answer similar question if it appears in the exam.
public class Cup extends Box { public void method1() { System.out.println("Cup 1"); } public void method2() { System.out.println("Cup 2"); super.method2(); } } class Pill { public void method2() { System.out.println("Pill 2"); } } class Jar extends Box { public void method1() { System.out.println("Jar 1"); } public void method2() { System.out.println("Jar 2"); } } class Box extends Pill { public void method2() { System.out.println("Box 2"); } public void method3() { method2(); System.out.println("Box 3"); } } class Driver { public static void main(String[] args) { Box var1 = new Box(); Pill var2 = new Jar(); Box var3 = new Cup(); Box var4 = new Jar(); Object var5 = new Box(); Pill var6 = new Pill(); var1.method2(); var2.method2(); var3.method2(); var4.method2(); // var5.method2(); //error var6.method2(); var1.method3(); // var2.method3();//error var3.method3(); var4.method3(); //((Cup)var1).method1(); //runtime error ((Jar)var2).method1(); ((Cup)var3).method1(); // ((Cup)var4).method1(); //runtime error ((Jar)var4).method2(); ((Box)var5).method2(); // ((Pill)var5).method3();//error ((Jar)var2).method3(); ((Cup)var3).method3(); // ((Cup)var5).method3();//runtime error } }
****************************************************************************************************************
Question 2
Comparable Programming. Suppose you have a pre-existing class BankAccount that represents users' accounts and money deposited at a given bank. The class has the following data and behavior:
Field/Constructor/Method |
Description |
private String name |
name of the person using the account |
private int id |
ID number of this account |
private double balance |
amount of money currently in the account |
public BankAccount(String name, int id) |
makes account with given name/ID and $0.00 |
public void deposit(double amount) |
adds given amount to account's balance |
public int getID() |
returns the account's ID number |
public String getName() |
returns the account's name |
public double getBalance() |
returns the account's balance |
public String toString() |
returns String such as "Ed Smith: $12.56" |
public void withdraw(double amount) |
subtracts given amount from account's balance |
Make BankAccount objects comparable to each other using the Comparable interface.
use the following rules to implement the compareTo method
public class BankAccount implements Comparable {
public int compareTo(Object o) { BankAccount other = (BankAccount)o; if (balance > other.getBalance()) { return 1; } else if (balance < other.getBalance()) { return -1; } else if (id > other.getID()) { return 1; } else if (id < other.getID()) { return -1; } else { return 0; } } }
****************************************************************************************************************
Question 3
Add a compreTo method to the Passenger class that you created for the previous assignment. Passengers should be compared based on their last names. If two passengers have the same last name then the seat numbers must be compared.
Solution
public int compareTo(Object o) { Passenger p = (Passenger)o; //checking to see if the last names are the same, if it is then compare based on the seat number if (this.getLast().equalsIgnoreCase(p.getLast())) return this.seatNumber - p.seatNumber; else return this.getLast().compareTo(p.getLast()); //if the last names are not the same then compare the last names }
PreviousNext
****************************************************************************************************************
Question 4
You should be able to answer the following questions
Part 1.create an interface called Incrementable that has two methods called increment and decrement. both of these methods have a parameter of type integer and they don't return anything.
part 2:
The following code does not compile. what is the issue? how can you fix the problem
interface Pay { public double getRaise(); public String getPromotion(double num); } class Secretary implements Pay { public Secretary() { } public void getRaise() { System.out.println("You got a Raise"); } public double getPromotion(int num) { System.out.println("You got " +num + " promotion"); } }
dsfdfdf
PreviousNext
****************************************************************************************************************
question 5
Suppose that the following two classes have been declared:
public class Car { public void m1() { System.out.println("car 1"); } public void m2() { System.out.println("car 2"); } public String toString() { return "vroom"; } } class Truck extends Car { public void m1() { System.out.println("truck 1"); } public void m2() { super.m1(); } public String toString() { return super.toString() + super.toString(); } }
Write a class MonsterTruck whose methods have the behavior below. Don't just print/return the output; use inheritance to reuse behavior from the superclass.
Method Output/Return
m1 : monster 1
m2 : truck 1
car 1
toString: "monster vroomvroom"
Solution
class MonsterTruck extends Truck { public void m1() { System.out.println("Monster 1"); } public void m2() { super.m1(); super.m2(); } public String toString() { return "Monster "+ super.toString(); } } class Driver { public static void main(String[]args) { MonsterTruck m = new MonsterTruck(); m.m1(); m.m2(); System.out.println(m); } }
your turn:
the following classes have been created.
class Eye extends Mouth { public void method1() { System.out.println("Eye 1"); } } class Mouth { public void method1() { System.out.println("Mouth 1"); } public void method2() { System.out.println("Mouth 2"); } } class Nose extends Eye { public void method1() { System.out.println("Nose 1"); } public void method3() { System.out.println("Nose 3"); } }
create a class called Ear that extends Nose. this class must implement the method1, method2, method3 . After creating the Ear class the following drive should generate the given output
class Driver { public static void main(String[] args) { Ear e = new Ear(); System.out.println("calling method 1"); e.method1(); System.out.println("calling the method 2"); e.method2(); System.out.println("calling the method 3"); e.method3(); } } Output: calling method 1 Nose 1 Ear1 calling the method 2 Ear 2 Mouth 2 calling the method 3 Ear 3 Nose 1
public class Ear extends Nose { //your code }
****************************************************************************************************************
Question 6
The following classes have been created.
public class Plate { public void method1() { System.out.println("Plate"); } } class Fork { public void method2() { System.out.println("Fork"); } } class Spoon { public void method3() { System.out.println("Spoon"); } }
The following driver has been created but it does not compile. what is the cause of the error and how can you fix it.
class Driver { public static void main(String[] args) { Object[] stuff = {new Spoon(), new Fork(), new Plate()}; for(int i = 0; i < stuff.length; i++) { stuff[i].method1(); Stuff[i].method2(); stuff[i].method3(); } } }
solution: since there is an array of Objects, every element in the array must be type casted to the proper type. then the method from the class can be called on it.
class Driver { public static void main(String[] args) { Object[] stuff = {new Spoon(), new Fork(), new Plate()}; for(int i = 0; i < stuff.length; i++) { if(stuff[i] instanceof Plate) { Plate p = (Plate)stuff[i]; p.method1(); } else if(stuff[i] instanceof Fork) { Fork f = (Fork)stuff[i]; f.method2(); } else if(stuff[i] instanceof Spoon) { Spoon s = (Spoon)stuff[i]; s.method3(); } } } }
****************************************************************************************************************
Question 7
There will one question related to ArrayList class similar to the following question.
The following driver has created a an ArrayList of Point objects. write a method that moves all the points with the value of x greater than its value of y to the end of the list. .
import java.util.*; public class ArrayistQuestion { public static void main(String[] args) { ArrayList<Point> points = new ArrayList<Point>(); points.add(new Point(12, 5)); points.add(new Point(2,23)); points.add(new Point(6,3)); points.add(new Point(9,2)); points.add(new Point(12,23)); System.out.println(points); shift(points); System.out.println(points); } //this method shifts all the points with x greater than y to the end of the list public static void shift(ArrayList<Point> list) { int count = list.size(); for(int i = 0; i < count; i++) { if(list.get(i).getX() > list.get(i).getY()) { Point p = list.get(i); //make a copy of the Point object list.remove(i);//removes it from the list list.add(p); // adds it ot the endof the list i--; count--; // decrement the count by 1 since one element has been removed } } } } class Point { private int x; private int y; public Point(int x, int y) { this.x = x; this.y = y; } public int getX() { return x; } public int getY() { return y; } public String toString() { return "(x = "+ x + " y = " + y+" )"; } }
****************************************************************************************************************
In: Computer Science
This is based on LinkedLists. Please complete the methods max() and threshold(). I'd greatly appreciate it. There is a type mismatch in my first method and I dont know how to get around it. I've commented on the line with the type mismatch. Please write a correct method in the answer so I can compare it to my wrong method
public class Node {
public T info;
public Node link;
public Node(T i, Node l) {
info = i; link = l;
}
}
class LinkedList> {
protected Node head = null;
public LinkedList add(T el) {
head = new Node(el, head);
return this;
}
public void print() {
for(Node node = head; node!=null; node=node.link) {
System.out.print(node.info+" ");
}
System.out.println("");
}
public T maxValue() { // Note: Recursive methods not allowed, using
new key word not allowed, no iterators allowed
if (head == null) {
return null;
}
else {
Node temp = head;
if (temp.link == null) {
return temp.info;
}
else {
T max = temp.link; //type mismatch
if (temp.info.compareTo(max) > 0)
max = temp.info;
return max;
}
}
}
public void threshold(T thres) {//Note: Recursive methods not
allowed, using new key word not allowed, no iterators allowed
}
public static void main(String args[]) {
LinkedList list = new LinkedList();
System.out.println(list.maxValue()); // should be null
list.add(20).add(30).add(10);
System.out.println(list.maxValue()); // should be 30
list.threshold(40);
list.print(); // should print out all elements
list.threshold(30);
list.print(); // should print out 10 20
list.threshold(10);
list.print(); // should print nothing
}
}
In: Computer Science
To get some practice with recursion.
You can do all this in one driver program.
Write a recursive method to compute the result of the Fibonacci sequence:
Fibonacci(N) = Fibonacci(N -1) + Fibonacci(N-2)
N == 0 is 0
N == 1 is 1
Testing: Display the result for Fibonacci(N) and the number of function calls for N = 2, 5 and 10.
In: Computer Science
CODE IN JAVA
Create a new class named Task1. In its main function, use Scanner to read integers from the keyboard with the method nextInt. Use a try catch block to capture non-integer input, and tell the user, "This is not an Integer". The program loop should end when the user enters the string "quit". (Hint: "quit" is clearly not a number and will be captured in the try / catch block.)
A typical Output Dialog is shown below:
Enter an Integer: 5 You typed.......: 5 Enter an Integer: 91 You typed.......: 91 Enter an Integer: 8.7 >>> That is not an Integer! Enter an Integer: 34 You typed.......: 34 Enter an Integer: Isabelle >>> That is not an Integer! Enter an Integer: 45 You typed.......: 45 Enter an Integer: quit ::: End Program
In: Computer Science
Describe how the Round Robin Scheduling algorithm works. Explain the differences of working procedure between preemptive and non-preemptive version of this algorithm.
In: Computer Science
Task 1
Please import the “admit.csv” into Rstudio. In this dataset, we know the GRE score, the GPA, and the rankof 400 applicants for a graduate program. We also know if each of the candidates is admitted. In the admit column, 1 stands for “admitted”, and 0 stands for “rejected”. Please answer the following questions and include the codes.
1. import the dataset and call it "mydata". Then check the structure of the data
2. convert the data type of the admit and the rank column from int to factors
3. randomly select 80% of the dataset as training set and the rest as the testing set
4. train a decision tree model, using admit as the category, and gre, gpa, and rank as predictors. Then plot the tree
5. Please answer the question: if a candidate has a GPA of 3.7, and rank of 4, does this candidate have a higher chance to be admitted or to be rejected? Please note that when you only have two categories, the darker proportion stands for the proportion for 1 in the end node of the tree plot
6. Please calculate the accuracy of your decision tree model
In: Computer Science
1. What is the average waiting time for Processes If the Operating System uses the Shortest-Job-First (SJF) Scheduling Algorithm?
(P1=5 ms, P2=10 ms, P3=15 ms)
2. How many page faults occur in the Optimum Page Replacement algorithm (OPR) with the following reference string for three-page frames?
Reference String: 4,2,1,3,2,3,4,1
3. What is the average waiting time for Processes If the Operating System uses Shortest-Job-Remaining-First (SJRF) Scheduling Algorithm?
(P1=5 ms, P2=10 ms, P3=15 ms)
Arrival Time ( P1=0 ms, P2=5 ms, P3=10 ms)
4. What is the average waiting time for Processes If Operating System uses the First Come First Serve (FCFS) Scheduling Algorithm?
(P1=5 ms, P2=10 ms, P3=15 ms)
Process Order: P2, P1, P3
5. What is the average waiting time for Processes If the Operating System uses Round Robin (RR) Scheduling Algorithm?
(P1=5 ms, P2=10 ms, P3=15 ms)
Time slice/ quantum = 5 ms
6. What is the average waiting time for Processes If the Operating System uses the Priority Scheduling (PS) Scheduling Algorithm?
(P1=5 ms, P2=10 ms, P3=15 ms)
Priority Order: P3, P1, P2
7. How many page faults occur in the FIFO replacement algorithm with the following reference string for THREE-page frames?
Reference String: 4,2,1,3,2,3,4,1
8. How many page faults occur in the Least Recently Used Algorithm (LRU) with the following reference string for three-page frames?
Reference String: 4,2,1,3,2,3,4,1
In: Computer Science
Describe how the Shortest Job First (SJF)Scheduling algorithm works. Explain the differences of working procedure between preemptive and non-preemptive version of this algorithm.
In: Computer Science
Write a Python program:
The function is named validity(). It receives 2 floating point parameters, min and max, from the program that invoked it. The function asks the user to enter a float number. Using a while loop it checks whether the number is valid (between min and max, inclusive). If not valid, the while loop uses this statement to prompt for a new number: num = float (input (" Enter a number that is at least :"+ str(min) + "and at most: "+ str(max) + " : ")). Once the function decides a number is valid, it returns it to the program. The program inputs 2 floating point numbers, max and min. It then invokes the validity() function with this statement: “validNum = validity(max,min)”. Once a valid number is returned to the program by the function. The program will print out the values of max, min, and the valid number returned.
In: Computer Science