KaeruCT

Untitled

Feb 28th, 2011
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.46 KB | None | 0 0
  1. import java.io.*;
  2. class ProblemaTramos{
  3.    
  4.     public static void main(String[] args) throws java.io.IOException{
  5.            
  6.         BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  7.         PrintStream out = System.out;          
  8.                                
  9.         int numTramo = 0, costoTotal = 0, longCarretera = 0,
  10.         tramoMayor = 0, tramoMenor = 0, numTramoMayor = 0, numTramoMenor = 0,
  11.         anchoTramo, difNivelTramo, costoTramo, longTramo, material, costoMaterial,
  12.         x1, y1, x2, y2;
  13.        
  14.         float relacInclinacion;
  15.         String clasificacion = "";
  16.        
  17.         boolean procesar;
  18.        
  19.         out.println("******************************");
  20.         out.println("*  Tramos v1.0               *");
  21.         out.println("*  Por Ernesto V. y Julio M. *");
  22.         out.println("******************************");
  23.         out.println();
  24.    
  25.         out.println("Introduzca x1:");
  26.         x1 = Integer.parseInt(in.readLine());
  27.        
  28.         out.println("Introduzca y1:");
  29.         y1 = Integer.parseInt(in.readLine());
  30.        
  31.         out.println("Introduzca x2:");
  32.         x2 = Integer.parseInt(in.readLine());
  33.        
  34.         out.println("Introduzca y2:");
  35.         y2 = Integer.parseInt(in.readLine());
  36.        
  37.         do{
  38.             procesar = false;
  39.            
  40.             out.println("Introduzca el ancho del tramo:");
  41.             anchoTramo = Integer.parseInt(in.readLine());
  42.            
  43.             out.println("Introduzca la diferencia de nivel del tramo:");
  44.             difNivelTramo = Integer.parseInt(in.readLine());
  45.            
  46.             out.println("Introduzca el material del tramo:");
  47.             out.println("(0: material selecto, 1: adoquin, 2: asfalto)");
  48.             material = Integer.parseInt(in.readLine());
  49.            
  50.             longTramo = (int) Math.sqrt(Math.pow(x2-x1, 2)+Math.pow(y2-y1, 2)) * 1000;
  51.            
  52.             relacInclinacion = (float) difNivelTramo/longTramo;
  53.            
  54.             if(relacInclinacion >= 0 && relacInclinacion <= 0.3){
  55.                 if(relacInclinacion >= 0.05){
  56.                     procesar = true;
  57.                     clasificacion = "suave";
  58.                 }else if(relacInclinacion <= 0.2){
  59.                     procesar = true;
  60.                     clasificacion = "moderada";
  61.                 }else if(relacInclinacion <= 30 && longTramo <= 1000){
  62.                     procesar = true;
  63.                     clasificacion = "levemente fuerte";
  64.                 }
  65.             }
  66.            
  67.             switch(material){
  68.                 case 0:
  69.                     costoMaterial = 4000;
  70.                     break;
  71.                    
  72.                 case 1:
  73.                     costoMaterial = 6000;
  74.                     break;
  75.                    
  76.                 case 2:
  77.                     costoMaterial = 17000;
  78.                     break;
  79.                    
  80.                 default:
  81.                     costoMaterial = 0;
  82.                     procesar = false;
  83.             }
  84.            
  85.             if(procesar){
  86.                 numTramo++;
  87.                 x1 = x2;
  88.                 y1 = y2;
  89.                
  90.                 costoTramo = anchoTramo*longTramo*costoMaterial;
  91.                 costoTotal += costoTramo;
  92.                 longCarretera += longTramo;
  93.                
  94.                 if(longTramo > tramoMayor){
  95.                     numTramoMayor = numTramo;
  96.                     tramoMayor = longTramo;
  97.                 }
  98.                
  99.                 if(longTramo < tramoMenor || tramoMenor == 0){
  100.                     numTramoMenor = numTramo;
  101.                     tramoMenor = longTramo;
  102.                 }
  103.                
  104.                 out.println();
  105.                
  106.                 out.println("--Tramo #"+numTramo+"--");
  107.                 out.println("Longitud: "+longTramo);
  108.                 out.println("Relacion de inclinacion: "+relacInclinacion);
  109.                 out.println("Material: "+material);
  110.                 out.println("Clasificacion: "+clasificacion);
  111.                 out.println("Costo: "+costoTramo);
  112.             }else{
  113.                 out.println("El tramo no se proceso");
  114.             }
  115.            
  116.             out.println();
  117.                
  118.             out.println("Introduzca x2:");
  119.             x2 = Integer.parseInt(in.readLine());
  120.    
  121.             out.println("Introduzca y2:");
  122.             y2 = Integer.parseInt(in.readLine());
  123.            
  124.         }while(x2 != -1 && y2 != -1);
  125.        
  126.        
  127.         out.println("--Informacion sobre la carretera--");
  128.         out.println("Longitud total: "+longCarretera);
  129.         out.println("Costo total: "+costoTotal);
  130.         out.println("Tramo menor: #"+numTramoMenor+", con "+tramoMenor+"m");
  131.         out.println("Tramo mayor: #"+numTramoMayor+", con "+tramoMayor+"m");
  132.     }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment