Status: Started
  • Digits.java
Font Size
14
Parentheses autocomplete
Wrap lines
Editor
Theme
Code with blocks by default
Console Font Size
12
Console Theme
Display Server Graphics Screen
Show File Tab Bar
Debug Mode
4 Digits Complete Class (text only)
Digits.java
public class Digits
{
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Output
Docs
Exercise
More
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
This student is viewing this assignment in English. View this page in English?

5 points

This question involves identifying and processing the digits of a non-negative integer. The declaration of the Digits class is shown below. You will write the constructor and one method for the Digits class. 


public class Digits

{

/** The list of digits from the number used to construct this object.

* The digits appear in the list in the same order in which they appear in the original number.

*/

    private ArrayList<Integer> digitList;


/** Constructs a Digits object that represents num.

* Precondition: num >= 0

*/

    public Digits(int num)

{ /* to be implemented in part (a) */ }


/** Returns true if the digits in this Digits object are in strictly increasing order;

. * false otherwise.

*/

    public boolean isStrictlyIncreasing()

{ /* to be implemented in part (b) */ }

}


Part A:


Write the constructor for the Digits class. The constructor initializes and fills digitList with the digits from the non-negative integer num. The elements in digitList must be Integer objects representing single digits, and appear in the same order as the digits in num. Each of the following examples shows the declaration of a Digits object and the contents of digitList as initialized by the constructor.



Complete the Digits constructor. 


Part B:


Write the Digits method isStrictlyIncreasing. The method returns true if the elements of digitList appear in strictly increasing order; otherwise, it returns false. A list is considered strictly increasing if each element after the first is greater than (but not equal to) the preceding element.

The following table shows the results of several calls to isStrictlyIncreasing.



Complete method isStrictlyIncreasing

Reset Code

Slides and Notes

No slides available for this video

About

Java (main)
Java Version 1.8.0_222