first commit

This commit is contained in:
Boris
2024-01-15 20:14:10 +00:00
commit 8c81ee28b7
3106 changed files with 474415 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
#BlueJ class context
comment0.params=
comment0.target=ClockDisplay()
comment0.text=\n\ Constructor\ for\ ClockDisplay\ objects.\ This\ constructor\ \n\ creates\ a\ new\ clock\ set\ at\ 00\:00.\n
comment1.params=hour\ minute
comment1.target=ClockDisplay(int,\ int)
comment1.text=\n\ Constructor\ for\ ClockDisplay\ objects.\ This\ constructor\n\ creates\ a\ new\ clock\ set\ at\ the\ time\ specified\ by\ the\ \n\ parameters.\n
comment2.params=
comment2.target=void\ timeTick()
comment2.text=\n\ This\ method\ should\ get\ called\ once\ every\ minute\ -\ it\ makes\n\ the\ clock\ display\ go\ one\ minute\ forward.\n
comment3.params=hour\ minute
comment3.target=void\ setTime(int,\ int)
comment3.text=\n\ Set\ the\ time\ of\ the\ display\ to\ the\ specified\ hour\ and\n\ minute.\n
comment4.params=
comment4.target=java.lang.String\ getTime()
comment4.text=\n\ Return\ the\ current\ time\ of\ this\ display\ in\ the\ format\ HH\:MM.\n
comment5.params=
comment5.target=void\ updateDisplay()
comment5.text=\n\ Update\ the\ internal\ string\ that\ represents\ the\ display.\n
numComments=6

View File

@@ -0,0 +1,84 @@
/**
* The ClockDisplay class implements a digital clock display for a
* European-style 24 hour clock. The clock shows hours and minutes. The
* range of the clock is 00:00 (midnight) to 23:59 (one minute before
* midnight).
*
* The clock display receives "ticks" (via the timeTick method) every minute
* and reacts by incrementing the display. This is done in the usual clock
* fashion: the hour increments when the minutes roll over to zero.
*
* @author Michael Kölling and David J. Barnes
* @version 2016.02.29
*/
public class ClockDisplay
{
private NumberDisplay hours;
private NumberDisplay minutes;
private String displayString; // simulates the actual display
/**
* Constructor for ClockDisplay objects. This constructor
* creates a new clock set at 00:00.
*/
public ClockDisplay()
{
hours = new NumberDisplay(24);
minutes = new NumberDisplay(60);
updateDisplay();
}
/**
* Constructor for ClockDisplay objects. This constructor
* creates a new clock set at the time specified by the
* parameters.
*/
public ClockDisplay(int hour, int minute)
{
hours = new NumberDisplay(24);
minutes = new NumberDisplay(60);
setTime(hour, minute);
}
/**
* This method should get called once every minute - it makes
* the clock display go one minute forward.
*/
public void timeTick()
{
minutes.increment();
if(minutes.getValue() == 0) { // it just rolled over!
hours.increment();
}
updateDisplay();
}
/**
* Set the time of the display to the specified hour and
* minute.
*/
public void setTime(int hour, int minute)
{
hours.setValue(hour);
minutes.setValue(minute);
updateDisplay();
}
/**
* Return the current time of this display in the format HH:MM.
*/
public String getTime()
{
return displayString;
}
/**
* Update the internal string that represents the display.
*/
private void updateDisplay()
{
displayString = hours.getDisplayValue() + ":" +
minutes.getDisplayValue();
}
}

View File

@@ -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

View File

@@ -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;
}
}

View File

@@ -0,0 +1,26 @@
Project: clock-display
Authors: David Barnes and Michael Kölling
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 ClockDisplay. Then inspect this
instance and leave the object inspector window open. With the inspector window open,
call the object's methods, such as timeTick and setTime. Watch the
"displayString" in the inspector.
The displayString field simulates the actual clock display device. Were this
program running in a real clock, it would change the real, physical display
hardware instead of this string. The timeTick method would be triggered once
every minute by some timer hardware.
Everything else could be pretty much the same.
Note: This project does not implement adequate handling of errors.

View File

@@ -0,0 +1,45 @@
#BlueJ package file
dependency1.from=ClockDisplay
dependency1.to=NumberDisplay
dependency1.type=UsesDependency
objectbench.height=124
objectbench.width=774
package.editor.height=371
package.editor.width=666
package.editor.x=70
package.editor.y=80
package.numDependencies=1
package.numTargets=2
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=745
target1.editor.width=845
target1.editor.x=81
target1.editor.y=119
target1.height=60
target1.name=ClockDisplay
target1.naviview.expanded=true
target1.showInterface=false
target1.type=ClassTarget
target1.typeParameters=
target1.width=110
target1.x=150
target1.y=100
target2.editor.height=792
target2.editor.width=873
target2.editor.x=97
target2.editor.y=188
target2.height=60
target2.name=NumberDisplay
target2.naviview.expanded=true
target2.showInterface=false
target2.type=ClassTarget
target2.typeParameters=
target2.width=110
target2.x=290
target2.y=180