Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7850105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T18:44:46+00:00 2026-06-02T18:44:46+00:00

I am a very new java user, and I have always had trouble with

  • 0

I am a very new java user, and I have always had trouble with testing my programs. Here I have implement a basic boolean array interface. I want to test it buy adding a couple values and then running each of the interface methods. Please be nice I am not very good at this but I want to get better.

package booleanmatrix;

import java.util.Arrays;

/**
 *
 * @author David
 */
public class ArrayMatrix implements BooleanMatrixs {

    private boolean a[][];
    public int Rows;
    public int Cols;
    public int capacityr = 1;
    public int capacityc = 1;
    public int pT=0;
    public int pF=0;

    public ArrayMatrix() {
        a = new boolean[capacityr][capacityc];
    }



    @Override
    public int getNumberRows() {
        return capacityr;
    }

    @Override
    public int getNumberCols() {
        return capacityc;

    }

    @Override
    public void set(int row, int col) throws IndexOutOfBoundsException {

        if (row > capacityr) {
            capacityr = row;
            boolean B[][] = new boolean[capacityr][capacityc];
            for (int k = 0; k < capacityr; k++) {
                for (int j = 0; j < capacityc; j++) {
                    B[k][j] = a[k][j];
                }
            }
            a = B;
        }
        if (col > capacityc) {
            capacityc = col;
            boolean C[][] = new boolean[capacityr][capacityc];
            for (int k = 0; k < capacityr; k++) {
                for (int j = 0; j < capacityc; j++) {
                    C[k][j] = a[k][j];
                }
            }
            a = C;
        }

        a[row][col] = true;
        pT++;


    }

    @Override
    public void clear(int row, int col) throws IndexOutOfBoundsException {
        if (row > capacityr) {
            capacityr = row;
            boolean B[][] = new boolean[capacityr][capacityc];
            for (int k = 0; k < capacityr; k++) {
                for (int j = 0; j < capacityc; j++) {
                    B[k][j] = a[k][j];
                }
            }
            a = B;
        }
        if (col > capacityc) {
            capacityc = col;
            boolean C[][] = new boolean[capacityr][capacityc];
            for (int k = 0; k < capacityr; k++) {
                for (int j = 0; j < capacityc; j++) {
                    C[k][j] = a[k][j];
                }
            }
            a = C;
        }

        a[row][col] = false;




    }

    @Override
    public void set(int row, int col, boolean value) throws IndexOutOfBoundsException {
        if (row > capacityr) {
            capacityr = row;
            boolean B[][] = new boolean[capacityr][capacityc];
            for (int k = 0; k < capacityr; k++) {
                for (int j = 0; j < capacityc; j++) {
                    B[k][j] = a[k][j];
                }
            }
            a = B;
        }
        if (col > capacityc) {
            capacityc = col;
            boolean C[][] = new boolean[capacityr][capacityc];
            for (int k = 0; k < capacityr; k++) {
                for (int j = 0; j < capacityc; j++) {
                    C[k][j] = a[k][j];
                }
            }
            a = C;
        }

        a[row][col] = value;
        if(value==true){
            pT++;
        }

    }

    @Override
    public void toggle(int row, int col) throws IndexOutOfBoundsException {
        if (row > capacityr) {
            capacityr = row;
            boolean B[][] = new boolean[capacityr][capacityc];
            for (int k = 0; k < capacityr; k++) {
                for (int j = 0; j < capacityc; j++) {
                    B[k][j] = a[k][j];
                }
            }
            a = B;
        }
        if (col > capacityc) {
            capacityc = col;
            boolean C[][] = new boolean[capacityr][capacityc];
            for (int k = 0; k < capacityr; k++) {
                for (int j = 0; j < capacityc; j++) {
                    C[k][j] = a[k][j];
                }
            }
            a = C;
        }

        if (a[row][col] == true) {
            a[row][col] = false;
            pT--;
        } else {
            a[row][col] = true;
            pT++;

        }

    }

    @Override
    public void setAll() {
        Arrays.fill(a, Boolean.TRUE);
        pT=(capacityr*capacityc);

    }

    @Override
    public void clearAll() {
        Arrays.fill(a, Boolean.FALSE);
        pT=0;

    }

    @Override
    public void setAll(boolean value) {
        if (value == false) {
            Arrays.fill(a, Boolean.FALSE);
        } else {
            Arrays.fill(a, Boolean.TRUE);
             pT=(capacityr*capacityc);

        }



    }

    @Override
    public boolean get(int row, int col) throws IndexOutOfBoundsException {
        boolean x;
        x = a[row][col];
        return x;
    }

    @Override
    public int[][] getTruePositions() {

        int count = 0;



        int ret[][] = new int[pT][2];



        for (int k = 0; k < capacityr; k++) {
            for (int j = 0; j < capacityc; j++) {
                if (a[k][j] == true) {
                    ret[count][0] = k;
                    ret[count][1] = j;
                    count++;
                }

            }
        }
        return ret;
    }

    @Override
    public int[][] getFalsePositions() {
             int total = (capacityr*capacityc);
             int P=(total-pT);
             int count=0;



        int ret[][] = new int[P][2];



        for (int k = 0; k < capacityr; k++) {
            for (int j = 0; j < capacityc; j++) {
                if (a[k][j] == false) {
                    ret[count][0] = k;
                    ret[count][1] = j;
                    count++;
                }
            }
        }
        return ret;

    }

    @Override
    public int[][] getPositions(boolean value) {
               int total = (capacityr*capacityc);
             int P=(total-pT);
             int count=0;


if(value==false){
        int retf[][] = new int[P][2];



        for (int k = 0; k < capacityr; k++) {
            for (int j = 0; j < capacityc; j++) {
                if (a[k][j] == false) {
                    retf[count][0] = k;
                    retf[count][1] = j;
                    count++;
                }
            }
        }
        return retf;}
else{ 
    int count2 = 0;



        int ret[][] = new int[pT][2];



        for (int k = 0; k < capacityr; k++) {
            for (int j = 0; j < capacityc; j++) {
                if (a[k][j] == true) {
                    ret[count2][0] = k;
                    ret[count2][1] = j;
                    count2++;
                }

            }
        }
        return ret;

    }}

    @Override
    public int getNumberTrueValues() {
        return pT;

    }

    @Override
    public int getNumberFalseValues() {
          int total = (capacityr*capacityc);
             int P=(total-pT);
             return P;

    }

    @Override
    public int getNumberValues(boolean value) {
        if (value==false){
             int total = (capacityr*capacityc);
             int P=(total-pT);
             return P;
        }
        else{return pT;}}
    @Override
    public String toString(){
        String X= "1)The number of rows"+capacityr+"\n 2)The number of Columns"+capacityc+"\n 3)The number of True Values"+pT+"\n 4)The number of false values"+(capacityc*capacityr-pT);
        return X;
    }


     public static void main(String[] args) {









     }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T18:44:48+00:00Added an answer on June 2, 2026 at 6:44 pm

    Add a new class that has a Main method (if you are using eclipse there is an auto click button that does that for you) then instantiate a new variable from your class.

    ArrayMatrix arrayVar = new ArrayMatrix();
    

    Then you would be able to access all the methods such as:

    arrayVar.getNumberCols();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am very new to wpf. How can I implement CardLayout functionality from java?
I am very new to Java, I want to add a PNG image to
I'm very new to Java but I've been developing a habit to use final
Hi i am very new to java and this is my first piece of
I am very new to Java and I was wondering if it is possible
I am very new to Java. I am writing a program to read a
Let me start by saying I'm very new to Java and to this site.
I am very new to processing.org and Java. I am trying to store objects
I'm very new to Python (I'm coming from a JAVA background) and I'm wondering
I am very new to symfony. In other languages like java and others I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.