The bits transmitted by four stations A, B, C and D are multiplexed using Code Division Multiplexing (CDMA). Assume A transmits a 1 bit, B transmits a 0 bit, C transmits a 1 bit, and D is silent. Assume the following are the chip sequences of the four stations, answer below questions: SA = (-1 -1 -1 +1 +1 -1 +1 +1); SC = (-1 -1 +1 -1 +1 +1 +1 -1) SB = (-1 +1 -1 +1 +1 +1 -1 -1); SD = (-1 +1 -1 -1 -1 -1 +1 -1)
i) What is the transmitted sequence?
ii) Show how the receiver determines station B’s transmission.
In: Computer Science
In.java
In this program write a method called upDown that takes three integers as arguments and returns one of these 3 strings:
In the main method do the following:
read three integers from the user and call upDown for those integers, save the result in a variable, res1, and then print it.
---------- Sample run 1: Enter three integers separated by spaces: 2 0 9 These numbers are in order: none Enter three integers separated by spaces: 17 90 567 These numbers are in order: increasing different ---------- Sample run 2: Enter three integers separated by spaces: 90 9 1 These numbers are in order: decreasing Enter three integers separated by spaces: 7 3 1 These numbers are in order: decreasing same ---------- Sample run 3: Enter three integers separated by spaces: 3 3 4 These numbers are in order: none Enter three integers separated by spaces: 8 1 16 These numbers are in order: none same
In: Computer Science
List two differences between Multi-Way Array Aggregation method and BUC method.
In: Computer Science
import java.util.Scanner;
public class Lab5 {
public static void main(String[] args) {
final char SIDE_SYMB = '-';
final char MID_SYMB = '*';
Scanner scanner = new Scanner(System.in);
String inputStr = "";
char choice = ' ';
int numSymbols = -1, sideWidth = -1, midWidth = -1;
do {
displayMenu();
inputStr = scanner.nextLine();
if (inputStr.length() > 0) {
choice = inputStr.charAt(0);
}
switch (choice) {
case 'r':
System.out.println("Width of the sides?");
sideWidth = scanner.nextInt();
System.out.println("Width of the middle?");
midWidth = scanner.nextInt();
scanner.nextLine(); // Flush junk newline symbols
System.out.println();
System.out.println(buildRow(SIDE_SYMB, sideWidth, MID_SYMB,
midWidth));
break;
case 'p':
System.out.println("Number of symbols on the lowest layer?");
numSymbols = scanner.nextInt();
scanner.nextLine(); // Flush junk newline symbols
System.out.println();
System.out.println(buildPyramid(SIDE_SYMB, MID_SYMB, numSymbols));
break;
case 'd':
System.out.println("Number of symbols on the middle layer?");
numSymbols = scanner.nextInt();
scanner.nextLine(); // Flush junk newline symbols
System.out.println();
System.out.println(buildDiamond('*', ' ', numSymbols));
break;
case 'q':
System.out.println("Bye");
break;
default:
System.out.println("Please choose a valid option from the menu.");
break;
}
System.out.println();
} while (choice != 'q');
scanner.close();
}
/**
* Build a row of symbols (pattern) with the given parameters.
*
* For example, -----*****----- can be built by the parameters
*
* sideWidth = 5, midWidth = 5, sideSymb = '-', midSymb = '*'
*
* @param sideSymb A char to be repeated on both sides
* @param sideWidth Number of symbols on each side
* @param midSymb A char to be repeated in the middle
* @param midWidth Number of symbols in the middle
* @return A String of a row of the designed pattern
*/
private static String buildRow(
char sideSymb, int sideWidth, char midSymb, int midWidth) {
String result = "";
// YOUR CODE HERE
// Make one side
// -->
// Make the middle part
// -->
// Combine side + middle + side, save into "result"
// -->
return result;
} // End of buildRow
/**
* Build a pyramid pattern with the given parameters.
*
* For example, the following pattern
*
* -----*-----
* ----***----
* ---*****---
* --*******--
* -*********-
* ***********
*
* can be built by sideSymb = '-', midSymb = '*', numSymbols = 11
*
* When ptnHeight is not an odd integer, replace it by the closest
* even integer below. For example, if numSymbols is 10, use 9 instead.
*
* When ptnHeight is 0, return an empty String.
*
* @param sideSymb A char to be repeated on both sides
* @param midSymb A char to be repeated in the middle
* @param numSymbols The number of symbols on the lowest layer
* @return A String of the pyramid pattern.
*/
private static String buildPyramid(
char sideSymb, char midSymb, int numSymbols) {
String result = "";
int sideWidth = -1, midWidth = -1;
// YOUR CODE HERE
// If numSymbols is 0, return an empty string
// -->
// If numSymbols is not an odd number, find the
// odd number less than numSymbols and replace it
// -->
// Make a loop to iterate the pyramid's levels
for (????????????) {
// Compute the number of middle symbols
// -->
// Compute the number of symbols on one side
// -->
// Use the "buildRow" method to make a row, then
// add the row to the variable "result".
// You may need to add a linebreak char "\n".
// -->
}
return result;
}
/**
* Build a diamond pattern. The parameters are the same
* as {@link #buildPyramid(char, char, int)}.
*
* @param sideSymb A char to be repeated on both sides
* @param midSymb A char to be repeated in the middle
* @param numSymbols The height of a pyramid
* @return A String of the inverted diamond pattern.
*/
private static String buildDiamond(
char sideSymb, char midSymb, int numSymbols) {
String result = "";
// YOUR CODE HERE
// -->
return result;
}
/**
* Display the menu
*/
private static void displayMenu() {
System.out.println("Please choose one pattern from the list:");
System.out.println("r) Row");
System.out.println("p) Pyramid");
System.out.println("d) Shallow diamond");
System.out.println("q) Quit");
} // End of displayMenu
} // End of Lab5
Annotations
In: Computer Science
Consider the following Python function definition and determine what value will be returned by the 24. function call that follows.
def calculate(value, src):
result = 0
val_string = str(value)
size = len(val_string)
mult = src ** (size - 1)
for digit in val_string:
d = int(digit)
result += d * mult
mult = mult // src
return result
calculate(93, 2)
In: Computer Science
Now we want to display which error was thrown in our voting program.
Add the appropriate code to the try/except statement so the
exception is displayed.
Run the program and, when prompted, enter the word 'old' so your
output matches the output under Desired Output.
# Set the variable
age = input("What is your age?")
# Insert a try/except statement
# here when you convert the input
# to a number using int()
try:
age = int(age)
if age >= 18:
print("Go vote!")
except:
print("Please enter a valid age!")
Output :
invalid literal for int() with base 10: 'old'
Please enter a valid age!
We're still working with pie. Now we want to use the finally clause to display a message no matter what happens with our code.
Add the appropriate code to the try/except statement so that the
message "Enjoy your pie!" is displayed regardless of the error
caught (or not caught).
Run the program and, when prompted, enter the number 3 so your
output matches the output under Desired Output.
# Get Input
pieces = input("How many pieces of pie do you want? ")
# Attempt to convert to integer
try:
percentage = 1/int(pieces)
except ValueError:
print("You need to enter a number!")
except:
print("Something went wrong!")
else:
print("You get", format(percentage, ".2%"), "of the pie!")
Output:
Enjoy your pie!
You get 33.33% of the pie!
both problems are python
In: Computer Science
In IOS store data. Each method has its strengths and weaknesses. Compare and contrast methods, and give an example of an app (it doesn’t have to be a particular app, just an “app type”) that is appropriate for each type
In: Computer Science
Find L and U Using python3 programming language( using Doolittle's Decomposition method)
3X3 Matrices
[4,-1,0],[-1,4,-1],[0,-1,4]
In: Computer Science
1. A doctor’s office has at least 2 patients but can have up to 30 patients. All patients have names, number of doctor’s visits, and total copayments for the year so far. After each visit, you need to be able to update each patient’s number of doctor’s visits and total copayments for the year.
a. Create the UML for the class diagram for patients.
b. Create the Java implementation for patients.
In: Computer Science
JAVA
Answer the following questions as briefly (but completely) as possible:
1: /** Return the max of two numbers */
2: public static int max ( int num1, int num2 ) {
3: int result;
4:
5: if ( num1 > num2 )
6: result = num1;
7: else
8: result = num2;
9: return result;
10: } 1: public class Test {
2: public static method1(int n, m) {
3: n += m;
4: method2 (3. 4);
5: }
6:
7: public static int method2(int n) {
8: if ( n > 0 ) return 1;
9: else if (n == 0) return 0;
10: else if (n < 0) return -1;
11: }
12: } 1: public class Test {
2: public static void main ( String [] args ) {
3: int max = 0;
4: max(1, 2, max);
5: System.out.println(max);
6: }
7:
8: public static void max ( int value1, int value2, int max ) {
9: if ( value1 > value2 )
10: max = value1;
11: else
12: max = value2;
13: }
14: } 1: public class Test {
2: public static void main ( String [] args ) {
3: int i = 1;
4: while ( i <= 6 ) {
5: method1( i, 2 );
6: i++;
7: }
8: }
9:
10: public static void method1 ( int i, int num ) {
11: for ( int j = 1; j <= i; j++ ) {
12: System.out.print( num + " " );
13: num *= 2;
14: }
15: System.out.println();
16: }
17: }1: public class Test {
2: public static void method ( int x ) {
3: }
4: public static int method ( int y ) {
5: return y;
6: }
7: } 1: import java.util.Scanner;
2:
3: public class ComputeFactorial {
4: public static void main ( String [] args ) {
5: Scanner input = new Scanner( System.in );
6: System.out.print( "Enter a nonnegative integer: " );
7: int n = input.nextInt();
8:
9: // Display factorial
10: System.out.println( "Factorial of " + n + " is " + factorial(n) );
11: }
12:
13: /** Return the factorial for the specified number */
14: public static long factorial ( int n ) {
15: if ( n == 0 ) // Base case
16: return 1;
17: else
18: return n * factorial( n - 1 ); // Recursive call
19: }
20: }1: public class F {
2: int i;
3: static String s;
4: void iMethod () {
5: }
6: static void sMethod () {
7: }
8: }
1: public class Test {
2: private int count;
3: public ? void main ( String [] args ) {
4: ...
5: }
6: public ? int getCount () {
7: return count;
8: }
9: public ? int factorial ( int n ) {
10: int result = 1;
11: for ( int i = 1; i <= n; i++ )
12: result *= i;
13: return result;
14: }
15: }In: Computer Science
For CBC mode with DES, if there is an error in C_1, are any blocks beyond P_2 affected when decryption occurs? If instead there is a source error in P_1, how many ciphertext output blocks are affected?
In: Computer Science
How can I write a Python program that runs without crashing even though it has an error that a compiler would have caught and how can I write a Java program that crashes even after the compiler checked it. Please add comments that explain the problem, the outcome, and what this proves in both of the programs.
In: Computer Science
(C++) You are given a file consisting of students’ names in the following form: lastName, firstName middleName. (Note that a student may not have a middle name.)
Write a program that converts each name to the following form: firstName middleName lastName. Your program must read each student’s entire name in a variable and must consist of a function that takes as input a string, consists of a student’s name, and returns the string consisting of the altered name. Use the string function find to find the index of ,; the function length to find the length of the string; and the function substr to extract the firstName, middleName, and lastName.
Here are the names:
Miller, Jason Brian
Blair, Lisa Maria
Gupta, Anil Kumar
Arora, Sumit Sahil
Saleh, Rhonda Beth
Spilner, Brody
In: Computer Science
Let’s assume you do DES double encryption by encrypting a plaintext twice with K1 and K2 respectively. Is this method more secure than the regular single DES encryption? Please explain your reason.
In: Computer Science
In: Computer Science