HOW TO CALL A VOID METHOD FROM ANOTHER CLASS

Alex Leblois

Total Post:67

Points:471
Posted by  Alex Leblois
Class  Void 
 1198  View(s)
Ratings:
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).

  1. Brad Pitt

    Post:61

    Points:429
    Re: How to call a void method from another class

    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 Apr-06-2018 04:38:07 AM

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!