CSE114: Introduction to Object Oriented Programming Spring 2020 Homework3: Due Date: Homework3 is due by 11:59 PM on Wednesday, April 22, 2020. Submit your work (the .java source code files ONLY, not...

none


CSE114: Introduction to Object Oriented Programming Spring 2020 Homework3: Due Date: Homework3 is due by 11:59 PM on Wednesday, April 22, 2020. Submit your work (the .java source code files ONLY, not the compiled .class files!) through the “Homework3” link on Blackboard. You may submit an unlimited number of times; we will only grade the last/latest submission attempt, but be sure to attach all of your files to each submission attempt. Be sure to include your name and Stony Brook ID number in a comment at the beginning of each file that you submit. Submission Instructions: Please follow the following submission instructions: 1. Name your java classes as: a. Complex for problem 1. b. Rational for problem 2. c. Location for problem 3. 2. Name your java source files as: a. Complex.java for problem 1. b. Rational.java for problem 2. c. Location.java for problem 3 3. Compress all the three source files (i.e., Complex.java, Rational.java and Location.java) into a zipped file named Homework3_yourSBU-ID.zip and submit that to the Homework3 link on Blackboard. As an example if your SBU-ID is 1000903096 then your zipped file should be Homework3_1000903096.zip. Instructions: This assignment is worth 40 points (10 + 15 + 15). 1. Create a class called Complex for performing arithmetic with complex numbers. Complex numbers have the form ???????? + ????????????? ∗ ? where ? is √−1 Write a program to test your class. Use double variable to represent the private data of the class. Provide a constructor that enables an object of this class to be initialized when it’s declared. Provide a no-argument constructor with default values in case no initializers are provided. Provide public methods that perform the following operations: a) Add two Complex numbers: The real parts are added together and the imaginary parts are added together. b) Subtract two Complex numbers: The real part of the right operand is subtracted from the real part of the left operand, and the imaginary part of the right operand is subtracted from the imaginary part of the left operand. c) Print Complex numbers in the form (?, ?) where ? the real part and ? is the imaginary part. CSE114: Introduction to Object Oriented Programming Spring 2020 [10] Here is a sample run: Enter real part of the first complex number: 3 Enter imaginary part of the first complex number: 6 Enter real part of the second complex number: 2 Enter imaginary part of the second complex number: 7 First complex number is: (3.0, 6.0) Second complex number is: (2.0, 7.0) Addition of the complex numbers is: (5.0, 13.0) Subtraction of the complex numbers is: (1.0, -1.0) 2. Create a class called Rational for performing arithmetic with fractions. Write a program to test your class. Use integer variables to represent the private instance variables of the class - the numerator and the denominator. Provide a constructor that enables an object of this class to be initialized when it’s declared. The constructor should store the fraction in reduced form. The fraction 2/4 is equivalent to 1/2 and would be stored in the object as 1 in the numerator and 2 in the denominator. Provide a no-argument constructor with default values in case no initializers are provided. Provide public methods that perform each of the following operations: a) Add two Rational numbers: The result of the addition should be stored in reduced form. b) Subtract two Rational numbers: The result of subtraction should be stored in reduced form. c) Multiply two Rational numbers: The result of the multiplication should be stored in reduced form. d) Divide two Rational numbers: The result of the division should be stored in reduced form. e) Return a String representation of Rational number in the form ?/?, where ? is the numerator and ? is the denominator. Here is a sample run: Enter numerator for the first rational number: 4 Enter a non-zero denominator for the first rational number: 6 Enter numerator for the second rational number: 1 Enter a non-zero denominator for the second rational number: 4 First rational number is: 2/3 Second rational number is: 1/4 Addition of the rational numbers is: 11/12 Subtraction of the rational numbers is: 5/12 Multiplication of the rational numbers is: 1/6 Division of the rational numbers is: 8/3 [15] CSE114: Introduction to Object Oriented Programming Spring 2020 3. Implement the following method to sort (in ascending order) the rows in a two-dimensional array. A new array is returned and the original array is intact. public static double[][] sortRows(double[][] m) Write a test program that prompts the user to enter a 3 × 3 matrix of double values and displays a new row-sorted matrix. Here is a sample run: [15] Enter a 3-by-3 matrix row by row: 0.15 0.875 0.375 0.55 0.005 0.225 0.30 0.12 0.4 The row-sorted array is: 0.15 0.375 0.875 0.005 0.225 0.55 0.12 0.30 0.4 [Note: Please implement your own sorting algorithm. You can implement Bubble sort.]
Apr 15, 2021
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here