Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

 
 
Thread Tools Display Modes
Prev Previous Post in Thread   Next Post in Thread Next
Old Jan 13th, 2008, 2:27 AM   #1
bearvsgodzila
Newbie
 
Join Date: Jan 2008
Posts: 4
Rep Power: 0 bearvsgodzila is on a distinguished road
Help in Converting C# to Java

Hey guys, need some help converting c# codes to java.

there's a lot of errors(repetitive at each else-if) and i only spot the starting of the codes, can any one help?

i don't know what's "Convert.ToInt32", the char numbers can't seem to convert into toString. sorry for my bad english
 
 import java.*;
   import java.math.*;
   import java.util.*;

    class NricCheck {
   
      
   
   
       public static void main (String [] args){
      
         

      }
      
       public boolean nricValidator(String nric){
      
       char[] nricArray = nric.toCharArray();
            int sum = 0;
            int num = 0;
            int result = 0;
            char numbers;
            String no = "";
            boolean valided = false;
				

            try
            {
                for (int i = 0; i<nricArray.length; i++)
                {
                    if (i == 1)
                    {
                        num = 0;
                        numbers = nricArray[i];
                        no = numbers.toString();
                        num = Convert.ToInt32(no);
                        num *= 2;
                        nricArray[i] = Convert.ToChar(num);
                    }
                    else if (i == 2)
                    {
                        num = 0;
                        numbers = nricArray[i];
                        no = numbers.ToString();
                        num = Convert.ToInt32(no);
                        num *= 7;
                        nricArray[i] = Convert.ToChar(num);
                    }
                    else if (i == 3)
                    {
                        num = 0;
                        numbers = nricArray[i];
                        no = numbers.ToString();
                        num = Convert.ToInt32(no);
                        num *= 6;
                        nricArray[i] = Convert.ToChar(num);
                    }
                    else if (i == 4)
                    {
                        num = 0;
                        numbers = nricArray[i];
                        no = numbers.ToString();
                        num = Convert.ToInt32(no);
                        num *= 5;
                        nricArray[i] = Convert.ToChar(num);
                    }
                    else if (i == 5)
                    {
                        num = 0;
                        numbers = nricArray[i];
                        no = numbers.ToString();
                        num = Convert.ToInt32(no);
                        num *= 4;
                        nricArray[i] = Convert.ToChar(num);
                    }
                    else if (i == 6)
                    {
                        num = 0;
                        numbers = nricArray[i];
                        no = numbers.ToString();
                        num = Convert.ToInt32(no);
                        num *= 3;
                        nricArray[i] = Convert.ToChar(num);
                    }
                    else if (i == 7)
                    {
                        num = 0;
                        numbers = nricArray[i];
                        no = numbers.ToString();
                        num = Convert.ToInt32(no);
                        num *= 2;
                        nricArray[i] = Convert.ToChar(num);
                    }
                }

                for (int i = 0; i < nricArray.Length; i++)
                {
                    if (i > 0 && i < 8)
                    {
                        numbers = nricArray[i];

                        num = Convert.ToInt32(numbers);

                        sum += num;
                    }
                }

                result = sum % 11;

                if (result == 10)
                {
                    if (nricArray[8] == 'A' || nricArray[8] == 'a')
                    {
                        valided = true;
                    }
                    else
                    {
                        valided = false;
                        System.out.println.out("Your last alphabet should be 'A'", "Nric Error");
                    }
                }
                else if (result == 9)
                {
                    if (nricArray[8] == 'B' || nricArray[8] == 'b')
                    {
                        valided = true;
                    }
                    else
                    {
                        valided = false;
                        System.out.println.out("Your last alphabet should be 'B'", "Nric Error");
                    }
                }
                else if (result == 8)
                {
                    if (nricArray[8] == 'C' || nricArray[8] == 'c')
                    {
                        valided = true;
                    }
                    else
                    {
                        valided = false;
                        System.out.println.out("Your last alphabet should be 'C'", "Nric Error");
                    }
                }
                else if (result == 7)
                {
                    if (nricArray[8] == 'D' || nricArray[8] == 'd')
                    {
                        valided = true;
                    }
                    else
                    {
                        valided = false;
                       System.out.println.out("Your last alphabet should be 'D'", "Nric Error");
                    }
                }
                else if (result == 6)
                {
                    if (nricArray[8] == 'E' || nricArray[8] == 'e')
                    {
                        valided = true;
                    }
                    else
                    {
                        valided = false;
                        System.out.println.out("Your last alphabet should be 'E'", "Nric Error");
                    }
                }
                else if (result == 5)
                {
                    if (nricArray[8] == 'F' || nricArray[8] == 'f')
                    {
                        valided = true;
                    }
                    else
                    {
                        valided = false;
                        System.out.println.out("Your last alphabet should be 'F'", "Nric Error");
                    }
                }
                else if (result == 4)
                {
                    if (nricArray[8] == 'G' || nricArray[8] == 'g')
                    {
                        valided = true;
                    }
                    else
                    {
                        valided = false;
                        System.out.println.out("Your last alphabet should be 'G'", "Nric Error");
                    }
                }
                else if (result == 3)
                {
                    if (nricArray[8] == 'H' || nricArray[8] == 'h')
                    {
                        valided = true;
                    }
                    else
                    {
                        valided = false;
                        System.out.println.out("Your last alphabet should be 'H'", "Nric Error");
                    }
                }
                else if (result == 2)
                {
                    if (nricArray[8] == 'I' || nricArray[8] == 'i')
                    {
                        valided = true;
                    }
                    else
                    {
                        valided = false;
                        System.out.println.out("Your last alphabet should be 'I'", "Nric Error");
                    }
                }
                else if (result == 1)
                {
                    if (nricArray[8] == 'Z' || nricArray[8] == 'z')
                    {
                        valided = true;
                    }
                    else
                    {
                        valided = false;
                        System.out.println.out("Your last alphabet should be 'Z'", "Nric Error");
                    }
                }
                else if (result == 0)
                {
                    if (nricArray[8] == 'J' || nricArray[8] == 'j')
                    {
                        valided = true;
                    }
                    else
                    {
                        valided = false;
                        System.out.println.out("Your last alphabet should be 'J'", "Nric Error");
                    }
                }
            }
            catch (FormatException e)
            {
                System.out.println("Check your NRIC. You may have key it wrongly.", "Error");
            }
            catch (IndexOutOfRangeException e)
            {
                System.out.println("Check your NRIC. You may have key it wrongly.", "Error");
            }
            catch (NullReferenceException e)
            {
                System.out.printl("Check your NRIC. You may have key it wrongly.", "Error");
            }

           return nric;
        }
      
      
       }
bearvsgodzila is offline   Reply With Quote
 

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programming with Java: Tutorial ReggaetonKing Java 7 May 20th, 2008 10:58 AM
Special browser in Java (Project) stalefish Java 3 Feb 9th, 2008 4:22 PM
Java programmers, game developers, artists, be ware! RPG game team is recruiting! atcomputers.us Paid Job Offers 7 Sep 25th, 2005 7:25 PM
Help! converting java to c++ hilbertspace C++ 1 Jun 8th, 2005 8:46 AM
converting python to java shak187 Java 4 May 4th, 2005 2:36 AM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:27 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC