Great Deal! Get Instant $10 FREE in Account on First Order + 10% Cashback on Every Order Order Now

this was my professors feedback on the last assignment (Please work on increasing your pylint score. Also, pylint gives scores on a 10.0 pt scale, so not sure what you are...

1 answer below »
Microsoft Word - Homework 4.docx
1
Homework 4

1. (10 pts) For the following program, explain the interesting elements related to threads. Focus on
explaining the output of the program.

1 public class TaskThreadDemo {
2 public static void main (String args []) {
3 String [] sa = {"a", "X", "+", "."};
4 for (String s: sa) {
5 Runnable ps = new PrintChar (s, 200);
6 Thread ts = new Thread (ps, s);
7 ts.start ();
8 }
end for each character
9 }
end main
10 }
end class TaskThreadDemo
11
12 class PrintChar implements Runnable {
13 String ch;
14 int times;
15
16 public PrintChar (String c, int n) {
17 ch = c;
18 times = n;
19 }
end constructor
20
21 public void run () {
22 for (int i = 0; i < times; i++) {
23 System.out.print (ch);
24 }
end for loop
25 }
end method run
26 }
end class PrintChar

2. (10 pts) What is changed if the method called on line 7, start(), is replaced with run()? Explain (of
course). Focus on explaining the output of the program.

3. (10 pts) What is changed if the method Thread.yield() is added between lines 23 and 24? Explain.
Focus on explaining the output of the program.

4. (10 pts) Modify the above program so that the Thread.sleep method is called after each character has
een printed causing it to sleep for 500 milliseconds. Describe how that modification has altered the
output and explain why the change had the effect that you described.

5. (10 pts) Modify the above program so that the Thread.sleep method is called after each thread is
created in the main method causing it to sleep for 500 milliseconds. Describe how that modification has
altered the output and explain why the change had the effect that you described.
2
Grading Ru
ic:

Attribute Meets Does not meet
Problem 1 10 points
Explains the interesting elements
elated to threads. Focuses on
explaining the output of the program.
0 points
Does not explain the interesting elements
elated to threads. Does not focus on
explaining the output of the program.
Problem 2 10 points
Explains what is changed if the
method called on line 7, start(), is
eplaced with run().Focuses on
explaining the output of the program.
0 points
Does not explain what is changed if the
method called on line 7, start(), is replaced
with run(). Does not focus on explaining
the output of the program.
Problem 3 10 points
Explains what is changed if the
method Thread.yield() is added
etween lines 23 and 24. Focuses on
explaining the output of the program.
0 points
Does not explain what is changed if the
method Thread.yield() is added between
lines 23 and 24. Does not focus on
explaining the output of the program.
Problem 4 10 points
Explains how the output is changed if
the Thread.sleep method is called
after each character has been
printed.
0 points
Does not explain how the output is
changed if the Thread.sleep method is
called after each character has been
printed.
Problem 5 10 points
Explains how the output is changed if
the Thread.sleep method is called
after each thread is created in the
main method.
0 points
Does not explain how the output is
changed if the Thread.sleep method is
called after each thread is created in the
main method.
Answered 1 days After Nov 11, 2024

Solution

Bhaumik answered on Nov 12 2024
3 Votes
Lab [X] report
Executive Summary
1. Input Validation:
· Phone numbers are validated using a regex pattern ^\d{3}-\d{3}-\d{4}$.
· Zip codes are validated with the pattern ^\d{5}-\d{4}$.
2. Matrix Input:
· A function get_matrix_input() gathers 3x3 matrix values with validation for numeric input.
3. Matrix Operations:
· The perform_operation function applies addition, subtraction, matrix multiplication (using np.matmul), or element-wise multiplication based on user choice.
4. Result Display:
· The display_results function prints the matrix result, its transpose, row mean, and column mean.
5. Program Loop:
· The program loops until the user decides to exit, ensuring a continuous experience.
This python application validates user inputs and performs matrix operations. It supports both phone number and zip code validation. Users can perform addition and subtraction and element-wise multiplication on two 3x3 matrices. The program will calculate the results, provide transposes, and compute row and column means of the resulting matrices. Test cases were designed for each feature to ensure it worked co
ectly. For instance, Test Case 1 and Test Case 2 validate that the phone numbers and zip codes are in the proper format, and test cases Test Cases 3 through 6 validate the execution of the matrix operations-addition, subtraction, multiplication, and element by element multiplication of matrices. All these test cases had expected results that validated the working of the program for multiple scenarios. This will integrate user input validation with the mathematical operations so that a matrix-based application can be made interactive and reliable.
Testing
Test Case Table
    Test Cases
    Description
    Expected Output
    Actual Output
    Pass/Fail
    Test Case 1
    Phone Number: 555-555-5555
    Valid phone numbe
    Valid phone numbe
    Pass
    Test Case 2
    Zip Code: 21022-3213
    Valid zip code
    Valid zip code
    Pass
    Test Case 3
    Matrix Operation: Addition of matrices
    Matrix addition result, transpose, row mean, column mean
    Matrix addition result, transpose, row mean, column mean
    Pass
    Test Case 4
    Matrix Operation: Subtraction of matrices
    Matrix subtraction result, transpose, row mean, column mean
    Matrix subtraction result, transpose, row mean, column mean
    Pass
    Test Case 5
    Matrix Operation: Multiplication of matrices
    Matrix multiplication result, transpose, row mean, column mean
    Matrix...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Looking For Homework Help? Get Help From Best Experts!

Copy and Paste Your Assignment Here