Question

Java Project1. The largest positive integer of type int is 2,147,483,647. Another integer type, long, represents integers up to 9,223,372,036,854,775,807. Imagine that you want to represent even larger integers. For example, cryptography uses integers having more than 100 digits. Design and implement a class Huge of very large nonnegative integers. The largest integer should contain at least 30 digits. Use a deque to represent the value of an integer. Provide operations for the class that * Set the value of a nonnegative integer (provide both set methods and constructors) Return the value of a nonnegative integer as a string Read a large nonnegative integer (skip leading zeros, but remember that zero is a valid number) Display a large nonnegative integer (do not display leading zeros, but if the integer is zero, display a single zero) . Add two nonnegative integers to produce the sum as a third integer . Multiply two nonnegative integers to produce the product as a third integer You should handle overflow when reading, adding, or multiplying integers. An integer is too large if it exceeds MAX_SIZE digits where MAX_SIZE is a named constant that you define. Write a test program that demonstrates each method

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Answer:

Dequelnterface java: W implement a package. import java.math.Biglnteger import java.util Scanner Define the interface public

Class Huge import the package. mport java.math. Biginteger import java.util Scanner; Define the class Huge which implements Dfrontlndex-backlndex-1 I Set bi to null. bi-null: Define the parameterizeduor to set hugint as user defined hugelint public Helse birnew Biglnteger(String)hugelnt) Define the method returnNonNegativelnteger to return the hugelnt if it is set otherwisIstoring big integer into hugeint hugelnt-(Ts1 /Set the value setValueOfNonNegativelntegero Define the method displayLargelntDefine the method BigInteger to add multiply big integers. public Biginteger mulHuge bi2) throws Exceptionchecking of null ifthis nul bi2null) return null Call multiply0 method of Biglnteger class Biginteger mul-bi.multiply(bi2.bi;Define the method removeBack to removes and returns the back entry of this deque public T removeBack0 return null: Define theClass TestHugeint l import the package. mport java.math. Biglnteger Define the class TestHugelnt in which main method is beine.printStackTrace0) Wprint first big integer System.out.printin( The first big integer is +bigInt1.returnNonNegativelnteger0)IN TODO Auto-generated catch block e.printStackTrace0) System.out.printin( The addition is: +biAdd) multiplication Biglnteger

Add a comment
Know the answer?
Add Answer to:
Java Project 1. The largest positive integer of type int is 2,147,483,647. Another integer type, long,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 3. (Dynamic Array) In C++, the largest int value is 2147483647. So. an integer larger than this cannot be stored and pr...

    3. (Dynamic Array) In C++, the largest int value is 2147483647. So. an integer larger than this cannot be stored and processed as an integer. Similarly, if the sum or product of two positive integers is greater than 2147483647, the result will be incorrect. One way to store and manipulate large integers is to store each individual digit of the number in an array. Your program must, at least, contain a function to read and store a number into an...

  • C++ pleasr Extra Credit: Large Integer (25 points) In C++, the largest int value is 2147483647....

    C++ pleasr Extra Credit: Large Integer (25 points) In C++, the largest int value is 2147483647. So, an integer larger than this cannot be stored and processed as an integer. Similarly, if the sum or product of two positive integers is greater than 2147483647, the result will be incorrect. One way to store and manipulate large integers is to store each individual digit of the number in an array. Write a program that inputs two positive integers of, at most,...

  • In JAVA 1. Create a class called Rectangle that has integer data members named - length...

    In JAVA 1. Create a class called Rectangle that has integer data members named - length and width. Your class should have a default constructor (no arg constructor) Rectangle() that initializes the two instance variables of the object Rect1. The second overloading constructor should initializes the value of the second object Rect2. The class should have a member function named GetWidth() and GetLength() that display rectangle's length and width. OUTPUT: Rectl width: 5 Rectl length: 10 Enter a width :...

  • DESCRIPTION: The range of integers that can be represented in Java using a primitive data type is...

    DESCRIPTION: The range of integers that can be represented in Java using a primitive data type is only from-263 to 263-1. What if we need to manipulate integer values beyond this range? In this assignment you will write a HugeInteger 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...

  • I only need help with the constructors and add method. Thanks! Background Arbitrary length integers are...

    I only need help with the constructors and add method. Thanks! Background Arbitrary length integers are integers that have no size restriction. Recall that the int type has a range of -2,147,483,648 to 2,147,483,647. The long type runs from -263 to 263 - 1. Sometimes these numbers are not large enough. One example application that may need larger numbers is public-key cryptography where very large integers are used to make decryption hard. A large integer may be represented as a...

  • Programming Project #5 Project Outcomes: Develop a Java program that Uses selection constructs (if, and if...

    Programming Project #5 Project Outcomes: Develop a Java program that Uses selection constructs (if, and if else). Uses the Java iteration constructs (while, do, for). Uses static variables. Ensure integer variables input are within a range that will not cause integer overflow. Uses proper design techniques including reading UML Class Diagrams Background Information: The Unified Modeling Language (UML) provides a useful notation for designing and developing object-oriented software systems. One of the basic components of the UML is a class...

  • the user should be prompted to enter an integer and then your program will produce another...

    the user should be prompted to enter an integer and then your program will produce another integer depending on whether the input was even or odd. The following is an example of what you might see when you run the program; the input you type is shown in green (press Enter at the end of a line), and the output generated by the program is shown in black text. Enter an integer: 1234 Number is even, taking every other digit...

  • In a new file located in the same package as the class Main, create a public...

    In a new file located in the same package as the class Main, create a public Java class to represent a photograph that consists of a linear (not 2D) array of pixels. Each pixel is stored as an integer. The photograph class must have: (a) Two private fields to represent the information stored about the photograph. These are the array of integers and the date the photograph was taken (stored as a String). The values in the array must be...

  • C++ 1st) [Note: This assignment is adapted from programming project #7 in Savitch, Chapter 10, p.616.]...

    C++ 1st) [Note: This assignment is adapted from programming project #7 in Savitch, Chapter 10, p.616.] Write a rational number class. Recall that a rational number is a ratio-nal number, composed of two integers with division indicated. The division is not carried out, it is only indicated, as in 1/2, 2/3, 15/32. You should represent rational numbers using two int values, numerator and denominator. A principle of abstract data type construction is that constructors must be present to create objects...

  • Program Purpose In this program you will demonstrate your knowledge in programming OOP concepts, such as classes, encapsulation, and procedural programming concepts such as lınked lists, dynamic me...

    Program Purpose In this program you will demonstrate your knowledge in programming OOP concepts, such as classes, encapsulation, and procedural programming concepts such as lınked lists, dynamic memory allocation, pointers, recursion, and debugging Mandatory Instructions Develop a C++ object oriented solution to the Towers of Hanoi puzzle. Your solution will involve designing two classes one to represent individual Disk and another to represent the TowersOfHanoi game. TowersOfHanoi class will implement the game with three linked lists representing disks on each...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT