Professional Documents
Culture Documents
Page 1 of 6
Material
Covered
long
integers
if
statements
input
validation
using
Scanner
"has-"
methods
loops
(while,
do-while,
for)
File
input
using
Scanner
class
String
processing
Page 2 of 6
For
example,
performing
the
algorithm
on
the
credit
card
number
5048
4801
4229
6497
gives
the
following
results:
digit
position
check
value
5
0
4
8
4
8
0
1
4
2
2
9
6
4
9
7
even
odd
even
odd
even
odd
even
odd
even
odd
even
odd
even
odd
even
odd
5*2
=
10
-
9
=
1
0
4*2
=
8
8
4*2
=
8
8
2*0
=
0
1
4*2
=
8
2
2*2
=
4
9
6*2
=
12
-
9
=
3
4
9*2
=
18
-
9
=
9
7
Total 80
(valid)
Create
a
Java
program
that
accepts
as
input
a
16-digit
number
and
implements
the
above
algorithm
to
check
for
a
valid
credit
card
number.
Since
a
16-digit
number
is
too
large
to
fit
into
an
int,
you
will
need
to
work
with
long
integer
values.
1
Page 3 of 6
Input: Ask the user for a credit card number with 16 digits (Note: leading zeros are NOT permitted). Use System.in (using the Scanner class) for input and echo the input using System.out.println. You must validate the input by checking that 1) the input is a valid long integer (hint: use one of the Scanner "has-" methods), and 2) that the input has 16 digits (hint: the number must be in the range 1,000,000,000,000,000 input < 10,000,000,000,000,000). Use a loop to accept and validate input so that the user must enter valid input before proceeding to the calculation step. Print meaningful messages when invalid input is entered (see the sample output below). Calculate: calculate the check value using the algorithm described above. You will use a loop to perform this calculation. (Which is the most appropriate type?) Output: Print (using System.out) the total check value and a message indicating whether the credit card number is valid or not. Here is sample output from the program. Scanner input is shown in bold italic. Enter a 16-digit credit card number: something else Input of 'something else' is not valid. Enter a 16-digit credit card number : 0000111122223333 Input of 111122223333 is not 16 digits. Enter a 16-digit credit card number: 12345678901234567 Input of 12345678901234567 is not 16 digits. Enter a 16-digit credit card number: 5048480142296497 Your card number is 5048480142296497 Checksum is 80 Card number is valid. Programmed by Stew Dent ** End of processing. ** Extra feature (not required): Echo the credit card number as four groups of 4 digits. Hand in: Your Java source code, according to the instructions on page 1. Also, submit two sets of output using the following input values: 5048 4801 4229 6497 and 1234 5678 9009 8765. Your output should also show that invalid input is detected and an appropriate message is printed by entering: 1) non-numeric input, 2) a number with less than 16 digits and 3) a number with more than 16 digits. Put all your output into one file. (Submit exactly 2 files, one .java file and one .txt file, for this question.)
Page 4 of 6
Calculate:
Find
all
the
ascending
words
that
are
at
least
2
letters
long
(the
single
letter
words
are
not
interesting),
count
them
and
calculate
the
average
length
and
longest
length.
Output:
Print
the
list
of
ascending
words.
Group
the
list
by
first
letter,
separating
each
group
with
a
blank
line.
Print
as
many
words
on
each
line
as
will
fit
into
an
80-character
width,
but
do
not
go
over
80
characters.
Separate
the
words
with
a
single
blank
(but
don't
put
a
blank
at
the
beginning
of
a
line).
Print
the
total
number
of
ascending
words
found,
their
average
length
and
the
longest
length.
Hand
in:
Your
Java
source
code,
according
to
the
instructions
on
page
1.
Also,
submit
the
output
from
running
your
program.
(Submit
exactly
2
files,
one
.java
file
and
one
.txt
file,
for
this
question.)
Here
is
sample
output
from
the
program,
with
some
values
obscured.
Since
everyones
output
should
be
identical,
we
dont
want
to
give
away
the
correct
values.
Searching for ascending words from the input file. abbe abbey abbot abc abet abort accent accept access accost ace act ad add adept ado adopt aegis affix afoot aft ago ah ahoy ail aim air airy all allot allow // more output here Found *** ascending words. Average word length is ******. Longest word length is *.
Page 5 of 6
COMP 1010 Fall 2013 Assignment 2 password password password password password password password password Password
Page 6 of 6
passes length check. passes letters and numbers only check. passes begins with letter check. passes minimum letter check. fails minimum number check. passes same character check. fails maximum repetitive check (maximum 2 allowed). passes userid check. 'passswd' failed 2 tests.
> run PasswordChecker Enter your userid and password: ng245 sing2456 Checking userID: ng245 and password: sing2456 password passes length check. password passes letters and numbers only check. password passes begins with letter check. password passes minimum letter check. password passes minimum number check. password passes same character check. password passes maximum repetitive check. password fails userid check. Password 'sing2456' failed 1 test. Enter your userid and password: umdent24 1BadPswd Checking userID: umdent24 and password: 1BadPswd password passes length check. password passes letters and numbers only check. password fails begins with letter check. password passes minimum letter check. password passes minimum number check. password passes same character check. password passes maximum repetitive check. password passes userid check. Password '1BadPswd' failed 1 test. > run PasswordChecker Enter your userid and password: umdent24 aa1aa2aa Checking userID: umdent24 and password: aa1aa2aa password passes length check. password passes letters and numbers only check. password passes begins with letter check. password passes minimum letter check. password passes minimum number check. password fails same character check (maximum 4 allowed). password passes maximum repetitive check. password passes userid check. Password 'aa1aa2aa' failed 1 test.