SlideShare a Scribd company logo
1 of 31
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 tests.
Synthesis Questions
1.
Why is it a good idea to test a general class with a driver
program before trying to use it?
2.
What is the difference between black box and glass box
debugging?
3.
In pseudo-code, describe
CreateTest.java.
4.
In pseudo code, describe the driver program that is provided
below.
5.
If x = 37, y=23, z=-110, r=-32 answer the following questions.
Assume that we are working with bytes. To answer these
questions, you will need to convert from decimal to binary.
Remember that
System.out.println
DOES NOT print binary values. You will need to convert your
results to decimal. Of course you can verify your results by
computer. Remember that there will be questions like this on
the quiz, so try them yourself first.
a.
System.out.println
(
x&y
);
b.
System.out.println
(
x^y
);
c.
System.out.println
(~
x|y
);
d.
System.out.println
(~x>>2);
e.
System.out.println
((byte)(z<<(~r>>4)));
f.
System.out.println
((byte)(x + (x<<1) + (x<<2) + (x<<3)));
g.
System.out.println
(y>>>3);
h.
System.out.println
(
x&y|z^r
);
i.
System.out.println
(~x + x);
j.
System.out.println
(x|(3<<4));
6.
In
about
a sentence, give a reasonable example of when the following
operators would be useful when working with strings of bits.
a.
or operation (|):
b.
and operation (&):
c.
exclusive or operation (^):
d.
left shift operation: (<<):
7.
Suppose we need to create a multiple-choice exam, where each
question has four possible choices. Briefly describe (in a few
sentences) how we could create a new class that uses
inheritance that would allow this. Giving class API and a brief
description of the needed methods would also suffice.
8.
Suppose we needed to modify the
BitMap
class to handle a bit stream of up to
16384
bits. Briefly describe the changes necessary to handle this
refinement. Can you think of a way that the maximum number
of bits to be handled is completely flexible?
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

Similar to Goals1)Be able to work with individual bits in java.2).docx

import java.util.Scanner;Henry Cutler ID 1234 7202.docx
import java.util.Scanner;Henry Cutler ID 1234  7202.docximport java.util.Scanner;Henry Cutler ID 1234  7202.docx
import java.util.Scanner;Henry Cutler ID 1234 7202.docxwilcockiris
 
AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...
AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...
AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...acijjournal
 
CIS 407 STUDY Inspiring Innovation--cis407study.com
CIS 407 STUDY Inspiring Innovation--cis407study.comCIS 407 STUDY Inspiring Innovation--cis407study.com
CIS 407 STUDY Inspiring Innovation--cis407study.comKeatonJennings91
 
SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)Amr E. Mohamed
 
Article link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docxArticle link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docxfredharris32
 
Lab7: More Arrays, Strings, Vectors, and Pointers
Lab7: More Arrays, Strings, Vectors, and PointersLab7: More Arrays, Strings, Vectors, and Pointers
Lab7: More Arrays, Strings, Vectors, and Pointersenidcruz
 
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxmaxinesmith73660
 
Name _______________________________ Class time __________.docx
Name _______________________________    Class time __________.docxName _______________________________    Class time __________.docx
Name _______________________________ Class time __________.docxrosemarybdodson23141
 
BTE 320-498 Summer 2017 Take Home Exam (200 poi.docx
BTE 320-498 Summer 2017 Take Home Exam (200 poi.docxBTE 320-498 Summer 2017 Take Home Exam (200 poi.docx
BTE 320-498 Summer 2017 Take Home Exam (200 poi.docxAASTHA76
 
Introduction to Intermediate Java
Introduction to Intermediate JavaIntroduction to Intermediate Java
Introduction to Intermediate JavaPhilip Johnson
 
Prueba de conociemientos Fullsctack NET v2.docx
Prueba de conociemientos  Fullsctack NET v2.docxPrueba de conociemientos  Fullsctack NET v2.docx
Prueba de conociemientos Fullsctack NET v2.docxjairatuesta
 
Optimization in the world of 64-bit errors
Optimization  in the world of 64-bit errorsOptimization  in the world of 64-bit errors
Optimization in the world of 64-bit errorsPVS-Studio
 
(3) cpp abstractions more_on_user_defined_types_exercises
(3) cpp abstractions more_on_user_defined_types_exercises(3) cpp abstractions more_on_user_defined_types_exercises
(3) cpp abstractions more_on_user_defined_types_exercisesNico Ludwig
 
Mockito with a hint of PowerMock
Mockito with a hint of PowerMockMockito with a hint of PowerMock
Mockito with a hint of PowerMockYing Zhang
 
Python for Physical Science.pdf
Python for Physical Science.pdfPython for Physical Science.pdf
Python for Physical Science.pdfMarilouANDERSON
 

Similar to Goals1)Be able to work with individual bits in java.2).docx (20)

import java.util.Scanner;Henry Cutler ID 1234 7202.docx
import java.util.Scanner;Henry Cutler ID 1234  7202.docximport java.util.Scanner;Henry Cutler ID 1234  7202.docx
import java.util.Scanner;Henry Cutler ID 1234 7202.docx
 
AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...
AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...
AUTOCODECOVERGEN: PROTOTYPE OF DATA DRIVEN UNIT TEST GENRATION TOOL THAT GUAR...
 
Ecet 370 week 1 lab
Ecet 370 week 1 labEcet 370 week 1 lab
Ecet 370 week 1 lab
 
CIS 407 STUDY Inspiring Innovation--cis407study.com
CIS 407 STUDY Inspiring Innovation--cis407study.comCIS 407 STUDY Inspiring Innovation--cis407study.com
CIS 407 STUDY Inspiring Innovation--cis407study.com
 
SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)SE2018_Lec 20_ Test-Driven Development (TDD)
SE2018_Lec 20_ Test-Driven Development (TDD)
 
Article link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docxArticle link httpiveybusinessjournal.compublicationmanaging-.docx
Article link httpiveybusinessjournal.compublicationmanaging-.docx
 
Lab7: More Arrays, Strings, Vectors, and Pointers
Lab7: More Arrays, Strings, Vectors, and PointersLab7: More Arrays, Strings, Vectors, and Pointers
Lab7: More Arrays, Strings, Vectors, and Pointers
 
Java execise
Java execiseJava execise
Java execise
 
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
 
Name _______________________________ Class time __________.docx
Name _______________________________    Class time __________.docxName _______________________________    Class time __________.docx
Name _______________________________ Class time __________.docx
 
CORE JAVA
CORE JAVACORE JAVA
CORE JAVA
 
BTE 320-498 Summer 2017 Take Home Exam (200 poi.docx
BTE 320-498 Summer 2017 Take Home Exam (200 poi.docxBTE 320-498 Summer 2017 Take Home Exam (200 poi.docx
BTE 320-498 Summer 2017 Take Home Exam (200 poi.docx
 
Introduction to Intermediate Java
Introduction to Intermediate JavaIntroduction to Intermediate Java
Introduction to Intermediate Java
 
Prueba de conociemientos Fullsctack NET v2.docx
Prueba de conociemientos  Fullsctack NET v2.docxPrueba de conociemientos  Fullsctack NET v2.docx
Prueba de conociemientos Fullsctack NET v2.docx
 
Unit testing - A&BP CC
Unit testing - A&BP CCUnit testing - A&BP CC
Unit testing - A&BP CC
 
Optimization in the world of 64-bit errors
Optimization  in the world of 64-bit errorsOptimization  in the world of 64-bit errors
Optimization in the world of 64-bit errors
 
CORE JAVA
CORE JAVACORE JAVA
CORE JAVA
 
(3) cpp abstractions more_on_user_defined_types_exercises
(3) cpp abstractions more_on_user_defined_types_exercises(3) cpp abstractions more_on_user_defined_types_exercises
(3) cpp abstractions more_on_user_defined_types_exercises
 
Mockito with a hint of PowerMock
Mockito with a hint of PowerMockMockito with a hint of PowerMock
Mockito with a hint of PowerMock
 
Python for Physical Science.pdf
Python for Physical Science.pdfPython for Physical Science.pdf
Python for Physical Science.pdf
 

More from josephineboon366

Hello, these are the discussion questions for the weekThe genera.docx
Hello, these are the discussion questions for the weekThe genera.docxHello, these are the discussion questions for the weekThe genera.docx
Hello, these are the discussion questions for the weekThe genera.docxjosephineboon366
 
Hello, I need a one and a half to two page long research paper on 3 .docx
Hello, I need a one and a half to two page long research paper on 3 .docxHello, I need a one and a half to two page long research paper on 3 .docx
Hello, I need a one and a half to two page long research paper on 3 .docxjosephineboon366
 
Hello, I need an Argumentative Research Essay with low level words.docx
Hello, I need an Argumentative Research Essay with low level words.docxHello, I need an Argumentative Research Essay with low level words.docx
Hello, I need an Argumentative Research Essay with low level words.docxjosephineboon366
 
Hello, I have a powerpoint presentation and I want an expert to do a.docx
Hello, I have a powerpoint presentation and I want an expert to do a.docxHello, I have a powerpoint presentation and I want an expert to do a.docx
Hello, I have a powerpoint presentation and I want an expert to do a.docxjosephineboon366
 
hello,Can you write a research paper Racisim defin Rcism an.docx
hello,Can you write a research paper  Racisim defin Rcism an.docxhello,Can you write a research paper  Racisim defin Rcism an.docx
hello,Can you write a research paper Racisim defin Rcism an.docxjosephineboon366
 
Hello, what I want is 2 pages of a play (link below) that you are go.docx
Hello, what I want is 2 pages of a play (link below) that you are go.docxHello, what I want is 2 pages of a play (link below) that you are go.docx
Hello, what I want is 2 pages of a play (link below) that you are go.docxjosephineboon366
 
Hello, we have a homework to implement fingerprint technology in ban.docx
Hello, we have a homework to implement fingerprint technology in ban.docxHello, we have a homework to implement fingerprint technology in ban.docx
Hello, we have a homework to implement fingerprint technology in ban.docxjosephineboon366
 
Hello, Need assistance with creating a mind map, This is due early.docx
Hello, Need assistance with creating a mind map, This is due early.docxHello, Need assistance with creating a mind map, This is due early.docx
Hello, Need assistance with creating a mind map, This is due early.docxjosephineboon366
 
Hello, I need help with these questions please. Please do not copy f.docx
Hello, I need help with these questions please. Please do not copy f.docxHello, I need help with these questions please. Please do not copy f.docx
Hello, I need help with these questions please. Please do not copy f.docxjosephineboon366
 
Hello, Im posting my project for someone to please identify and und.docx
Hello, Im posting my project for someone to please identify and und.docxHello, Im posting my project for someone to please identify and und.docx
Hello, Im posting my project for someone to please identify and und.docxjosephineboon366
 
Hello, I need help with my final essay for ENC1102. Its a 3 pages es.docx
Hello, I need help with my final essay for ENC1102. Its a 3 pages es.docxHello, I need help with my final essay for ENC1102. Its a 3 pages es.docx
Hello, I need help with my final essay for ENC1102. Its a 3 pages es.docxjosephineboon366
 
Hello, i need a 8 page double spaced research paper by the 11th .docx
Hello, i need a 8 page double spaced research paper by the 11th .docxHello, i need a 8 page double spaced research paper by the 11th .docx
Hello, i need a 8 page double spaced research paper by the 11th .docxjosephineboon366
 
Hello, i need 4 pages Argumentative essay. The subject exactly about.docx
Hello, i need 4 pages Argumentative essay. The subject exactly about.docxHello, i need 4 pages Argumentative essay. The subject exactly about.docx
Hello, i need 4 pages Argumentative essay. The subject exactly about.docxjosephineboon366
 
hello, i have five pages research paper and i would like to finish i.docx
hello, i have five pages research paper and i would like to finish i.docxhello, i have five pages research paper and i would like to finish i.docx
hello, i have five pages research paper and i would like to finish i.docxjosephineboon366
 
Hello, I have 2 questions that need be answered in 200 words each. I.docx
Hello, I have 2 questions that need be answered in 200 words each. I.docxHello, I have 2 questions that need be answered in 200 words each. I.docx
Hello, I have 2 questions that need be answered in 200 words each. I.docxjosephineboon366
 
Hello, I have a paper and I wrote the oultine and the reasons and .docx
Hello, I have a paper and I wrote the oultine and the reasons and .docxHello, I have a paper and I wrote the oultine and the reasons and .docx
Hello, I have a paper and I wrote the oultine and the reasons and .docxjosephineboon366
 
Hello! I need an 8 page essay done on the following anthropological .docx
Hello! I need an 8 page essay done on the following anthropological .docxHello! I need an 8 page essay done on the following anthropological .docx
Hello! I need an 8 page essay done on the following anthropological .docxjosephineboon366
 
Hello!  The directions are in the attatchements below. You only have.docx
Hello!  The directions are in the attatchements below. You only have.docxHello!  The directions are in the attatchements below. You only have.docx
Hello!  The directions are in the attatchements below. You only have.docxjosephineboon366
 
Hello  Please find the attached assignment. Prepare a 1,400-.docx
Hello  Please find the attached assignment. Prepare a 1,400-.docxHello  Please find the attached assignment. Prepare a 1,400-.docx
Hello  Please find the attached assignment. Prepare a 1,400-.docxjosephineboon366
 
Hello XXIAO,Qualitative research often generates large amounts of .docx
Hello XXIAO,Qualitative research often generates large amounts of .docxHello XXIAO,Qualitative research often generates large amounts of .docx
Hello XXIAO,Qualitative research often generates large amounts of .docxjosephineboon366
 

More from josephineboon366 (20)

Hello, these are the discussion questions for the weekThe genera.docx
Hello, these are the discussion questions for the weekThe genera.docxHello, these are the discussion questions for the weekThe genera.docx
Hello, these are the discussion questions for the weekThe genera.docx
 
Hello, I need a one and a half to two page long research paper on 3 .docx
Hello, I need a one and a half to two page long research paper on 3 .docxHello, I need a one and a half to two page long research paper on 3 .docx
Hello, I need a one and a half to two page long research paper on 3 .docx
 
Hello, I need an Argumentative Research Essay with low level words.docx
Hello, I need an Argumentative Research Essay with low level words.docxHello, I need an Argumentative Research Essay with low level words.docx
Hello, I need an Argumentative Research Essay with low level words.docx
 
Hello, I have a powerpoint presentation and I want an expert to do a.docx
Hello, I have a powerpoint presentation and I want an expert to do a.docxHello, I have a powerpoint presentation and I want an expert to do a.docx
Hello, I have a powerpoint presentation and I want an expert to do a.docx
 
hello,Can you write a research paper Racisim defin Rcism an.docx
hello,Can you write a research paper  Racisim defin Rcism an.docxhello,Can you write a research paper  Racisim defin Rcism an.docx
hello,Can you write a research paper Racisim defin Rcism an.docx
 
Hello, what I want is 2 pages of a play (link below) that you are go.docx
Hello, what I want is 2 pages of a play (link below) that you are go.docxHello, what I want is 2 pages of a play (link below) that you are go.docx
Hello, what I want is 2 pages of a play (link below) that you are go.docx
 
Hello, we have a homework to implement fingerprint technology in ban.docx
Hello, we have a homework to implement fingerprint technology in ban.docxHello, we have a homework to implement fingerprint technology in ban.docx
Hello, we have a homework to implement fingerprint technology in ban.docx
 
Hello, Need assistance with creating a mind map, This is due early.docx
Hello, Need assistance with creating a mind map, This is due early.docxHello, Need assistance with creating a mind map, This is due early.docx
Hello, Need assistance with creating a mind map, This is due early.docx
 
Hello, I need help with these questions please. Please do not copy f.docx
Hello, I need help with these questions please. Please do not copy f.docxHello, I need help with these questions please. Please do not copy f.docx
Hello, I need help with these questions please. Please do not copy f.docx
 
Hello, Im posting my project for someone to please identify and und.docx
Hello, Im posting my project for someone to please identify and und.docxHello, Im posting my project for someone to please identify and und.docx
Hello, Im posting my project for someone to please identify and und.docx
 
Hello, I need help with my final essay for ENC1102. Its a 3 pages es.docx
Hello, I need help with my final essay for ENC1102. Its a 3 pages es.docxHello, I need help with my final essay for ENC1102. Its a 3 pages es.docx
Hello, I need help with my final essay for ENC1102. Its a 3 pages es.docx
 
Hello, i need a 8 page double spaced research paper by the 11th .docx
Hello, i need a 8 page double spaced research paper by the 11th .docxHello, i need a 8 page double spaced research paper by the 11th .docx
Hello, i need a 8 page double spaced research paper by the 11th .docx
 
Hello, i need 4 pages Argumentative essay. The subject exactly about.docx
Hello, i need 4 pages Argumentative essay. The subject exactly about.docxHello, i need 4 pages Argumentative essay. The subject exactly about.docx
Hello, i need 4 pages Argumentative essay. The subject exactly about.docx
 
hello, i have five pages research paper and i would like to finish i.docx
hello, i have five pages research paper and i would like to finish i.docxhello, i have five pages research paper and i would like to finish i.docx
hello, i have five pages research paper and i would like to finish i.docx
 
Hello, I have 2 questions that need be answered in 200 words each. I.docx
Hello, I have 2 questions that need be answered in 200 words each. I.docxHello, I have 2 questions that need be answered in 200 words each. I.docx
Hello, I have 2 questions that need be answered in 200 words each. I.docx
 
Hello, I have a paper and I wrote the oultine and the reasons and .docx
Hello, I have a paper and I wrote the oultine and the reasons and .docxHello, I have a paper and I wrote the oultine and the reasons and .docx
Hello, I have a paper and I wrote the oultine and the reasons and .docx
 
Hello! I need an 8 page essay done on the following anthropological .docx
Hello! I need an 8 page essay done on the following anthropological .docxHello! I need an 8 page essay done on the following anthropological .docx
Hello! I need an 8 page essay done on the following anthropological .docx
 
Hello!  The directions are in the attatchements below. You only have.docx
Hello!  The directions are in the attatchements below. You only have.docxHello!  The directions are in the attatchements below. You only have.docx
Hello!  The directions are in the attatchements below. You only have.docx
 
Hello  Please find the attached assignment. Prepare a 1,400-.docx
Hello  Please find the attached assignment. Prepare a 1,400-.docxHello  Please find the attached assignment. Prepare a 1,400-.docx
Hello  Please find the attached assignment. Prepare a 1,400-.docx
 
Hello XXIAO,Qualitative research often generates large amounts of .docx
Hello XXIAO,Qualitative research often generates large amounts of .docxHello XXIAO,Qualitative research often generates large amounts of .docx
Hello XXIAO,Qualitative research often generates large amounts of .docx
 

Recently uploaded

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 

Recently uploaded (20)

Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 

Goals1)Be able to work with individual bits in java.2).docx

  • 1. 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 tests. Synthesis Questions 1. Why is it a good idea to test a general class with a driver program before trying to use it? 2. What is the difference between black box and glass box debugging? 3.
  • 2. In pseudo-code, describe CreateTest.java. 4. In pseudo code, describe the driver program that is provided below. 5. If x = 37, y=23, z=-110, r=-32 answer the following questions. Assume that we are working with bytes. To answer these questions, you will need to convert from decimal to binary. Remember that System.out.println DOES NOT print binary values. You will need to convert your results to decimal. Of course you can verify your results by computer. Remember that there will be questions like this on the quiz, so try them yourself first. a. System.out.println ( x&y ); b. System.out.println ( x^y ); c. System.out.println (~ x|y ); d.
  • 3. System.out.println (~x>>2); e. System.out.println ((byte)(z<<(~r>>4))); f. System.out.println ((byte)(x + (x<<1) + (x<<2) + (x<<3))); g. System.out.println (y>>>3); h. System.out.println ( x&y|z^r ); i. System.out.println (~x + x); j. System.out.println (x|(3<<4)); 6. In about a sentence, give a reasonable example of when the following operators would be useful when working with strings of bits. a.
  • 4. or operation (|): b. and operation (&): c. exclusive or operation (^): d. left shift operation: (<<): 7. Suppose we need to create a multiple-choice exam, where each question has four possible choices. Briefly describe (in a few sentences) how we could create a new class that uses inheritance that would allow this. Giving class API and a brief description of the needed methods would also suffice. 8. Suppose we needed to modify the BitMap class to handle a bit stream of up to 16384 bits. Briefly describe the changes necessary to handle this refinement. Can you think of a way that the maximum number of bits to be handled is completely flexible? 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
  • 5. 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
  • 7. 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
  • 8. ( ) 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.
  • 9. (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.
  • 10. 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.
  • 11. 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
  • 12. 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.*;
  • 14. 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.
  • 16. 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:
  • 17. // 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 (
  • 18. 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 (
  • 19. " compareTo = " + bitMap.compareTo ( secondMap )); break ; case 8: // See if maps equal. secondMap = getMap (); System.out.println ( bitMap ); System.out.println ( secondMap ); if ( bitMap.equals
  • 20. ( secondMap )) { System.out.println ( "Maps equal" ); } else { System.out.println ( "Maps not equal" ); } break ; case 9: // toString . System.out.println ( bitMap ); break ; default :
  • 21. 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 =
  • 22. 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
  • 23. " ); 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);
  • 24. } // 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
  • 26. 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 (
  • 29. ; } // 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 ;
  • 30. 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;