Results 1 to 5 of 5
  1. #1
    yamicaitsith is offline Member
    Join Date
    Sep 2012
    Location
    san marcos,ca
    Posts
    12
    Rep Power
    0

    Default How to call a classes to a object?

    Hi. I have a problem with calling a class in "main", can someone provide me method calls to call classes?.
    My program contains a 4 dice roll, I only separated the program in different classes.

    My question is how can I do it ?
    Could anyone provide me with some example or method calls I need to use to make this program call them on the main object?

    Thank you.

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

    Default Re: How to call a classes to a object?

    Your question without more context makes little sense. Please clarify just what it is you are asking, and what code you currently have that's not working.

  3. #3
    yamicaitsith is offline Member
    Join Date
    Sep 2012
    Location
    san marcos,ca
    Posts
    12
    Rep Power
    0

    Default Re: How to call a classes to a object?

    import java.util.Random;
    public class twelveDiceRoll {



    /**
    * Dodecahedral Dice program, this program gives a near hypothesis on Eric Harshbarger dice theory with 4 dice with 12 sides
    */
    public static void main(String[] args) {

    // arrays

    //Die 1: 1, 8, 11, 14, 19, 22, 27, 30, 35, 38, 41, 48
    int[] die1;
    die1 = new int[12];
    die1[0] = 1;
    die1[1] = 8;
    die1[2] = 11;
    die1[3] = 14;
    die1[4] = 19;
    die1[5] = 22;
    die1[6] = 27;
    die1[7] = 30;
    die1[8] = 35;
    die1[9] = 38;
    die1[10] = 41;
    die1[11] = 48;

    // Die 2: 2, 7, 10, 15, 18, 23, 26, 31, 34, 39, 42, 47
    int[]die2;
    die2 = new int[12];
    die2[0] = 2;
    die2[1] = 7;
    die2[2] = 10;
    die2[3] = 15;
    die2[4] = 18;
    die2[5] = 23;
    die2[6] = 26;
    die2[7] = 31;
    die2[8] = 34;
    die2[9] = 39;
    die2[10] = 42;
    die2[11] = 47;

    //Die 3: 3, 6, 12, 13, 17, 24, 25, 32, 36, 37, 43, 46
    int[]die3;
    die3 = new int[12];
    die3[0] = 3;
    die3[1] = 6;
    die3[2] = 12;
    die3[3] = 13;
    die3[4] = 17;
    die3[5] = 24;
    die3[6] = 25;
    die3[7] = 32;
    die3[8] = 36;
    die3[9] = 37;
    die3[10] = 43;
    die3[11] = 46;

    // Die 4: 4, 5, 9, 16, 20, 21, 28, 29, 33, 40, 44, 45
    int[]die4;
    die4 = new int[12];
    die4[0] = 4;
    die4[1] = 5;
    die4[2] = 9;
    die4[3] = 16;
    die4[4] = 20;
    die4[5] = 21;
    die4[6] = 28;
    die4[7] = 29;
    die4[8] = 33;
    die4[9] = 40;
    die4[10] = 44;
    die4[11] = 45;

    Random randomDie = new Random();


    int w,d1,d2,d3,d4,dice1=0,dice2=0,dice3=0,dice4=0;
    for (int i=0; i<=1000000; i++)
    {


    w = randomDie.nextInt(12);

    //System.out.println(w);

    d1 = die1[randomDie.nextInt(12)];
    d2 = die2[randomDie.nextInt(12)];
    d3 = die3[randomDie.nextInt(12)];
    d4 = die4[randomDie.nextInt(12)];

    //System.out.println(d1+" " +" "+ d2+" "+ d3+" "+ d4);
    if ((d1 > d2) && (d1 > d3) && (d1 > d4))
    dice1 ++;
    else if ((d2 > d4) && (d2 > d3) && (d2 > d1))
    dice2 ++;
    else if ((d3 > d1) && (d3 > d2) && (d3 > d4))
    dice3 ++;
    else if ((d4 > d1) && (d4 > d2) && (d4 > d3))
    dice4 ++;
    }


    System.out.println(dice1);
    System.out.println(dice2);
    System.out.println(dice3);
    System.out.println(dice4);




    }
    }

  4. #4
    yamicaitsith is offline Member
    Join Date
    Sep 2012
    Location
    san marcos,ca
    Posts
    12
    Rep Power
    0

    Default Re: How to call a classes to a object?

    that is the actual code. this program rolls 4 dice with 12 variables each, stores the values and prints uniformly the rolls that wins.
    what im trying to do with this code is implement a chain of classes example (class A,B and C) splitting the code and use in one main class to recall on the others class "B" and "C".

  5. #5
    yamicaitsith is offline Member
    Join Date
    Sep 2012
    Location
    san marcos,ca
    Posts
    12
    Rep Power
    0

    Default Re: How to call a classes to a object?

    maybe what im trying to say is how to use class instances?

Similar Threads

  1. Replies: 2
    Last Post: 09-22-2012, 10:31 PM
  2. Classes Help!!! two classes with object question.
    By stuckonjava in forum New To Java
    Replies: 16
    Last Post: 02-10-2012, 01:39 AM
  3. Replies: 4
    Last Post: 10-11-2011, 11:48 PM
  4. Call Static Methods Outside Classes
    By Insomniac Riot in forum New To Java
    Replies: 4
    Last Post: 05-11-2010, 10:03 PM
  5. How to call methods of different classes
    By adeeb in forum New To Java
    Replies: 2
    Last Post: 06-06-2008, 06:08 AM

Tags for this Thread

Posting Permissions

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