Project 9-10

Discussion in 'iOS Jailbreak & Cydia' started by azninsane540, Dec 3, 2007.

  1. azninsane540

    azninsane540 New Member

    Joined:
    Oct 19, 2007
    Messages:
    22
    Likes Received:
    0
    Device:
    2G iPod touch
    /***************************************************************
    * *
    * Name: *
    * Date: 3 December 2007 *
    * Project: Project 9-10 *
    * *
    ***************************************************************/

    import java.util.Random;
    import java.util.Scanner;

    class Project910{

    public static void main (String [] args){

    int value[][] = new int [5][5];

    value[0][0] = 1;
    value[0][1] = 1;
    value[0][2] = 1;
    value[0][3] = 1;
    value[0][4] = 1;

    value[1][0] = 1;
    value[1][1] = 2;
    value[1][2] = 2;
    value[1][3] = 2;
    value[1][4] = 1;

    value[2][0] = 1;
    value[2][1] = 2;
    value[2][2] = 3;
    value[2][3] = 2;
    value[2][4] = 1;

    value[3][0] = 1;
    value[3][1] = 2;
    value[3][2] = 2;
    value[3][3] = 2;
    value[3][4] = 1;

    value[4][0] = 1;
    value[4][1] = 1;
    value[4][2] = 1;
    value[4][3] = 1;
    value[4][4] = 1;

    System.out.println("~Penny Pitch~\n");

    for (int i = 0; i < 5; i++){
    for (int j = 0; j < 5; j++){
    System.out.print (value[j] + " ");
    }
    System.out.println("\n");
    }

    Scanner reader = new Scanner(System.in);
    int selection = 0;
    int loop = 0;
    int counter = 0;
    int sum = 0;
    while(loop == 0){
    System.out.print("\nEnter 1 to toss a coin, 0 to exit. ");
    selection = reader.nextInt();

    if(selection == 1) {
    counter++;
    System.out.println("\nTossing penny...");
    Random rnd1 = new Random();
    int x = rnd1.nextInt(5);
    int y = rnd1.nextInt(5);

    if(value[x][y] == 0) {
    System.out.println("Your penny landed on another penny at coordinates: " + (y+1) + "," + (x+1));
    }
    else{
    System.out.println("Your penny landed on a " + value[x][y] + " at coordinates: " + (y+1) + "," + (x+1));
    }
    sum += value[x][y];
    System.out.println("Your sum so far is " + sum + " after " + counter + " tosses.");
    value[x][y] = 0;

    System.out.println("\n");
    for (int i = 0; i < 5; i++) {
    for (int j = 0; j < 5; j++) {
    if (value[j] == 0) {
    System.out.print("P ");
    }
    else {
    System.out.print(value[j] + " ");
    }
    }
    System.out.println("\n");
    }
    }
    else {
    System.out.println("\nHave a nice day! =)");
    break;
    }

    }

    }

    }
  2. Nt1440

    Nt1440 New Member

    Joined:
    Nov 9, 2007
    Messages:
    1,431
    Likes Received:
    26
    from looking at this im assuming this is some type of coin toss game?

    i dont really see the point of this, but it is nice to finally have a look at some coding, can you tell me how you first started? and possibly any tips to some one who wants to start coding?
  3. Blake

    Blake Super Moderator Emeritus

    Joined:
    Oct 4, 2007
    Messages:
    2,963
    Likes Received:
    63
    Device:
    iPhone 4S (White)
    At least tell the name of the project

    Please Register or Log in to view images

    .
    But I'm assuming that it has something to do with pennies.
    -Moved to Ipod Touch Applications-
  4. SkylarEC

    SkylarEC Super Moderator Emeritus Staff Member

    Joined:
    Sep 19, 2007
    Messages:
    6,642
    Likes Received:
    129
    For those who can't tell, this little applet throws five pennies onto an imaginary 4 x 4 grid. It then tells you where the pennies landed.

    Sidenote: You don't have to seed the random number generator in Java? Most other languages that I know require the random number to be seeded, usually with a datestamp. Neat.
  5. Nt1440

    Nt1440 New Member

    Joined:
    Nov 9, 2007
    Messages:
    1,431
    Likes Received:
    26
    oh skylar, u continue to amaze me with ur coding knowledge lol

    how can i learn?

Share This Page