Urgente galera preciso para hoje, quem puder ajudar.
Então estou criando um programa básico a onde o usuário cadastra cidades, no caso terá 7 cidades cadastradas.
O usuário terá direito a cadastrar as cidades, pesquisa, ver cidades cadastradas e escolher a melhor rota para se chegar a uma cidade.
Na Opção 4 que seria a rota, o usuário irá digita a cidade em que está e em qual quer chegar e o programa dará a melhor rota.
Estou agarrado nessa opção (4) porque não sei com fazer e preciso disso para hoje, se alguem puder me dar exemplos ou me ajudar mesmo.
Segue o código principal.
package Trabalho.Inf.B;
import javax.swing.JOptionPane;
import java.util.ArrayList;
import java.util.Random;
public class Principal {
public static void main(String[] args){
String City, nCidade, nHabitantes, prefeito, vizinhos;
int x = 0, cont =1;
int y = 9;
ArrayList cd = new ArrayList <>();
Random random = new Random ();
int j = random.nextInt(30);
while (j<5){
j=random.nextInt();
}
String nomes = "";
String cidadeBuscada = "NAO FOI ENCONTRADA";
do {
City = JOptionPane.showInputDialog(null,"|ESCOLHA A OPÇÃO DESEJADA|"
+ "\n1) CADASTRAR CIDADE"
+ "\n2) MOSTRA CIDADES CADASTRADAS"
+ "\n3) PESQUISAR CIDADE"
+ "\n4) MELHOR ROTA"
+ "\n5) DIGITE ESC PARA SAIR","|ROTA FELIZ|", JOptionPane.PLAIN_MESSAGE);
do {
if(City.toUpperCase().equals("1")){
Estado entidade = new Estado();
nCidade = JOptionPane.showInputDialog(null,"NOME DA CIDADE: ","CADASTRO", JOptionPane.PLAIN_MESSAGE);
entidade.setnCidade(nCidade);
nHabitantes = JOptionPane.showInputDialog(null,"QUANTIDADE DE HABITANTES: ","CADASTRO", JOptionPane.PLAIN_MESSAGE);
entidade.setnHabitantes(Integer.parseInt(nHabitantes));
prefeito = JOptionPane.showInputDialog(null,"NOME DO PREFEITO: ","CADASTRO", JOptionPane.PLAIN_MESSAGE);
entidade.setPrefeito(prefeito);
vizinhos = JOptionPane.showInputDialog(null,"VIZINHOS: ","CADASTRO", JOptionPane.PLAIN_MESSAGE);
entidade.setVizinhos(vizinhos);
cd.add(entidade);
x = Integer.parseInt(JOptionPane.showInputDialog(null,"DIGITE QUALQUER TECLA PARA SAIR DO PROGRAMA OU \n0 PARA CONTINUAR CADASTRANDO"));
}cont++;
}while ((x==0)&&(cont<=2));
if(City.toUpperCase().equals("2")){
for(Estado nome : cd){
nomes += nome+"\n";
}
JOptionPane.showMessageDialog(null, nomes, "TODAS AS CIDADES", JOptionPane.INFORMATION_MESSAGE);
}
if(City.toUpperCase().equals("3")){
String busca = JOptionPane.showInputDialog(null,"DIGITE A CIDADE DESEJADA: ","PESQUISAR CIDADE", JOptionPane.PLAIN_MESSAGE);
for (int i = 0; i < cd.size(); i++) {
if(cd.get(i).getnCidade().equals(busca)) {
cidadeBuscada = (
cd.get(i).getnCidade()+ "\n" +
cd.get(i).getnHabitantes()+ "\n" +
cd.get(i).getPrefeito()+ "\n" +
cd.get(i).getVizinhos()+ "\n");
}
JOptionPane.showMessageDialog(null, cidadeBuscada, "CIDADE PESQUISADA", JOptionPane.INFORMATION_MESSAGE);
}
}
if(City.toUpperCase().equals("4")){
String Catual = JOptionPane.showInputDialog(null,"DIGITE A CIDADE EM QUE ESTÁ: ","MELHOR ROTA", JOptionPane.PLAIN_MESSAGE);
int[] sorteio = new int[30];
for (int i = 0; i < cd.size(); i++) {
String Cfinal = JOptionPane.showInputDialog(null,"DIGITE A CIDADE EM QUE DESEJA IR: ","MELHOR ROTA", JOptionPane.PLAIN_MESSAGE);
}
JOptionPane.showMessageDialog(null, cidadeBuscada, "A MELHOR ROTA E ESSA", JOptionPane.INFORMATION_MESSAGE);
}
}while (y==9);
}
}