0
I need to merge in java, with values of an Instance of a class, Queue a and Queue b, I made a method to insert(), in the Queue class. and would like to access the values of a and b. And assign these values to another Instance of the Queue class, type Queue c = new Queue (gets the values of A and B). But I don’t have much idea to do that, I appreciate any kind of help.
Class Queue with other methods
public class Fila {
private int remove;
private int max = 0;
public int dado[];
public Fila(int tamanhoFila) {
this.dado = new int[tamanhoFila];
this.remove = 0;
}
Fila() {
this(3);
}
public void insere(int elemento) {
if (this.max < this.dado.length) {
this.dado[this.max] = elemento;
this.max++;
}
}
public void cheia() {
if (this.max == this.dado.length) {
System.out.println("A Fila esta cheia");
} else {
System.out.println("A Fila não esta cheia");
}
}
public boolean vazia() {
if (this.max == 0) {
return true;
}
return false;
}
public Object primeiro() {
if (this.vazia()) {
return "A fila esta vazia !";
}
return this.dado[0];
}
public Object ultimo() {
return this.dado[--max];
}
public Object remove() {
int pos = 0;
int removeElemento = this.dado[pos];
for (int i = pos; i < this.max - 1; i++) {
dado[i] = dado[i + 1];
}
this.max--;
return removeElemento;
}
@Override
public String toString() {
return Arrays.toString(this.dado);
}
}
Class Executes with the main method
public class Executa {
public static void main(String[] args) {
Fila a = new Fila(4);
Fila b = new Fila(5);
Fila c = new Fila(9);
a.insere(12);
a.insere(35);
a.insere(52);
a.insere(64);
b.insere(05);
b.insere(15);
b.insere(23);
b.insere(55);
b.insere(75);
}
}
I made the constructor method, as reported above. Only when instantiating in the Run class, it presents me with errors in the instance. Displaying errors in b and a. public class Executes { public Static void main(String[] args) { Fila c = new Fila(9, b, a); } }
– Luan Magalhaes
See if you urged
conly after entering the values of the other twoFilas, if you still have the problem edit your question showing what you tried and where and which errors are.– g-otn
I managed to, thank you very much.
– Luan Magalhaes
If you’ve got it differently, answer your question with your solution and mark it as correct, to help other people with a similar question.
– g-otn