Write a python program that:
Note:
- Students are referred to using an ID (automatically incremented, starting from 1).
Write a program to print the absolute difference between the two given numbers. (Absolute difference is the difference without the negative sign)
Write a program that plays a dice game with the user. The specification: The user begins with a score of 1000. The user is asked how many points to risk and then the computer rolls two dice. If an even total is rolled, the user loses the points at stake. If an odd total is rolled, the user receives double the points at stake. The program output may look similar to:
(User’s input is underlined)
Sample Run:
You have 1000 points.
Points to risk: 100
Roll is 3 and 5.
You lose.
Play again? Y
You have 900 points.
Points to risk: 200
Roll is 1 and 2.
You win.
Play again? N
Final score: 1300
Task should be accomplished by a user defined function(s).A prime number is an integer that has no factors other than one and itself. For example, 2, 3, 5, and 7 are prime while 9, 10, and 15 are not.Write a function IsPrime() that accepts a long greater than 1 as a parameter and returns a bool. The function should return true if and only if the integer is prime.
1. Using practical examples, describe green computing. List and explain the steps that you can take to contribute to green computing
3) Refer to the code segment below and answer the questions in the comments labelled Question i – vi. For each answer; provide a brief explanation for your answer.
public class Scope {
private int x = 2;
private int x = 1;
public void start() {
int x = 5;
int x = 2;
//Question i
System.out.printf( "The value of x is %d\n", x );
int x = 2;
//Question ii
System.out.printf( "\nThe value of x is is %d\n", x );
} // end method begin
public void middle() {
int x = 25;
//Question iii
System.out.printf( "\nThe value of x is %d\n", x );
++x;
//Question iv
System.out.printf( "The value of x is %d\n", x );
} // end method middle
public void end() {
//Question v
System.out.printf( "\nThe value of x is %d\n", x );
x *= 10;
//Question vi
System.out.printf( "The value of x is %d\n", x );
} // end method end
} // end class Scope
• Describe (4) FOUR general strategies for dealing with deadlocks.?
• What are the (4) FOUR conditions required for deadlock to occur?
A. Consider a problem to find the student who had the highest GPA for the 2020/2021 academic year. i. Explain your choice of either a search or a sorting algorithm to solve this problem.
ii. Write the algorithm for your implementation. [
B. Consider the analogy of a pile of books on a table. Using a diagram, explain the basic operations involved in adding a book to the pile and removing a book from the pile.
C. Use the code below to answer the questions that follow:
public class CS204 { public static int linearSearch(int[] data, int target) {
for (int i = 0; i < data; i++) {
if (target == data[i]){ return i; 5
}
}
return -1;
}
public void main(String[] args) {
int[] data = {3, 14, 7, 22, 45, 12, 19, 42, 6};
System.out.println("Search for 7: " +
linearSearch(7));
}
}
i. Why is method linearSearch declared static?
ii. Identify and resolve the errors in the code.
(b) Compare the two policies and then create a policy you believe would be fair to you as a student of RGI. Include guidelines for Internet use during school hours, breaks, use of smartphones, and restrictions for using social media and unauthorized websites.
(c) Compile your findings in a report format.
Q3 (B) The performance of an algorithm can be determined in terms of its time and space complexity. Explain the difference between time complexity and space complexity and make a case for which is the most efficient method for determining the performance of an algorithm. [7 marks]