Results 1 to 8 of 8
 08052009, 04:04 AM #1Member
 Join Date
 Aug 2009
 Posts
 11
 Rep Power
 0
Stuck on Boolean varificationplz 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.
Thank you in advance
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);
}
}

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!
 08052009, 12:03 PM #3Member
 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
 08052009, 12:12 PM #4Member
 Join Date
 Aug 2009
 Posts
 11
 Rep Power
 0
?.............
 08052009, 12:23 PM #5Member
 Join Date
 Jan 2009
 Location
 Belgium
 Posts
 20
 Rep Power
 0
123456 % 10 = 6 = last digit
123456 % 100 = 56 = 2 last digits
...
 08052009, 12:41 PM #6Member
 Join Date
 Aug 2009
 Posts
 11
 Rep Power
 0
Thanks for your reply freqrush,
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
 08052009, 01:43 PM #7Member
 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 ?
 08052009, 02:18 PM #8Member
 Join Date
 Aug 2009
 Posts
 11
 Rep Power
 0
Similar Threads

1 as an integer, not boolean
By McChill in forum New To JavaReplies: 1Last Post: 05022009, 09:39 PM 
Simple Boolean
By jigglywiggly in forum New To JavaReplies: 3Last Post: 01012009, 06:01 AM 
boolean to string
By otoro_java in forum New To JavaReplies: 2Last Post: 01302008, 06:31 AM 
boolean variables
By ravian in forum New To JavaReplies: 3Last Post: 12312007, 05:58 AM 
Boolean Expression
By ritwik07 in forum New To JavaReplies: 3Last Post: 07112007, 04:11 AM
Bookmarks