Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Chapter 19, Problem 19.11PE
Program Plan Intro
ComplexMatrix
Program Plan:
- Include a class name named “Exercise19_11”.
- Declare util package.
- Declare main method.
- Define the matrices “arr1” and “arr2” using the class “Complex”.
- Using “for” loop, generate values into arrays.
- Add and multiply the matrices and multiply the matrices using “GenericMatrix” class.
- Define the method named “removeDuplicates”.
- Define the object “ans” for “ArrayList” class.
- Using condition, check the duplicate values in arrays and return the result.
- Include a class name named “ComplexMatrix” which extends the “GenericMatrix”.
- Define the method named “add()” which add two matrices and return the resultant value.
- Define the method named “multiply()” which multiplies two matrices and return the resultant value.
- Define the method named “zero()” which fills “0” to matrices.
- Include an abstract class name named “GenericMatrix”.
- Declare the methods “add”, “multiply”, and “zero” with generic object “E”.
- Define all the methods with their arguments.
- Define “printResult()” method to print the resultant values on screen.
- Include a class name named “Complex”.
- Declare package.
- Declare main method.
- Declare double variables “a” and “b”.
- Declare Constructors that creates a complex object for number 0.
- Declare a constructor that creates a complex object with 0 for b.
- Declare a constructor that creates a complex object with specified a and b.
- Declare a method to return real part of complex number.
- Declare a method to return imaginary part of complex number.
- Declare a method to add a complex number to this complex number.
- Create a method to subtract a complex number from this complex number.
- Create a method to multiply a complex number by this complex number.
- Create a method to divide a complex number by this complex number.
- Create a method that returns the absolute value of this complex number.
- The protected clone method defined in the Object class is overridden, its accessibility is strengthened.
- Close the main method.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
(Tic-Tac-Toe) Write a program that allows two players to play the tic-tac-toe game. Your program must contain the class ticTacToe to implement a ticTacToe object. Include a 3-by-3 two-dimensional array, as a private member variable, to create the board. If needed, include additional member variables. Some of the operations on a ticTacToe object are printing the current board, getting a move, checking if a move is valid, and determining the winner after each move. Add additional operations as needed.
I would really appreciate it if you could solve it quickly. Thank you so much
C++
The following describes the difference between void and NULL pointers: Make proper use of examples to bolster your argument.
Chapter 19 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 19.2 - Are there any compile errors in (a) and (b)?Ch. 19.2 - Prob. 19.2.2CPCh. 19.2 - Prob. 19.2.3CPCh. 19.3 - Prob. 19.3.1CPCh. 19.3 - Prob. 19.3.2CPCh. 19.3 - Prob. 19.3.3CPCh. 19.3 - Prob. 19.3.4CPCh. 19.4 - Prob. 19.4.1CPCh. 19.4 - Prob. 19.4.2CPCh. 19.5 - Prob. 19.5.1CP
Ch. 19.5 - Prob. 19.5.2CPCh. 19.6 - What is a raw type? Why is a raw type unsafe? Why...Ch. 19.6 - Prob. 19.6.2CPCh. 19.7 - Prob. 19.7.1CPCh. 19.7 - Prob. 19.7.2CPCh. 19.7 - Prob. 19.7.3CPCh. 19.7 - Prob. 19.7.4CPCh. 19.8 - Prob. 19.8.1CPCh. 19.8 - Prob. 19.8.2CPCh. 19.8 - Prob. 19.8.3CPCh. 19.8 - Prob. 19.8.4CPCh. 19.8 - Prob. 19.8.5CPCh. 19.9 - Prob. 19.9.1CPCh. 19.9 - How are the add, multiple, and zero methods...Ch. 19.9 - How are the add, multiple, and zero methods...Ch. 19.9 - What would be wrong if the printResult method is...Ch. 19 - (Revising Listing 19.1) Revise the GenericStack...Ch. 19 - Prob. 19.2PECh. 19 - (Distinct elements in ArrayList) Write the...Ch. 19 - Prob. 19.4PECh. 19 - (Maximum element in an array) Implement the...Ch. 19 - (Maximum element in a two-dimensional array) Write...Ch. 19 - Prob. 19.7PECh. 19 - (Shuffle ArrayList) Write the following method...Ch. 19 - (Sort ArrayList) Write the following method that...Ch. 19 - (Largest element in an ArrayList) Write the...Ch. 19 - Prob. 19.11PE
Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- (Triangle class) Design a new Triangle class that extends the abstract Geometricobject class. Draw the UML diagram for the classes Triangle and Geometricobject then implement the Triangle class. Write a test program that prompts the user to enter three sides of the triangle, a color, and a Boolean value to indicate whether the triangle is filed. The program should create a Tri- angle object with the se sides, and set the color and filled properties using the input. The program should display the area, perimeter, color, and true or false to indicate whether it is filled or not.arrow_forward(Triangle class) Design a new Triangle class that extends the abstract GeometricObject class. Draw the UML diagram for the classes Triangle and GeometricObject and then implement the Triangle class. Write a test program that prompts the user to enter three sides of the triangle, a colour, and a Boolean value to indicate whether the triangle is filled. The program should create a Triangle object with these sides and set the colour and filled properties using the input. The program should display the area, perimeter, colour, and true or false to indicate whether it is filled or not.arrow_forward(The Rectangle class) Following the example of the Circle class in Section 8.2,design a class named Rectangle to represent a rectangle. The class contains:■ Two double data fields named width and height that specify the width andheight of the rectangle. The default values are 1 for both width and height.■ A no-arg constructor that creates a default rectangle.■ A constructor that creates a rectangle with the specified width and height.■ A method named getArea() that returns the area of this rectangle.■ A method named getPerimeter() that returns the perimeter.Draw the UML diagram for the class and then implement the class. Write a testprogram that creates two Rectangle objects—one with width 4 and height 40and the other with width 3.5 and height 35.9. Display the width, height, area,and perimeter of each rectangle in this order.arrow_forward
- (The Rectangle class) Following the example of the Circle class in Section 8.2,design a class named Rectangle to represent a rectangle. The class contains:■ Two double data fields named width and height that specify the width andheight of the rectangle. The default values are 1 for both width and height.■ A no-arg constructor that creates a default rectangle.■ A constructor that creates a rectangle with the specified width and height.■ A method named getArea() that returns the area of this rectangle.■ A method named getPerimeter() that returns the perimeter.Draw the UML diagram for the class and then implement the class. Write a testprogram that creates two Rectangle objects—one with width 4 and height 40and the other with width 3.5 and height 35.9. Display the width, height, area,and perimeter of each rectangle in this order.arrow_forward(Algebra: quadratic equations) Design a class named QuadraticEquation for a quadratic equation ax² + bx + x = 0. The class contains: 1 The private data fields a, b, and c that represent three coefficients. 1 A constructor for the arguments for a, b, and c. 1 Three get methods for a, b, and c. A method named getDiscriminant() that returns the discriminant, which is b? – 4ac. The methods named getRoot1() and getRoot2() for returning the two roots of the equation using these formulas: -b + Vb? – 4ac -b - Vb? – 4ac and r2 2a 2a These methods are useful only if the discriminant is nonnegative. Let these meth- ods return 0 if the discriminant is negative. Draw the UML diagram for the class, and then implement the class. Write a test program that prompts the user to enter values for a, b, and c and displays the result based on the discriminant. If the discriminant is positive, display the two roots. If the discriminant is 0, display the one root. Otherwise, display "The equation has no…arrow_forwardRewrite the client program to use the Baby class that you have done using ArrayList. You should also have the following function in this new client program: a) Enter details for each baby (name and age) and thus populate the Baby ArrayList b) Calculate and display the average age of all babies in the ArrayList c) Ask the user to enter the name of a baby, and then remove it from the ArrayList d) Allow the user to add new baby information in the ArrayList e) Output the details of each baby from the ArrayList (name and age) Compare this client program using the ArrayList with the client program you have done using array, comment on the differences between the two. Modify your client program in the last question, by adding a sort function such that when that option is selected, it sorts the ArrayList using the baby names in alphabetical order and output the details in the sorted ArrayList to a CSV (sortedbabylist.csv) file. public class Baby { private String name; private int age;…arrow_forward
- (The Rectangle class) Following the example of the Circle class in Section 8.2, design a class named Rectangle to represent a rectangle. The class contains: Two double data fields named width and height that specify the width and height of the rectangle. The default values are 1 for both width and height. I A no-arg constructor that creates a default rectangle. I A constructor that creates a rectangle with the specified width and height. I A method named getArea() that returns the area of this rectangle. A method named getPerimeter () that returns the perimeter. Draw the UML diagram for the class and then implement the class. Write a test program that creates two Rectangle objects-one with width 4 and height 40 and the other with width 3.5 and height 35.9. Display the width, height, area, and perimeter of each rectangle in this order.arrow_forward(Operator Overloads in Templates) Write a simple function template for predicate functionisEqualTo that compares its two arguments of the same type with the equality operator (==) andreturns true if they are equal and false otherwise. Use this function template in a program thatcalls isEqualTo only with a variety of fundamental types. Now write a separate version of the program that calls isEqualTo with a user-defined class type, but does not overload the equality operator.What happens when you attempt to run this program? Now overload the equality operator (withthe operator function) operator==. Now what happens when you attempt to run this program?arrow_forward(The MyDate class) Design a class named MyDate. The class contains: The data fields year, month, and day that represent a date. month is 0-based, i.e., 0 is for January. A no-arg constructor that creates a MyDate object for the current date. A constructor that constructs a MyDate object with a specified elapsed time since midnight, January 1, 1970, in milliseconds. A constructor that constructs a MyDate object with the specified year, month, and day. Three getter methods for the data fields year, month, and day, respectively. A method named setDate(long elapsedTime) that sets a new date for the object using the elapsed time. Draw the UML diagram for the class and then implement the class. Write a test program that creates two MyDate objects (using new MyDate() and new MyDate(34355555133101L)) and displays their year, month, and day. (Hint: The first two constructors will extract the year, month, and day from the elapsed time. For example, if the elapsed time is 561555550000…arrow_forward
- Please Solve the Question in C++ as quickly as you can in 40 minutes. And do the same as asked in the question. Don't use extra things, please. Q1: Start with the safearay class from the ARROVER3 program in Chapter 8 of Object Orient programming by Rober Lafore. Make this class into a template, so the safe array can store any kind of data. Include following member functions in Safe array class. The minimum function finds the minimum value in array. The maximum function find the maximum value in array. The average function find average of all the elements of an array. The total function finds the running total of all elements of an array. In main(), create safe arrays of at least two different types int and double and store some data in them. Then display minimum, maximum, average and total of array elements. Note: use subscript ([]) operator in sasfearay class.arrow_forwarduse javascriptarrow_forward(The MyPoint class) Design a class named MyPoint to represent a point with x- and y-coordinates. The class contains: 1 The data fields x and y that represent the coordinates with getter methods. 1 A no-arg constructor that creates a point (0, 0). I A constructor that constructs a point with specified coordinates. I A method named distance that returns the distance from this point to a specified point of the MyPoint type. I A method named distance that returns the distance from this point to another point with specified x- and y-coordinates. Draw the UML diagram for the class and then implement the class. Write a test program that creates the two points (0, 0) and (10, 30.5) and displays the distance between them.arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning