Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. package multiplexador;
  2.  
  3. import java.io.FileNotFoundException;
  4. import java.io.FileOutputStream;
  5. import java.io.IOException;
  6. import java.io.OutputStream;
  7. import org.jfree.chart.ChartFactory;
  8. import org.jfree.chart.ChartUtilities;
  9. import org.jfree.chart.JFreeChart;
  10. import org.jfree.chart.editor.DefaultChartEditorFactory;
  11. import org.jfree.chart.plot.PlotOrientation;
  12. import org.jfree.data.category.DefaultCategoryDataset;
  13.  
  14. class Multiplex{
  15. int Em = 100;
  16.  
  17. int E = 0;
  18. double pa = 0.5;
  19. double pb = 0.3;
  20. double pc = 0.2;
  21.  
  22. DefaultCategoryDataset grafico = new DefaultCategoryDataset();
  23. public Multiplex() throws FileNotFoundException, IOException{
  24.  
  25.  
  26.  
  27. System.out.println("Estado inicial do pacote é: " + E);
  28.  
  29. for (int i = 1; i < 1001; i++){
  30. double va = Math.random();
  31.  
  32. if (va <= pa && E != Em){
  33. E = E + 1;
  34. System.out.println("Passo nº: " + i + "\nPacote no Estado: " + E);
  35. System.out.println("Deslocou o pacote pra frente \n");
  36.  
  37.  
  38. }
  39.  
  40. else if (va > pa && va <= pa + pb && E != 0){
  41. E = E - 1;
  42. System.out.println("Passo nº: " + i + "\nPacote no Estado: " + E);
  43. System.out.println(" Deslocou o pacote para trás \n");
  44. }
  45.  
  46. else if (va > pa + pb ){
  47. E = E;
  48. System.out.println("Passo nº: " + i + "\nPacote no Estado: " + E);
  49. System.out.println("Pacote continua no mesmo estado \n");
  50. }
  51.  
  52. else {
  53. E = E;
  54. System.out.println("Passo nº: " + i + "\nPacote no Estado: " + E);
  55. System.out.println("Pacote continua no mesmo estado \n");
  56. }
  57.  
  58. grafico.addValue(E, "Gráfico", i);
  59. }
  60.  
  61. JFreeChart grafic = ChartFactory.createLineChart("Gráfico", "Passos", "Pacotes", grafico, PlotOrientation.VERTICAL, true, true, false);
  62.  
  63. OutputStream File = new FileOutputStream("Grafico.png");
  64. ChartUtilities.writeChartAsPNG(File, grafic, 1000, 800);
  65. }
  66.  
  67. }
  68.  
  69.  
  70. public class Multiplexador {
  71.  
  72.  
  73.  
  74.  
  75.  
  76. public static void main(String[] args) throws IOException {
  77.  
  78. Multiplex mlt = new Multiplex();
  79.  
  80.  
  81. }
  82.  
  83.  
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement