Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Could you help me with the code Thank you SeMaster University Dept. Electrical and Comp. Engineering COE 2S14 - Term II (Winter) 2020 LABS 1.2

Could you help me with the code Thank you image text in transcribed
image text in transcribed
image text in transcribed
image text in transcribed
SeMaster University Dept. Electrical and Comp. Engineering COE 2S14 - Term II (Winter) 2020 LABS 1.2 - OPERATIONS WITH HUGE INTEGERS Assessment: 8% of the total course mark. INSTRUCTIONS: This assignment will span Labs 1 and 2. . By the end of the Lab 1 session you must demonstrate to your TA the following parts: (i) the constructors of Huge Integer class and (ii) the addition operation for positive integers. The entire solution mast be demonstrated by the end of the Lab 2 son The electronic submission on Avenue to Learn of all java source code must to be done by 5:20 pm the day of your lab session. Specifically, you have to submit the java code for your Huge Integer class, for the test class and for any other classes you may need in your implementation for both labs 1 and 2. The code for each class must be submitted in a separate TEXT file. The report in PDF) must be submitted by 11:59 pm on February 10, 2020 A bonus of 2% of the course mark will be awarded if the asymptotic time complexity of your implementation of the multiplication of two integers of at most digits is on") (ie, subquadratic). A description of the algorithm and an evaluation of the running time are additionally needed for the bonus to be awarded. DESCRIPTION: The range of integers that can be represented in Java using a primitive data type is only from -26 to 263-1. What if we need to manipulate integer values beyond this range? In this assignment you will write a Huge Integer class which is able to represent arbitrar ily large integer numbers. This class must implement arithmetic operations on integers such as addition, subtraction, multiplication, division and comparison. You have to implement this class without using Java predefined classes, unless specified otherwise Additionally, you have to measure experimentally the running times of the operations implemented in your Huge Integer dass and compare them with the measured running times of the corresponding operations provided by java.math. BigInteger class SPECIFICATIONS: The class Huge Integer must contain at least the following methods 1) public Huge Integer add(Huge Integer h): Returns a new Huge Integer repre senting the sum of this Huge Integer and h 2) public Huge Integer subtract (Huge Integer h): Returns a new Huge Integer representing the difference between this Huge Integer and 1 of 4 MeMaster University Dept. Electrical and Comp. Engineering COE 2514 - Teem II (Winter 2020 3) public Huge Integer multiply(Huge Integer h): Returns a new Huge Integer representing the product between this Huge Integer and h 4) public int compareTo(Huge Integer h): Returns-1 if this Huge Integer is less thanh, 1 if this HugeInteger is larger thanh, and if this HageInteger isega to h 5) public String toString(): Returns a string representing the sequence of digits corresponding to the decimal representation of this Huge Integer The class HugeInteger must contain at least the following constructors 1) public Huge Integer (String val) creates a Huge Integer from the decimal String representation val. The string contains an optional minus sign at the beginning followed by one or more decimal digits. No other characters are allowed in the string 2) public Huge Integer (int n) creates a random Huge Integer of n digits, the first digit being different from 0; n must be larger or equal to 1. Each constructor must throw an exception if the argument passed to the constructor does not comply to the specifications. In your solution, you may use Java API methods for string manipulation and for pseudo-random number generation THEORY AND EXPERIMENT: Theory You have to compute the amount of memory (in bytes) required to store an integer of n decimal digits by using your Huge Integer class For each of the operations on huge integers (ie, comparison, addition, subtraction, mul tiplication, division) you are required to compute a big-Theta estimate of the worst-case and of the average-case running times and of the amount of extra memory allocated dur ing the execution, as a function of the number of digits n in the decimal representation. Extra memory refers to the memory needed during the method execution apart from the memory used to store the input numbers and the result. Experiment You are also required to measure the running time of each of the operations i.e., com parison, addition, subtraction, multiplication and division) using your implementation of the Huge Integer class as well as using the implementation provided by the Java platform as the java.math. BigInteger class. Write a program Huge IntTiming.java to estimate the running time of each operation. For fixed this program should instan tiate random integers of size nie, of n decimal digits) and should then run each of the operations on the integers measuring the amount of time required to perform each op eration. To measure the running time the System.current TimeMillis() method can be used, which returns the current time in milliseconds since GMT midnight January 1, 1970. In order to have reasonable accuracy in the measurement, you should run each operation many times on a given pair of integers. Also you should run the measurements on at least 100 different pairs of random integers. For example, to measure the running time of the addition operation in class Huge Integer you may use the following code: 2 of 4 McMaster University Dept. Electrical and Comp. Engineering COE 2S14 - Term II (Winter) 2020 Huge Integer hugel, huge2, huge3; long startTize, endTime; double runTime 0.0; for (int numints ; nunInts

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

More Books

Students also viewed these Databases questions

Question

Verify the result given for var(n + 1 / n Yn) in Example 10.6.

Answered: 1 week ago

Question

b. Why were these values considered important?

Answered: 1 week ago