Always learning Java, currently using Eclipse on Fedora.
Linux user#: 501795
ed spithaler wrote:I have a programming project that is due very soon, but I am stuck on the requirements. I am able to figure out how to reverse 5 digits with no problem, but our instructor is including char and doubles as well and that's where I get confused. I have asked for further clarification, but I don't receive clear answers. There is also a reset function that I have no idea how to construct. I have included the requirements and my partially completed program. Thanks to anyone that help me in advance.
You are to write a program that reads in an integer and breaks it into a sequence of individual digits in reverse order.
For example, if the input is 16843, the result would be the sequence of values:
3
4
8
6
1
If the input is ‘A’, the result would be:
5
6
You may NOT assume the user input is positive; use Math.abs to guarantee a positive representation.
1) Write a class called DigitExtractor that performs the necessary operation specified above. It should
minimally contain two instances variables: (1) the original integer value itself and (2) a working variable to
help with place holding (I suggest a positive representation of the original integer value that you can modify as
needed).
2) The class should have the following methods:
• A default constructor that initializes all instance fields.
• A parameterized constructor that takes an input int.
• A parameterized constructor that takes an input double. Type-casting will be required to convert to
an integer.
• A parameterized constructor that takes an input char. Type-casting will be required to convert to an
integer.
• Accessor method for the integer.
• Mutator method for the integer. It the mutator is called, the state of the class should be reset.
• A nextDigit method that will return the integer value of the next digit extracted (as described
above). If you are at the end of the number, 0 should be returned.
• A reset method that will reset the object back to its original state so that nextDigit begins again
at the ones place.
3) Implement a driver program called DigitPrinter to test your DigitExtractor class; thoroughly test
all methods.