Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: Need help!!! Asap PLEASE!!!!

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Need help!!! Asap PLEASE!!!!

    import java.util.Scanner;

    public class data {

    public static int setoriginal() { //prompt user to input 4 digit number
    int n = 0;
    int l = 0;

    do {
    Scanner input = new Scanner(System.in);

    System.out.println("Please enter a 4 digit number: ");
    n = input.nextInt();

    if (n >= 1000 && n <= 9999) {
    break;
    } else {
    System.err.
    printf("You did not enter 4 digits\n");
    }

    l = l + 1;
    }
    while (l < 3);

    return n;
    } //end method

    public static int encrypt(int n) { //encrypt number inputted by user

    int e1 = (((n / 1000) + 7) / 10);
    int e2 = ((((n % 1000) / 100) + 7) / 10);
    int e3 = ((((n % 100) / 10) + 7) / 10);
    int e4 = ((((n % 10) / 1) + 7) / 10);

    int e = e1 * 1000 + e2 * 100 + e3 * 10 + e4;

    int firstPart = e % 100;
    int lastPart = e / 100;

    int result = firstPart * 100 + lastPart;

    return result;
    } //end method

    public static int decrypt(int result) { //decrypt encrypted number

    int d1 = (((result / 1000) - 7) * 10);
    int d2 = ((((result % 1000) / 100) - 7) * 10);
    int d3 = ((((result % 100) / 10) - 7) * 10);
    int d4 = ((((result % 10) / 1) - 7) * 10);

    int d = d1 * 1000 + d2 * 100 + d3 * 10 + d4;

    int firstPart1 = d % 100;
    int lastPart1 = d / 100;

    int result1 = firstPart1 * 100 + lastPart1;

    return result1;
    } //end method

    public static int decrypt1(int n) { //decrypted number inputted by user

    int dd1 = (((n / 1000) - 7) * 10);
    int dd2 = ((((n % 1000) / 100) - 7) * 10);
    int dd3 = ((((n % 100) / 10) - 7) * 10);
    int dd4 = ((((n % 10) / 1) - 7) * 10);

    int dd = dd1 * 1000 + dd2 * 100 + dd3 * 10 + dd4;

    int firstPart1 = dd % 100;
    int lastPart1 = dd / 100;

    int result1 = firstPart1 * 100 + lastPart1;

    return result1;
    } //end method

    public static void display(int n, int result, int result1) { //output results
    System.out.println("Originl number is: " + n);
    System.out.println("\nEcrypted numebr is: " + result);
    } //end method

    public static void display1(int n, int result, int result1) { //output results
    System.out.println("Originl number is: " + n);
    System.out.println("\nDecrypted numebr is: " + result1);
    } //end method

    public static void getOriginal(int n) { //return original number
    System.out.println("The original number is: \n" + n);
    } //end method

    public static void getEncrypt(int n, int result) { //return encrypted number
    System.out.println("The encrypted number is: \n" + result);
    } //end method

    public static void main(String[]args, int result, int n, int result1) {
    int m = 0;
    Scanner input1 = new Scanner(System.in);

    System.out.print("\nPlease choose from the following menu ");
    System.out.print("\n1. Enter an original number");
    System.out.print("\n2. Encrypt the number and print it");
    System.out.print("\n3. Decrypt a number and print it");
    System.out.print("\n4. Quit\n");
    m = input1.nextInt();

    while (m < 1 || m > 4) {
    System.out.print("Error choose a number from 1-4");
    m = input1.nextInt();
    }

    if (m == 1) {
    setoriginal();
    main(args, m, m, m);
    }

    else if (m == 2) {
    if (setoriginal() == 0) {
    System.out.
    print
    ("Please enter an original number first");
    main(args, m, m, m);
    } else {
    encrypt(n);
    display(n, result, result1);
    main(args, n, result, result1);
    }
    } else if (m == 3) {
    if (encrypt(n) < 0) {
    System.out.
    print("Please encrypt your number first");
    main(args, n, result, result1);
    } else {
    decrypt(n);
    display1(n, result, result1);
    main(args, n, result, result1);
    }
    } else if (m == 4) {
    System.exit(0);

    }

    }
    }

    I keep getting a message saying "Selection does not contain a main type" :S But i do have a main. Any idea what the issue could be? Thanks in advance for the help guys.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Need help!!! Asap PLEASE!!!!

    Very carefully look at the structure of the main method in the following link, and for future reference please use the code tags

    Lesson: A Closer Look at the "Hello World!" Application (The Java™ Tutorials > Getting Started)

  3. #3
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Need help!!! Asap PLEASE!!!!

    Oh look another one who thinks they are more important than others. But wait we now have two people that want help ASAP. Who should we help?
    Improving the world one idiot at a time!

  4. #4
    Junior Member
    Join Date
    Nov 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Need help!!! Asap PLEASE!!!!

    help both

  5. #5
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Need help!!! Asap PLEASE!!!!

    And I might do that when I want not when you demand it!
    Improving the world one idiot at a time!

  6. #6
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Need help!!! Asap PLEASE!!!!

    Well, i guess after reading copeg's specified link, you will be able to solve the issue.

Similar Threads

  1. [SOLVED] Can someone help me with this code asap
    By Darkcore123 in forum What's Wrong With My Code?
    Replies: 12
    Last Post: November 14th, 2011, 11:55 AM
  2. Need some help with this code - Asap
    By Th3T3chGuy in forum What's Wrong With My Code?
    Replies: 3
    Last Post: November 10th, 2011, 07:17 AM
  3. Need help ASAP!!!!
    By Swiper in forum What's Wrong With My Code?
    Replies: 9
    Last Post: August 12th, 2011, 06:41 PM
  4. NEED HELP ASAP!!
    By JavaStudent_09 in forum What's Wrong With My Code?
    Replies: 7
    Last Post: August 18th, 2010, 07:33 PM
  5. NEED HELP ASAP PLEASE!!!
    By mbm4ever in forum What's Wrong With My Code?
    Replies: 8
    Last Post: August 12th, 2010, 07:01 PM

Tags for this Thread