Results 1 to 11 of 11
Like Tree2Likes
  • 1 Post By Tolls
  • 1 Post By Tolls

Thread: contingency table problem

  1. #1
    wan Toushiro is offline Member
    Join Date
    May 2012
    Posts
    6
    Rep Power
    0

    Question could anyone help me with this contingency table problem?

    I am struggling to find the java code for this problem. Firstly, I am in a beginner level and this question were hard for me to answer. I guess that this used a 2D array right? but i having problem to write the java code for this question. Kindly please help me?i need to submit this java code as soon as possible. thank you very much.

    here is the question :

    Write a Java program that
    1.queries a user for the number of rows and columns of a contingency table,
    2.read the data, row by row and
    3.displays the data in tabular form along with the row totals, column totals and grand total.

    For example if the six data of 2x3 table are

    1,3,6,7,9, and 8. the program displays these six numbers together with the appropriate totals as

    1 3 6 | 10
    7 9 8 | 24
    8 12 14 | 34

    The character '|' is used to separate the data from the row totals
    Last edited by wan Toushiro; 05-29-2012 at 12:42 PM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: contingency table problem

    What have you written so far and where are you having problems, including any exceptions or compilation errors, showing which line they occur on.
    quad64bit likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    wan Toushiro is offline Member
    Join Date
    May 2012
    Posts
    6
    Rep Power
    0

    Default Re: contingency table problem

    firstly i'm beginner in this java programming and do not know what type of code do i need to do whether it's loop array or etc.. could you guide me to solve this problem? thank you very much.

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: contingency table problem

    Well, you have 3 steps there, so start from the beginning.
    So write the code to do part 1, storing the numRows and numCols in int variables.
    Then extend that by writing the code to read in the data, storing that in something suitable (an array sounds good).
    Then finally look at part 3.

    There's no point looking at the whole problem and trying to figure it out in one go...that way lies madness.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    wan Toushiro is offline Member
    Join Date
    May 2012
    Posts
    6
    Rep Power
    0

    Default Re: contingency table problem

    i have done until here. then what should i do? how to assign the number(data) that user enter to the rows and columns? please help me?


    package javaapplication16;

    /**
    *
    * @author USER
    */import java.util.Scanner;
    import java.util.*;

    public class JavaApplication16 {

    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
    // TODO code application logic here

    int numRows;
    int numCols;
    int sizeTable;
    Scanner readinput = new Scanner(System.in);

    System.out.println(" Enter the size of table: Rows*Columns " );

    numRows = readinput.nextInt();
    numCols = readinput.nextInt();

    sizeTable = numRows*numCols;

    System.out.println(" The size of table are : "+numRows+"*"+numCols+"="+sizeTable );
    //
    int[][] ContigencyTable;
    ContigencyTable = new int[numRows][numCols];




    }
    }

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: contingency table problem

    So there you go, you now have an (empty) table based on the user input.

    Now for part 2.
    I have no idea where exactly you are supposed to be reading the data from, but if it's the user then you will need to loop around that array asking the user for numbers, then assigning the result to the bit of the array you are currently on.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    wan Toushiro is offline Member
    Join Date
    May 2012
    Posts
    6
    Rep Power
    0

    Default Re: contingency table problem

    could you please write me the code for the loop. the data is 1, 3, 4, 7. can you do it for 2 x 2 table.

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: contingency table problem

    See my sig.
    wan Toushiro likes this.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    wan Toushiro is offline Member
    Join Date
    May 2012
    Posts
    6
    Rep Power
    0

    Default Re: contingency table problem

    i've already email the question.

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,172
    Rep Power
    20

    Default Re: contingency table problem

    Please do not ask for code as refusal often offends.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  11. #11
    wan Toushiro is offline Member
    Join Date
    May 2012
    Posts
    6
    Rep Power
    0

    Default Re: contingency table problem

    ok2..sory. what if you suggest the type of loop that i will use that require the data from user like(nested-loop,if-else or etc..)

Similar Threads

  1. problem with inserting into table
    By pardhu in forum AWT / Swing
    Replies: 2
    Last Post: 11-19-2011, 05:46 AM
  2. Problem with ComboBox in a table
    By xyknight in forum New To Java
    Replies: 8
    Last Post: 04-25-2011, 04:05 AM
  3. Problem with table
    By fivig in forum SWT / JFace
    Replies: 0
    Last Post: 10-21-2009, 07:03 AM
  4. Problem in getting table on panel
    By adeeb in forum AWT / Swing
    Replies: 0
    Last Post: 06-09-2008, 09:23 PM
  5. Problem with sorting Table
    By sireesha264 in forum Advanced Java
    Replies: 0
    Last Post: 02-08-2008, 03:21 PM

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
  •