Results 1 to 8 of 8
  1. #1
    Cutter is offline Member
    Join Date
    Aug 2009
    Posts
    11
    Rep Power
    0

    Default 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.
    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);
    }
    }

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    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. #3
    Cutter is offline Member
    Join Date
    Aug 2009
    Posts
    11
    Rep Power
    0

    Default

    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. #4
    Cutter is offline Member
    Join Date
    Aug 2009
    Posts
    11
    Rep Power
    0

    Default

    ?.............

  5. #5
    freqrush is offline Member
    Join Date
    Jan 2009
    Location
    Belgium
    Posts
    20
    Rep Power
    0

    Default

    123456 % 10 = 6 = last digit
    123456 % 100 = 56 = 2 last digits
    ...

  6. #6
    Cutter is offline Member
    Join Date
    Aug 2009
    Posts
    11
    Rep Power
    0

    Default

    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

  7. #7
    freqrush is offline Member
    Join Date
    Jan 2009
    Location
    Belgium
    Posts
    20
    Rep Power
    0

    Default

    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. #8
    Cutter is offline Member
    Join Date
    Aug 2009
    Posts
    11
    Rep Power
    0

    Default

    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.

    You've made my week...:D

    Cutter

Similar Threads

  1. 1 as an integer, not boolean
    By McChill in forum New To Java
    Replies: 1
    Last Post: 05-02-2009, 10:39 PM
  2. Simple Boolean
    By jigglywiggly in forum New To Java
    Replies: 3
    Last Post: 01-01-2009, 06:01 AM
  3. boolean to string
    By otoro_java in forum New To Java
    Replies: 2
    Last Post: 01-30-2008, 06:31 AM
  4. boolean variables
    By ravian in forum New To Java
    Replies: 3
    Last Post: 12-31-2007, 05:58 AM
  5. Boolean Expression
    By ritwik07 in forum New To Java
    Replies: 3
    Last Post: 07-11-2007, 05:11 AM

Posting Permissions

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