Write a new class called InfiniteInt. We can (theoretically) store an infinite integer by linking together...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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(<message of your choice>). . 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(<message of your choice>). 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. 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(<message of your choice>). . 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(<message of your choice>). 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.
Expert Answer:
Answer rating: 100% (QA)
Heres the InfiniteInt class that follows your requirements Its a subclass of a doubly linked list and includes the requested methods import javautilLi... View the full answer
Related Book For
Smith and Roberson Business Law
ISBN: 978-0538473637
15th Edition
Authors: Richard A. Mann, Barry S. Roberts
Posted Date:
Students also viewed these programming questions
-
2. You are a U.S. investor and wish to buy 10,000 shares of Club Mditerrane ("Club Med"). You can buy them on the Paris Bourse or on SEAQ International in London. You ask the brokers to quote you net...
-
Planning is one of the most important management functions in any business. A front office managers first step in planning should involve determine the departments goals. Planning also includes...
-
Two colonies of animals predate on each other. On average, each week, each member of a colony A kills 0.2 members of colony B, and each member of colony B kills 0.1 members of colony A. You can...
-
The doctrine of intention to create legal relations has now become a challenge towards the doctrine of consideration, which has been riddled with so many criticisms and as such the former doctrine...
-
Using weighted average Delay a mail-order firm processes 4,500 checks per month. Of these, 60 percent are for $50 and 40 percent are for $70. The $50 checks are delayed two days on average; the $70...
-
The shareholders' equity accounts of Blue Bay Logistics Ltd. on April 1, 2013, the beginning of the fiscal year, are as follows: $6 preferred shares (20,000 issued)...............$1,800,000 Common...
-
The stress-strain relation of the Newtonian fluid is: (a) Linear (b) Parabolic (c) Hyperbolic (d) None of these
-
A bank is thinking of using economic value added to identify services that require improvement or elimination. What problems may the bank have in computing the economic value added of any of the...
-
What is the profit under the "best case scenario? According to the scenario manager (output), what is the profit under the "most likely" scenario? According to the one variable DATA TABLE, what is...
-
A concrete corporation had cost of goods sold of $1,550,000 for the third quarter. The beginning inventory at cost was $155,000, and the ending inventory at cost amounted to $180,900. The inventory...
-
The shareholders' equity of HUE Corporation on December 31 of the current year is shown below. Dividends are in arrears for two years. 6% Preference Share Capital, 100 par, 10,000 authorized, issued...
-
5. In the network of five nodes shown below, a one-on-one secure communication has to be established between every pair of nodes. That is, A and B have to securely communicate with each other; B and...
-
What information do you gain when you attend an annual conference of either the Mississippi Association of School Administrators, the Mississippi Association of High School Principals, the...
-
Q3) A grinding machine abrasive wheel has mass of 40 kg rotates at 2000 r.p.m. There is a sudden power outage. After 80 seconds later the wheel speed falls to 1200 r.p.m. The frictional resistive...
-
The chief accountant was hired by the CEO three years ago and they are close friends. The chief accountant keeps the CEO updated about the companys financial progress and discusses major accounting...
-
Here is selected financial statement data regarding a company's balance sheet. Dec. 31, 2018 Dec. 31, 2017 Assets Investments, long-term $ 14,000,000 $ 10,000,000 Liabilities and Stockholders' Equity...
-
(2) Given a sample space 2 and a probability measure P, two events A C and BCN are said to be independent if P(AB) = P(A)P(B). Assume that the events E1, E2 are independent. a) Prove that the events...
-
The age-old saying for investing is "buy low and sell high," but this is easier said than done. Investors who panic about falling prices sell their investments, which in turn lowers the price and...
-
Technical Textile agreed by written contract to manufacture and sell 20,000 pounds of yarn to Jagger Brothers at a price of $2.15 per pound. After Technical had manufactured, delivered, and been paid...
-
Elizabeth Tilleraas received three student loans totaling $3,500 under the Federal Insured Student Loan Program (FISLP) of the Higher Education Act. These loans were secured by three promissory notes...
-
Discuss intestate succession and the administration of decedents estates.
-
Futures contracts are standardized contracts for the delivery of a specified quantity of a commodity or financial instrument on a prearranged future date, at an agreed- upon price. They are a bet on...
-
Derivatives transfer risk from one person or firm to another. They can be used in any combination to unbundle risks and resell them.
-
Derivatives allow firms to arbitrarily divide up and rename risks and future payments, rendering their actual names irrelevant.
Study smarter with the SolutionInn App