first commit
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
#BlueJ class context
|
||||
comment0.params=rollOverLimit
|
||||
comment0.target=NumberDisplay(int)
|
||||
comment0.text=\n\ Constructor\ for\ objects\ of\ class\ NumberDisplay.\n\ Set\ the\ limit\ at\ which\ the\ display\ rolls\ over.\n
|
||||
comment1.params=
|
||||
comment1.target=int\ getValue()
|
||||
comment1.text=\n\ Return\ the\ current\ value.\n
|
||||
comment2.params=
|
||||
comment2.target=java.lang.String\ getDisplayValue()
|
||||
comment2.text=\n\ Return\ the\ display\ value\ (that\ is,\ the\ current\ value\ as\ a\ two-digit\n\ String.\ If\ the\ value\ is\ less\ than\ ten,\ it\ will\ be\ padded\ with\ a\ leading\n\ zero).\n
|
||||
comment3.params=replacementValue
|
||||
comment3.target=void\ setValue(int)
|
||||
comment3.text=\n\ Set\ the\ value\ of\ the\ display\ to\ the\ new\ specified\ value.\ If\ the\ new\n\ value\ is\ less\ than\ zero\ or\ over\ the\ limit,\ do\ nothing.\n
|
||||
comment4.params=
|
||||
comment4.target=void\ increment()
|
||||
comment4.text=\n\ Increment\ the\ display\ value\ by\ one,\ rolling\ over\ to\ zero\ if\ the\n\ limit\ is\ reached.\n
|
||||
numComments=5
|
@@ -0,0 +1,70 @@
|
||||
|
||||
/**
|
||||
* The NumberDisplay class represents a digital number display that can hold
|
||||
* values from zero to a given limit. The limit can be specified when creating
|
||||
* the display. The values range from zero (inclusive) to limit-1. If used,
|
||||
* for example, for the seconds on a digital clock, the limit would be 60,
|
||||
* resulting in display values from 0 to 59. When incremented, the display
|
||||
* automatically rolls over to zero when reaching the limit.
|
||||
*
|
||||
* @author Michael Kölling and David J. Barnes
|
||||
* @version 2016.02.29
|
||||
*/
|
||||
public class NumberDisplay
|
||||
{
|
||||
private int limit;
|
||||
private int value;
|
||||
|
||||
/**
|
||||
* Constructor for objects of class NumberDisplay.
|
||||
* Set the limit at which the display rolls over.
|
||||
*/
|
||||
public NumberDisplay(int rollOverLimit)
|
||||
{
|
||||
limit = rollOverLimit;
|
||||
value = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current value.
|
||||
*/
|
||||
public int getValue()
|
||||
{
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the display value (that is, the current value as a two-digit
|
||||
* String. If the value is less than ten, it will be padded with a leading
|
||||
* zero).
|
||||
*/
|
||||
public String getDisplayValue()
|
||||
{
|
||||
if(value < 10) {
|
||||
return "0" + value;
|
||||
}
|
||||
else {
|
||||
return "" + value;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of the display to the new specified value. If the new
|
||||
* value is less than zero or over the limit, do nothing.
|
||||
*/
|
||||
public void setValue(int replacementValue)
|
||||
{
|
||||
if((replacementValue >= 0) && (replacementValue < limit)) {
|
||||
value = replacementValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Increment the display value by one, rolling over to zero if the
|
||||
* limit is reached.
|
||||
*/
|
||||
public void increment()
|
||||
{
|
||||
value = (value + 1) % limit;
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
Project: number-display
|
||||
Authors: Michael Kölling and David J. Barnes
|
||||
|
||||
This project is part of the material for the book
|
||||
|
||||
Objects First with Java - A Practical Introduction using BlueJ
|
||||
Sixth edition
|
||||
David J. Barnes and Michael Kölling
|
||||
Pearson Education, 2016
|
||||
|
||||
It is discussed in chapter 3.
|
||||
|
||||
To use this project, create an instance of class NumberDisplay. Then inspect this
|
||||
instance and leave the inspector window open. With the inspector window open,
|
||||
call the object's methods, such as increment and setValue.
|
@@ -0,0 +1,29 @@
|
||||
#BlueJ package file
|
||||
objectbench.height=153
|
||||
objectbench.width=786
|
||||
package.editor.height=357
|
||||
package.editor.width=678
|
||||
package.editor.x=70
|
||||
package.editor.y=80
|
||||
package.numDependencies=0
|
||||
package.numTargets=1
|
||||
package.showExtends=true
|
||||
package.showUses=true
|
||||
project.charset=UTF-8
|
||||
readme.editor.height=626
|
||||
readme.editor.width=875
|
||||
readme.editor.x=53
|
||||
readme.editor.y=28
|
||||
target1.editor.height=796
|
||||
target1.editor.width=873
|
||||
target1.editor.x=234
|
||||
target1.editor.y=217
|
||||
target1.height=60
|
||||
target1.name=NumberDisplay
|
||||
target1.naviview.expanded=true
|
||||
target1.showInterface=false
|
||||
target1.type=ClassTarget
|
||||
target1.typeParameters=
|
||||
target1.width=110
|
||||
target1.x=210
|
||||
target1.y=100
|
Reference in New Issue
Block a user