Thanospan Thanospan - 1 month ago 13
Java Question

How to call a void method from another class

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).

SMA SMA
Answer

Just create instance of SignalMap and call display.

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