SlideShare a Scribd company logo
do it in eclips and make sure it compile
Goals
1)
Be able to work with individual bits in java
.
2)
Understand the serializable interface.
3)
Understand the comparable interface.
4)
Answer questions about a general-purpose class to be
developed.
5)
Understand the use of a driver program for ‘glass box’
debugging.
6)
Develop a program that can grade true/false te
Description
1)
The first step is to develop a general-purpose class that will be
able to perform operations on strings of bits. The class API
follows:
public class
BitMap
implements Comparable,
Serializable
{ public static final int BITSIZE = 64;
private
long bitString;
public BitMap
() // Three constructors.
public
BitMap
(String s)
throws
IndexOutOfBoundsException,ArithmeticException
public
BitMap
(
boolean
[] bits)
throws
IndexOutOfBoundsException
private
long
bitMask
(
int
b) // Other class methods.
public void
setBit
(
int
b)
public void
clearBit
(
int
b)
public
boolean
checkBit
(
int
b)
public
int
countTrue
()
public void
clearAll()
public void
setAll()
public
int
compareTo
(Object
bm
) //For Comparable.
public
boolean
equals(
BitMap
bm
)
public String
toString()
}
Notes:
a.
The only instance variable that is needed is
bitString
.
b.
Use BITSIZE for the maximum index value of your loops.
The above looks like a lot of methods, but the whole class
requires about a page of code when the methods are filled in.
Some methods can use others instead of duplicating code. For
example, the first constructor can just call the method,
clearAll
(
)
. The method
b
itMask
(
)
can be used by four or five other methods whenever a bit
operation is called for. We'll discuss that in class.
The operations to be performed by each method are briefly
described below:
a)
Constructors
(i) The first constructor just needs to set all bits to
false
(or
zero
). The method
clearAll()
does the same thing.
(ii) The second constructor takes a character string as input.
Each character of the string is either a
t
(for
true
) or
f
(for
false
) value. The bits with a
t
character are to be set on in the bit map; bits with an
f
character should be set off in the bit map. Throw an
ArithmeticException
if the input string has characters other
than ‘t’
, ‘T’, ‘f’, or ‘F’ appear. Throw
IndexOutOfBoundsException
if the string is too long.
(iii) The third constructor works just like the second except the
input is a
boolean
array. The bits corresponding to the array elements that have a
true
value should be set to a value of one;
the elements having a
false
value shoule
be
set to a value of zero.
b)
Primary Methods
The methods,
setBit(int), clearBit(int), and checkBit(int)
respectively set a given bit on, off or check a bits current value.
The method,
countTrue()
returns the total number of bits that are set. It can be used by
the
compareTo()
method. The method
setAll(
)
turns on all the bits;
clearAll
()
clears all bits. Both
setAll
(
)
and
clearAll
()
methods can be written with one instruction.
c)
Comparable interface
The
compareTo()
and
equals()
methods should be provided to conform to the standard way
that java programs compare objects. One
BitMap
object is considered less than another if it contains less
true
bits. In effect, this method of comparison can be used to
determine if one BitMap object has more bits on than another.
The
equals(
)
method can compare whether two
BitMaps
have all of their
on
and
off
bits in the same positions.
d) The
toString(
)
method should return an appropriate string of 't' and 'f' values.
The System.out.print methods use this method.
2)
The next step is to debug the class that was created in the above
step. I provide the program
driver.java
for this purpose; its code is at the bottom of this document.
Don’t modify this program in any way; use it to test your
class.
It contains a menu that has options to test every option. Once
the testing is complete,
BitMap
,
could be used as a general tool for working with bits and could
be used in many programs.
3)
Use notepad to create a file of true/false questions.
4)
Now write a program (
CreateTest.java)
that constructs a
true/false
test. This program reads the file created in step 3 to ask a
series of true false questions and record the resulting answers in
a bit map object. Be sure to use a
fileChooser
to ask the user for the file name. Make sure you catch all
exceptions (programs should never crash).
You can use your TextReader from the previous lab as the
starting point for this program. Better yet, just instantiate a
BufferedReader
and read lines from the text file till you encounter a null line.
Make sure to have at least
25
questions in your test. When the test is completed, the program
should use an
ObjectOutputStream
to write one record (
the BitMap object
) to a sequential binary file. That is why the
BitMap
class must have ‘implements
serializable
’ on its signature line. Name the disk file
ans.bin.
Hopefully, you'll know the answers to your questions so the
answer file will represent a perfect score.
5)
Finally, create a new application (Test.java). You can copy and
paste the program that you just wrote (and save it as
Test.java
), and then modify it appropriately. This program should read
the answer file (using an
ObjectInputStream
) and compare the answers given by someone taking the test to
ans.bin
. Display the score earned by the test taker.
6)
Answer the synthesis questions in an rtf or doc file (answers.rtf
or answers.doc).
Type your name and the lab number on this file and include the
questions with the answers.
7)
Zip your Eclipse project along with the synthesis answers and
email to
[email protected]
.
Driver.java
// Driver program to test the
BitMap
class.
import
java.io.*;
public
class
Driver
{
static
BitMap
bitMap
[];
static
BufferedReader
in =
new
BufferedReader
(
new
InputStreamReader
(System.in));
// Method to start the driver program.
public
static
void
main(String[]
args
)
{
int
bit, map, option;
BitMap
bitMap
=
new
BitMap
();
BitMap
secondMap
;
// Use a menu to test all of the other options.
option
= menu();
while
(option != 10)
{
switch
(option)
{
case
1:
// Set bit.
bit
=
getBit
();
bitMap.setBit
(bit);
System.out.println
(
bitMap
);
break
;
case
2:
// Clear bit.
bit
=
getBit
();
bitMap.clearBit
(bit);
System.out.println
(
bitMap
);
break
;
case
3:
// Check bit.
bit
=
getBit
();
if
(
bitMap.checkBit
(bit))
System.out.println
(
"Bit is set"
);
else
System.out.println
(
"Bit is not set"
);
System.out.println
(
bitMap
);
break
;
case
4:
// Clear all bits.
bitMap.clearAll
(
);
System.out.println
(
bitMap
);
break
;
case
5:
// Set all bits.
bitMap.setAll
(
);
System.out.println
(
bitMap
);
break
;
case
6:
// Count number of true bits.
System.out.println
(
bitMap
);
System.out.println
(
bitMap.countTrue
()
+
" bits are set"
);
break
;
case
7:
// Compare to bit maps.
secondMap
=
getMap
();
System.out.println
(
bitMap
);
System.out.println
(
secondMap
);
System.out.println
(
"
compareTo
= "
+
bitMap.compareTo
(
secondMap
));
break
;
case
8:
// See if maps equal.
secondMap
=
getMap
();
System.out.println
(
bitMap
);
System.out.println
(
secondMap
);
if
(
bitMap.equals
(
secondMap
))
{
System.out.println
(
"Maps equal"
); }
else
{
System.out.println
(
"Maps not equal"
); }
break
;
case
9:
//
toString
.
System.out.println
(
bitMap
);
break
;
default
:
System.out.println
(
"Illegal Option - try again"
);
break
;
}
option = menu();
}
System.out.println
(
"End of Driver for
BitMap
"
);
}
// End main.
// Method to display menu and get selection.
public
static
int
menu()
{
System.out.println
(
"Menu of driver options"
);
System.out.println
(
" 1 =
setBit
"
);
System.out.println
(
" 2 =
cleartBit
"
);
System.out.println
(
" 3 =
checkBit
"
);
System.out.println
(
" 4 =
clearAll
"
);
System.out.println
(
" 5 =
setAll
"
);
System.out.println
(
" 6 =
countTrue
"
);
System.out.println
(
" 7 =
compareTo
"
);
System.out.println
(
" 8 = equals"
);
System.out.println
(
" 9 =
toString
"
);
System.out.println
(
"10 = exit"
);
System.out.print
(
"Enter option: "
);
return
readInt
(1,10);
}
// End menu().
// Method to accept a bit number.
public
static
int
getBit
()
{
int
bit;
System.out.print
(
"Enter bit number: "
);
bit =
readInt
(0,BitMap.BITSIZE-1);
return
bit;
}
// End
getBit
().
// Method to instantiate either a
boolean
or string bit map.
public
static
BitMap
getMap
()
{
boolean
success =
false
;
BitMap
bitMap
=
null
;
do
{
try
{
System.out.println
(
"Enter string of '
t','T','f
', or 'F' "
);
String values =
in.readLine
().
toLowerCase
();
System.out.println
(
"Enter 'b' or 'B' for Boolean map"
);
String type =
in.readLine
().
toLowerCase
();
if
(
type.length
()!=0 &&
type.charAt
(0)==
'b'
)
{
boolean
bools
[] =
new
boolean
[
values.length
()];
for
(
int
i
=0;
i
<
values.length
();
i
++)
{
if
(
Character.toLowerCase
(
values.charAt
(
i
))==
't'
)
bools
[
i
] =
true
;
else
bools
[
i
] =
false
;
bitMap
=
new
BitMap
(
bools
);
} }
else
bitMap
=
new
BitMap
(values);
success =
true
;
}
catch
(Exception e) {
System.out.println
(e); }
}
while
(!success);
return
bitMap
;
}
// End
getMap
().
// Method to get an integer between min and max.
public
static
int
readInt
(
int
min,
int
max)
{ String token;
int
value = 0;
boolean
ok =
false
;
while
(!ok)
{ ok =
true
;
try
{ token =
in.readLine
();
value =
Integer.parseInt
(token);
if
(valuemax) ok =
false
;
}
catch
(Exception exception) {ok =
false
;}
if
(!ok)
{
System.out.print
(
"Illegal input, enter between "
+ min +
" and "
+ max +
": "
);
} }
return
value;
}
// End
readInt
().
}
// End class.

More Related Content

DOCX
Goals1)Be able to work with individual bits in java.2).docx
PPT
Bit manipulation
PDF
Engineering fast indexes (Deepdive)
PDF
Engineering Fast Indexes for Big-Data Applications: Spark Summit East talk by...
PPS
Wrapper class
PDF
26 Jo P Feb 09
PPTX
Programing techniques
PDF
Programming techniques
Goals1)Be able to work with individual bits in java.2).docx
Bit manipulation
Engineering fast indexes (Deepdive)
Engineering Fast Indexes for Big-Data Applications: Spark Summit East talk by...
Wrapper class
26 Jo P Feb 09
Programing techniques
Programming techniques

Similar to do it in eclips and make sure it compile Goals1)Be able to.docx (20)

PDF
Java programs
PDF
Java programming lab manual
PDF
PSI 3 Integration
DOC
H U F F M A N Algorithm
PDF
Week 5
PDF
Week 5
PDF
Java Pitfalls and Good-to-Knows
PDF
java-introduction.pdf
PDF
PDF
10 -bits_and_bytes
DOCX
Exercise1[5points]Create the following classe
PDF
java-language-programação.2-PDF Room.pdf
PDF
Data types and operators and statements
PDF
Data types and operators and statements
PPT
sets and maps
PDF
Introduction to computing Processing and performance.pdf
PPT
Counit2
PDF
01A - Greatest Hits of CS111 Data structure and algorithm
PPTX
Java Hands-On Workshop
PPTX
Collection and framework
Java programs
Java programming lab manual
PSI 3 Integration
H U F F M A N Algorithm
Week 5
Week 5
Java Pitfalls and Good-to-Knows
java-introduction.pdf
10 -bits_and_bytes
Exercise1[5points]Create the following classe
java-language-programação.2-PDF Room.pdf
Data types and operators and statements
Data types and operators and statements
sets and maps
Introduction to computing Processing and performance.pdf
Counit2
01A - Greatest Hits of CS111 Data structure and algorithm
Java Hands-On Workshop
Collection and framework

More from jameywaughj (20)

DOCX
DUE 11.07.14 @1200PMUnderstand PhaseThe Understand phase.docx
DOCX
DUE 11.14.14 @1159PMI believe the purpose of the Innovate phas.docx
DOCX
Due 103120143 paragraph 1 reference  Write a summary of .docx
DOCX
DUE 11.04.14 @1159PMIt is time to launch. The Launch Pad phase.docx
DOCX
Due 11 Mar 2015 1000am ESTStatistic in BusinessWrite a 300-wor.docx
DOCX
DUE 10.31.14 @ 1200PMsearch for and discuss a news article or .docx
DOCX
Due 1.14.15400 words 1 referenceHuman resources pr.docx
DOCX
DUE 10.07.14 @ 1159pmTopics covered1. Explain the import.docx
DOCX
Due 10 Feb 2015 at 12pm EST Map the Supply Chain PaperSelect.docx
DOCX
DUE 09.24.14 @ 1159pmDocument RequirementsMS WordFont size.docx
DOCX
DUE 11.21.14 @ 1159PMA Beta factor represents risk in a financ.docx
DOCX
Draft the next 2- to 3-page section of the paper, due in Week Five.docx
DOCX
Drama ConnectionsThe Greeks established many of the bones of sto.docx
DOCX
Dr. Wesch describes YouTube as something that gives people new ways .docx
DOCX
Dr. Carson defines sexual deviations as A) practices and behavio.docx
DOCX
DQ1 Media technologies have evolved throughout history to include .docx
DOCX
Dream TeamSubmit a 1-2 page paper on the following topicImagine.docx
DOCX
Dq1What do you see as the advantages and disadvantages of using a .docx
DOCX
DQ1Risk IndentificationState the importance of identifying risks.docx
DOCX
Due - June 16, 2015 by NOONPlease see attachment for Week 3 Assi.docx
DUE 11.07.14 @1200PMUnderstand PhaseThe Understand phase.docx
DUE 11.14.14 @1159PMI believe the purpose of the Innovate phas.docx
Due 103120143 paragraph 1 reference  Write a summary of .docx
DUE 11.04.14 @1159PMIt is time to launch. The Launch Pad phase.docx
Due 11 Mar 2015 1000am ESTStatistic in BusinessWrite a 300-wor.docx
DUE 10.31.14 @ 1200PMsearch for and discuss a news article or .docx
Due 1.14.15400 words 1 referenceHuman resources pr.docx
DUE 10.07.14 @ 1159pmTopics covered1. Explain the import.docx
Due 10 Feb 2015 at 12pm EST Map the Supply Chain PaperSelect.docx
DUE 09.24.14 @ 1159pmDocument RequirementsMS WordFont size.docx
DUE 11.21.14 @ 1159PMA Beta factor represents risk in a financ.docx
Draft the next 2- to 3-page section of the paper, due in Week Five.docx
Drama ConnectionsThe Greeks established many of the bones of sto.docx
Dr. Wesch describes YouTube as something that gives people new ways .docx
Dr. Carson defines sexual deviations as A) practices and behavio.docx
DQ1 Media technologies have evolved throughout history to include .docx
Dream TeamSubmit a 1-2 page paper on the following topicImagine.docx
Dq1What do you see as the advantages and disadvantages of using a .docx
DQ1Risk IndentificationState the importance of identifying risks.docx
Due - June 16, 2015 by NOONPlease see attachment for Week 3 Assi.docx

Recently uploaded (20)

PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Insiders guide to clinical Medicine.pdf
PPTX
Cell Types and Its function , kingdom of life
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Anesthesia in Laparoscopic Surgery in India
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
Computing-Curriculum for Schools in Ghana
PDF
Complications of Minimal Access Surgery at WLH
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
Pharma ospi slides which help in ospi learning
PPTX
GDM (1) (1).pptx small presentation for students
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
master seminar digital applications in india
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Insiders guide to clinical Medicine.pdf
Cell Types and Its function , kingdom of life
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Anesthesia in Laparoscopic Surgery in India
Renaissance Architecture: A Journey from Faith to Humanism
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
Computing-Curriculum for Schools in Ghana
Complications of Minimal Access Surgery at WLH
Final Presentation General Medicine 03-08-2024.pptx
Module 4: Burden of Disease Tutorial Slides S2 2025
Abdominal Access Techniques with Prof. Dr. R K Mishra
Pharma ospi slides which help in ospi learning
GDM (1) (1).pptx small presentation for students
102 student loan defaulters named and shamed – Is someone you know on the list?
Supply Chain Operations Speaking Notes -ICLT Program
master seminar digital applications in india

do it in eclips and make sure it compile Goals1)Be able to.docx

  • 1. do it in eclips and make sure it compile Goals 1) Be able to work with individual bits in java . 2) Understand the serializable interface. 3) Understand the comparable interface. 4) Answer questions about a general-purpose class to be developed. 5) Understand the use of a driver program for ‘glass box’ debugging. 6) Develop a program that can grade true/false te Description 1) The first step is to develop a general-purpose class that will be able to perform operations on strings of bits. The class API follows: public class BitMap implements Comparable,
  • 2. Serializable { public static final int BITSIZE = 64; private long bitString; public BitMap () // Three constructors. public BitMap (String s) throws IndexOutOfBoundsException,ArithmeticException public BitMap ( boolean [] bits) throws IndexOutOfBoundsException private long bitMask ( int b) // Other class methods. public void
  • 4. compareTo (Object bm ) //For Comparable. public boolean equals( BitMap bm ) public String toString() } Notes: a. The only instance variable that is needed is bitString . b. Use BITSIZE for the maximum index value of your loops. The above looks like a lot of methods, but the whole class requires about a page of code when the methods are filled in. Some methods can use others instead of duplicating code. For example, the first constructor can just call the method, clearAll ( ) . The method b itMask (
  • 5. ) can be used by four or five other methods whenever a bit operation is called for. We'll discuss that in class. The operations to be performed by each method are briefly described below: a) Constructors (i) The first constructor just needs to set all bits to false (or zero ). The method clearAll() does the same thing. (ii) The second constructor takes a character string as input. Each character of the string is either a t (for true ) or f (for false ) value. The bits with a t character are to be set on in the bit map; bits with an f character should be set off in the bit map. Throw an ArithmeticException if the input string has characters other than ‘t’ , ‘T’, ‘f’, or ‘F’ appear. Throw IndexOutOfBoundsException if the string is too long. (iii) The third constructor works just like the second except the
  • 6. input is a boolean array. The bits corresponding to the array elements that have a true value should be set to a value of one; the elements having a false value shoule be set to a value of zero. b) Primary Methods The methods, setBit(int), clearBit(int), and checkBit(int) respectively set a given bit on, off or check a bits current value. The method, countTrue() returns the total number of bits that are set. It can be used by the compareTo() method. The method setAll( ) turns on all the bits; clearAll () clears all bits. Both setAll ( ) and clearAll () methods can be written with one instruction. c)
  • 7. Comparable interface The compareTo() and equals() methods should be provided to conform to the standard way that java programs compare objects. One BitMap object is considered less than another if it contains less true bits. In effect, this method of comparison can be used to determine if one BitMap object has more bits on than another. The equals( ) method can compare whether two BitMaps have all of their on and off bits in the same positions. d) The toString( ) method should return an appropriate string of 't' and 'f' values. The System.out.print methods use this method. 2) The next step is to debug the class that was created in the above step. I provide the program driver.java for this purpose; its code is at the bottom of this document. Don’t modify this program in any way; use it to test your class. It contains a menu that has options to test every option. Once
  • 8. the testing is complete, BitMap , could be used as a general tool for working with bits and could be used in many programs. 3) Use notepad to create a file of true/false questions. 4) Now write a program ( CreateTest.java) that constructs a true/false test. This program reads the file created in step 3 to ask a series of true false questions and record the resulting answers in a bit map object. Be sure to use a fileChooser to ask the user for the file name. Make sure you catch all exceptions (programs should never crash). You can use your TextReader from the previous lab as the starting point for this program. Better yet, just instantiate a BufferedReader and read lines from the text file till you encounter a null line. Make sure to have at least 25 questions in your test. When the test is completed, the program should use an ObjectOutputStream to write one record ( the BitMap object ) to a sequential binary file. That is why the BitMap class must have ‘implements serializable
  • 9. ’ on its signature line. Name the disk file ans.bin. Hopefully, you'll know the answers to your questions so the answer file will represent a perfect score. 5) Finally, create a new application (Test.java). You can copy and paste the program that you just wrote (and save it as Test.java ), and then modify it appropriately. This program should read the answer file (using an ObjectInputStream ) and compare the answers given by someone taking the test to ans.bin . Display the score earned by the test taker. 6) Answer the synthesis questions in an rtf or doc file (answers.rtf or answers.doc). Type your name and the lab number on this file and include the questions with the answers. 7) Zip your Eclipse project along with the synthesis answers and email to [email protected] . Driver.java // Driver program to test the BitMap class. import java.io.*; public
  • 11. ) { int bit, map, option; BitMap bitMap = new BitMap (); BitMap secondMap ; // Use a menu to test all of the other options. option = menu(); while (option != 10) { switch (option) { case 1: // Set bit. bit
  • 13. 3: // Check bit. bit = getBit (); if ( bitMap.checkBit (bit)) System.out.println ( "Bit is set" ); else System.out.println ( "Bit is not set" ); System.out.println ( bitMap ); break ; case 4: // Clear all bits.
  • 14. bitMap.clearAll ( ); System.out.println ( bitMap ); break ; case 5: // Set all bits. bitMap.setAll ( ); System.out.println ( bitMap ); break ; case 6: // Count number of true bits. System.out.println ( bitMap
  • 15. ); System.out.println ( bitMap.countTrue () + " bits are set" ); break ; case 7: // Compare to bit maps. secondMap = getMap (); System.out.println ( bitMap ); System.out.println ( secondMap ); System.out.println ( "
  • 16. compareTo = " + bitMap.compareTo ( secondMap )); break ; case 8: // See if maps equal. secondMap = getMap (); System.out.println ( bitMap ); System.out.println ( secondMap ); if ( bitMap.equals (
  • 17. secondMap )) { System.out.println ( "Maps equal" ); } else { System.out.println ( "Maps not equal" ); } break ; case 9: // toString . System.out.println ( bitMap ); break ; default : System.out.println
  • 18. ( "Illegal Option - try again" ); break ; } option = menu(); } System.out.println ( "End of Driver for BitMap " ); } // End main. // Method to display menu and get selection. public static int menu() { System.out.println ( "Menu of driver options" ); System.out.println ( " 1 = setBit
  • 19. " ); System.out.println ( " 2 = cleartBit " ); System.out.println ( " 3 = checkBit " ); System.out.println ( " 4 = clearAll " ); System.out.println ( " 5 = setAll " ); System.out.println ( " 6 = countTrue "
  • 20. ); System.out.println ( " 7 = compareTo " ); System.out.println ( " 8 = equals" ); System.out.println ( " 9 = toString " ); System.out.println ( "10 = exit" ); System.out.print ( "Enter option: " ); return readInt (1,10); }
  • 21. // End menu(). // Method to accept a bit number. public static int getBit () { int bit; System.out.print ( "Enter bit number: " ); bit = readInt (0,BitMap.BITSIZE-1); return bit; } // End getBit (). // Method to instantiate either a boolean or string bit map. public
  • 23. (); System.out.println ( "Enter 'b' or 'B' for Boolean map" ); String type = in.readLine (). toLowerCase (); if ( type.length ()!=0 && type.charAt (0)== 'b' ) { boolean bools [] = new boolean [ values.length ()]; for ( int
  • 25. bitMap = new BitMap ( bools ); } } else bitMap = new BitMap (values); success = true ; } catch (Exception e) { System.out.println (e); } } while (!success); return bitMap ;
  • 26. } // End getMap (). // Method to get an integer between min and max. public static int readInt ( int min, int max) { String token; int value = 0; boolean ok = false ; while (!ok) { ok = true ; try
  • 27. { token = in.readLine (); value = Integer.parseInt (token); if (valuemax) ok = false ; } catch (Exception exception) {ok = false ;} if (!ok) { System.out.print ( "Illegal input, enter between " + min + " and " + max + ": " ); } } return value; }