Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a new class called InfiniteInt. We can (theoretically) store an infinite integer by linking together nodes that hold actual complete integers. For this

Write a new class called InfiniteInt. We can (theoretically) store an  

student submitted image, transcription available below

student submitted image, transcription available below

student submitted image, transcription available below  
 
 

Write a new class called InfiniteInt. We can (theoretically) store an "infinite" integer by linking together nodes that hold actual complete integers. For this program, just store 3 digits in each node (concept is the same, but we won't have to generate hundreds of digits to test it). For example, the integer 487021639 will be stored like this: tail Joob 021 639 head 487 As you can see, it uses a doubly linked list; therefore, make your Infinitelnt class a subclass of DLL ist and define using Generics it so it holds Integers. All of the data (head and tail) are inherited from the superclass. The other methods are also inherited, but you will need to implement the following methods: A constructor that receives a String as an argument and builds the linked list. If an Infinitelnt is created as follows Infinitelnt myList-new InfiniteInt("487021639"); then the list should be built as shown above. This constructor should also check for illegal Strings (containing a non-digit). If encountered, throw an Illegal ArgumentException( ). . as follows InfiniteInt myList = new InfiniteInt("487021639"); then the list should be built as shown above. This constructor should also check for illegal Strings (containing a non-digit). If encountered, throw an Illegal ArgumentException( ). Note that you can build the list by using the methods already available from the superclass. A constructor that takes no arguments and builds a linked list with that contains a value of 0 A toString() method that will override the one in the superclass. Your toString() method should return the String representation of the integer with no spaces between the digits. It should also have commas inserted for readability (our example integer should be represented as "487,021,639"). Note that the following InfiniteInt should print as 600,004. head. 600 tail A static add method which will receive 2 InfiniteInts as arguments, add them up, and return a new InfiniteInt with the total in it. If you think about this and try a few examples on paper, you will see how to do it-you must traverse each number backwards (using the prev link in the doubly linked list) and add each digit, carrying to the next place when necessary. Make sure that you carry correctly and handle the case when one list is longer than the other. This code should work in a driver program: InfiniteInt int1 = new InfiniteInt("646746734"); InfiniteInt int2 = new InfiniteInt("543534"); InfiniteInt int3; int3 Infinitelnt.add(int1, int2): System.out.println(int3); //should print 647,290,268 Notice that the add method will create and return an entirely new InfiniteInt. So in the code, it will call Infinitelnt's default constructor, however, that will put a 0 on the new instance. You will have to take off the 0 manually-otherwise you will be stuck with an extra 0 at the end. A compare To(Object o) that will implement the Comparable interface (please actually put "implements Comparable in the class definition). So compare To will return 1 if the InfiniteInt is greater than what is passed in. -1 if the InfiniteInt is less than what is passed in, and 0 if the InfiniteInt is the same as what is passed in. Refer to the java website for specifications on Comparable and notice that it throws a new Class CastException if what is passed in is not an InfiniteInt (we also checked the class type in the equals method). This code should work in a driver program: InfiniteInt int1= new InfiniteInt("24"); Infinite Int int2= new InfiniteInt("6"); Infinitelnt int3-new InfiniteInt("24"); Integer int4 new Integer(24): System.out.println(intl.compareTo(int2)); System.out.println(int2.compareTo(int1)); System.out.println(intl.compareTo(int1)); System.out.println(int1.compareTo(int3)); System.out.println(intl.compareTo(int4)); //should print 1 //should print -1 //should print 0 //should print 0 //throw a new instance of ClassCastException A reverse toString() method that will also remove all commas from the String. It should take a number such as 123,456 and return 654321. Name the method revAndRemoveToString() A replace CommasWithHyphens() method that replaces the comments generated by the toString() with hyphens and returns the String. Comments and formatting: Please use the Java conventions for variable names, indenting, and formatting. Each class should have an opening comment which briefly describes the class and includes your name and class on a separate line. Each method should have a short opening comment which describes it. "Sections" of code or parts that are tricky should have comments. See programs from the book for examples (although I prefer that opening and closing "squigglies" be indented the same). Please submit: your InfiniteInt.java file. // Disclaimer: // The given assignment description, project files, code files and/or solution files // should not be made available in a public form via methods such as online hosting // in code repositories, educational resource hosting websites, etc. such as Course // Hero and/or Chegg. Tracking information is embedded into the assignment files and // any person found to be distributing files may be prosecuted. This includes // notification to the college, any discipline it warrants and legal action if // it is warranted.

Step by Step Solution

3.54 Rating (161 Votes )

There are 3 Steps involved in it

Step: 1

Heres the InfiniteInt class that follows your requirements Its a subclass of a doubly linked list and includes the requested methods import javautilLi... 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

Smith and Roberson Business Law

Authors: Richard A. Mann, Barry S. Roberts

15th Edition

1285141903, 1285141903, 9781285141909, 978-0538473637

More Books

Students also viewed these Programming questions

Question

Describe the equity method of accounting.

Answered: 1 week ago

Question

How do you think this problem should be treated?

Answered: 1 week ago

Question

When should you avoid using exhaust brake select all that apply

Answered: 1 week ago

Question

Refer to Exercise 5. Compute a 95% t CI for .

Answered: 1 week ago