Home > DeveloperSection > Forums > How to call a void method from another class
Alex Leblois
Alex Leblois

Total Post:67

Points:471
Posted on    November-05-2014 3:29 AM

 Java Class  Void 
Ratings:


 1 Reply(s)
 677  View(s)
Rate this:
I would like to call the public void display() from another class but i don't know how please help me this my program:

public class SignalMap

{

    private boolean[][] signal;

    private double threshold;

    private Network net;

    private int size;

 

    public SignalMap(Network net, double threshold, int size)

    {

        this.net = net;

        this.threshold = threshold;

        signal = new boolean[size][size];

 

        for(int i = 0; i < size; i++)

            {          

                for(int j = 0; j < size; j++)

                {

                    if(net.getSignal(i, j) >= threshold)

                    {

                        signal[i][j] = false;

                    }

                    else

                    {

                        signal[i][j] = true;

                    }

                }

            }

    }

 

    public void display()

    {

        for(int i = 0; i < size; i++)

            {          

                for(int j = 0; j < size; j++)

                {

                    if (signal[i][j].equals(true))

                    {

                        System.out.printf("%5d ", signal[i][j]);

                    }

 

                }

                System.out.println();

            }  

    }

    public double poorSignal()

    {

        int x = 0;

        for (int i = 0; i < size; i++)

        {

            for (int j = 0; j < size; j++)

            {

                if (signal[i][j] == true)

                {

                    x = x + 1;

                }

            }

        }

        return 1 / (size / x);

    }

}


Please help tell me if I am doing something wrong. This is the question i have to answer : Write a method display in the SignalMap class which prints the array showing those areas which have poor signal (for example, display an X if the signal is poor).



Brad Pitt
Brad Pitt

Total Post:61

Points:429
Posted on    November-05-2014 5:23 AM

Just create instance of SignalMap and call display.

public class MainClass {
    public static void main(String args[]) {
         SignalMap signalMap = new SignalMap();
         signalMap.display();
    }
}

Modified On Nov-05-2014 05:24:00 AM

Don't want to miss updates? Please click the below button!

Follow MindStick