Questions
List two differences between Multi-Way Array Aggregation method and BUC method.

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 =...

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

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

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

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]

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

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: How do you simplify the...

JAVA

Answer the following questions as briefly (but completely) as possible:

  1. How do you simplify the max method in the following, using the conditional operator?
     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:     }
  2. Write method headers (just the declaration, not the bodies) for the following methods:
    1. Compute a sales commission, given the sales amount and the commission rate.
    2. Display the calendar for a month, given the month and year.
    3. Compute a square root of a number.
    4. Test whether a number is even, and returning true if it is.
    5. Display a message a specified number of times.
    6. Compute the monthly payment, given the loan amount, number of years, and annual interest rate.
    7. Find the corresponding uppercase letter, given a lowercase letter.
  3. Identify and correct the errors in the following program:
     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: }
  4. What is pass-by-value? Show the results of the following two programs.
    1.  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: }
    2.  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: }
  5. What is wrong with the following class?
    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. Write an expression that obtains a random integer between 34 and 55, inclusive.
    2. Write an expression that obtains a random integer between 0 and 999, inclusive.
    3. Write an expression that obtains a random number between 5.5 (inclusive) and 55.5 (exclusive).
    4. Write an expression that obtains a random lowercase (English) letter.
  6. How many times is the factorial method in the following invoked, for the call factorial(6)?
     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: }
  7. Suppose that the class F is defined as shown below. Let f be an instance of F. Which of the following statements are syntactically correct?
    1: public class F {
    2:   int i;
    3:   static String s;
    4:   void iMethod () {
    5:   }
    6:   static void sMethod () {
    7:   }
    8: }
    1. System.out.println(f.i);
    2. System.out.println(f.s);
    3. f.iMethod();
    4. f.sMethod();
    5. System.out.println(F.i);
    6. System.out.println(F.s);
    7. F.iMethod();
    8. F.sMethod();
  8. Add the static keyword in the place of ?, if appropriate, in the code below.
     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: }
  9. Can each of the following statements be compiled?
    1. Integer i = new Integer("23");
    2. Integer i = new Integer(23);
    3. Integer i = Integer.valueOf("23");
    4. Integer i = Integer.parseInt("23", 8);
    5. Double d = new Double();
    6. Double d = Double.valueOf("23.45");
    7. int i = (Integer.valueOf("23")).intValue();
    8. double d = (Double.valueOf("23.4")).doubleValue();
    9. int i = (Double.valueOf("23.4")).intValue();
    10. String s = (Double.valueOf("23.4")).toString();
    1. How do you convert an integer into a string?
    2. How do you convert a numeric string into an integer?
    3. How do you convert a double number into a string?
    4. How do you convert a numeric string into a double value?

In: Computer Science

For CBC mode with DES, if there is an error in C_1, are any blocks beyond...

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

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

(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...

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

Some of the well-known and best studied security models are listed below. Select a security model,...

Some of the well-known and best studied security models are listed below. Select a security model, research and submit a detailed post.

1. Bell-LaPadula Confidentiality Model
2. Biba Integrity Model
3. Clark-Wison (well-formed transaction) Integrity Model
4. Brewer-Nash (Chinese Wall)

In: Computer Science

In Java Describe an algorithm that given a matrix described below determines whether matrix contains a...

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

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