Write a Java program that includes in its class the following methods: - A method named unitMatrix which takes one parameter which is an integer (n) and - ‏prints a unit matrix of dimension (nxn). A unit matrix is a square matrix in which the - ‏diagonal elements are all 1s and the remaining elements are 0s. - ‏For example for n = 3 the printed unit matrix should be: - ‏1 0 0 - ‏0 1 0 - ‏0 0 1 - ‏- A method named triangularMatrix which takes two parameters. The first parameter is - ‏an integer (n) which specifies the dimensions of the triangular matrix to be printed - ‏(nxn). The second parameter is a boolean which specifies the type of the triangular - ‏matrix: if its value is true, the printed matrix must be an upper triangular matrix - ‏(square elements with all elements below the diagonal are 0s), if its value is false the - ‏printed matrix must be a lower triangular matrix (square elements with all elements - ‏above the diagonal are 0s). - ‏The values of non-zero elements must start from 1 counting upwards throughout the - ‏rows. - ‏For example if n = 3 and the Boolean is true, the printed matrix is an upper triangular - ‏as follows: - ‏1 2 3 - ‏0 4 5 - ‏0 0 6 - ‏For example if n = 3 and the Boolean is false, the printed matrix is a lower triangular - ‏as follows: - ‏1 0 0 - ‏2 3 0 - ‏4 5 6 - ‏- In your main method, test the above two methods by calling them for different - ‏dimensionality values. Make sure that you test printing unit matrices, upper triangular - ‏matrices, and lower triangular matrices.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Write a Java program that includes in its class the following methods:
- A method named unitMatrix which takes one parameter which is an integer (n) and
- ‏prints a unit matrix of dimension (nxn). A unit matrix is a square matrix in which the
- ‏diagonal elements are all 1s and the remaining elements are 0s.
- ‏For example for n = 3 the printed unit matrix should be:
- ‏1 0 0
- ‏0 1 0
- ‏0 0 1
- ‏- A method named triangularMatrix which takes two parameters. The first parameter is
- ‏an integer (n) which specifies the dimensions of the triangular matrix to be printed
- ‏(nxn). The second parameter is a boolean which specifies the type of the triangular
- ‏matrix: if its value is true, the printed matrix must be an upper triangular matrix
- ‏(square elements with all elements below the diagonal are 0s), if its value is false the
- ‏printed matrix must be a lower triangular matrix (square elements with all elements
- ‏above the diagonal are 0s).
- ‏The values of non-zero elements must start from 1 counting upwards throughout the
- ‏rows.
- ‏For example if n = 3 and the Boolean is true, the printed matrix is an upper triangular
- ‏as follows:
- ‏1 2 3
- ‏0 4 5
- ‏0 0 6
- ‏For example if n = 3 and the Boolean is false, the printed matrix is a lower triangular
- ‏as follows:
- ‏1 0 0
- ‏2 3 0
- ‏4 5 6
- ‏- In your main method, test the above two methods by calling them for different
- ‏dimensionality values. Make sure that you test printing unit matrices, upper triangular
- ‏matrices, and lower triangular matrices.
- ‏2. Write a Java program that includes in its class the following methods:
- ‏- A method named duplicateSentence that takes a String and an integer, and returns a
- ‏String that consists of duplicating the passed String number of times that equals the
- ‏passed integer on separate lines.
- ‏For example, if the passed String is Welcome to Java!, and the passed integer is 4, the
- ‏returned String should be:
- ‏Welcome to Java!
- ‏Welcome to Java!
- ‏Welcome to Java!
- ‏Welcome to Java!
- ‏- A method named calculate that takes two double numbers and a character as
- ‏parameters. The character must be one of the four main operations +, -, *, or /. The
- ‏method must return a String that consists of the full equation that includes the two
- ‏numbers, the operation and the result.
- ‏For example, if the passed double numbers are 3.5 and 2.1, and the passed operation is
- ‏+, the returned String must be as follows:
- ‏3.5 + 2.1 = 5.6
- ‏If the passed character does not represent any of the four main operations, the method
- ‏must return the following String: “Wrong operation”.
- ‏- In your main method, test the above two methods:
- ‏o Print the String (Coding is fun!) 10 times by invoking the method
- ‏duplicateSentence.
- ‏o Declare two double variables, and invoke the method calculate and print the result
- ‏of their addition, subtraction, multiplication, and division.

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY