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
In Java Describe an algorithm that given a matrix described below determines whether matrix contains a value k. The input matrix A[1...n, 1...n] has all rows and columns arranged in an non-descending order A[i, j] < A[i, j+1], A[j, i] < A[j + 1, i] for all 1 < i < n and 1 < j < n
In: Computer Science
Write a function divisibleBy3 with 2 positive integer inputs, a lower bound and an upper bound. Generate a list of integers from the lower bound to the upper bound and determine how many numbers in the list have a remainder equal to zero when dividing by 3.
Hint: Use a loop and the MATLAB built-in function rem to calculate the remainder after division. The remainder of N divided by P is rem(N,P).
In: Computer Science