# Thread: Stuck on Boolean varification--plz help

1. Member
Join Date
Aug 2009
Posts
11
Rep Power
0

## Stuck on Boolean varification--plz help

Hi there,
I'm very new to Java, and I'm trying to find a solution.

I have the user inputting a 6 digit number
the last digit is dropped and the 5 digit number is then % 7
to achive a remainder.
The remainder and the dropped digit should be the same, if so..a boolean "true" would then be displayed, or false if not.

EX. 123454
drop the 4
12345 % 7 = 4

dropped digit 4 - remainder is 4 so boolean returns true.

I have everything except the boolean part.
Any help/explanation would be very helpfull.

Cutter

CODE:

import javax.swing.JOptionPane;
public class TicketNumber
{
public static void main(String[] args)
{

String ticketString;
int ticket,valid,lastDigit,isTicketVaild;
int result = 7;

ticketString = JOptionPane.showInputDialog(null, "Enter 6 digit ticket number" , "Ticket validation",
JOptionPane.INFORMATION_MESSAGE);
lastDigit = Integer.parseInt(ticketString) -1;

valid = Integer.parseInt(ticketString) % result;

boolean b;
b=false
if(lastDigit==valid)b=true;

JOptionPane.showMessageDialog(null, b);

System.exit(0);
}
}

2. First things first.

You'd better first do a System.out.println on your lastDigit variable, because I don't think it's what you think it is. Taking a number and subtracting one from it will not get you the last digit. In my mind you have one of two ways to get this, either using a String method to extract the last character of the number String, or you could use the mod operator "%" to get the last digit of an int numerically (I'll let you figure out how to do this) -- up to you. Best of luck!

3. Member
Join Date
Aug 2009
Posts
11
Rep Power
0
Um..okay, thanks (I think :) )

I do see what you say now.

I guess I'm going to need both.
Because i would need the remainder and the last digit to compare each other to.

I've been workinhg on this for awhile now, and have 2 days left to hand it in.
If I could do it myself, I wouldn't have asked for the help:rolleyes:

I thought I'd finally had a break through....back to the books :confused:

Cutter

4. Member
Join Date
Aug 2009
Posts
11
Rep Power
0
?.............

5. Member
Join Date
Jan 2009
Location
Belgium
Posts
20
Rep Power
0
123456 % 10 = 6 = last digit
123456 % 100 = 56 = 2 last digits
...

6. Member
Join Date
Aug 2009
Posts
11
Rep Power
0

The 6 digits are user input, so they will vary.
The last digit of 123454 would be 4

wereas the 12345 would be calculated as 12345 % 7 = 4

the the lastdigit(4) and the remainder (4) would have a boolean expression to determine weather they are the same or not. (true or false).

Thanks again
Cutter

7. Member
Join Date
Jan 2009
Location
Belgium
Posts
20
Rep Power
0
If you do
lastDigit = Integer.parseInt(ticketString) -1;
when the user entered 123454 you get a lastDigit = 123453 = 123454 -1
but if you do
lastDigit = Integer.parseInt(ticketString) % 10;
when the user entered 123454 you get a lastDigit = 4 = 123454 % 10

now, if you do fiveDigitNumber = Integer.parseInt(ticketString) - lastDigit
you get a number ending at zero, so you can divide it by 10 and you have dropped the last digit. ->
fiveDigitNumber = fiveDigitNumber/10
moduloResult = fiveDigitNumber % 7
if (moduloResult == lastDigit) b = true

Would this do it ?

8. Member
Join Date
Aug 2009
Posts
11
Rep Power
0
OMG!!

Thank you so very much !!!!

And I actually understand it.

I was ready to give up....so thank you for helping me.

I really want to learn and I enjoy it.

Cutter

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•